Pergunta

Este refere-se a aplicação composta Orientação para WPF, ou prisma.

Eu tenho um "MainRegion" em minha concha. Meus vários módulos serão carregados na região principal. Eu posso preencher uma lista de módulos disponíveis em um menu e selecioná-los para carregar. No clique do menu I fazer:

var module = moduleEnumerator.GetModule(moduleName);
moduleLoader.Initialize(new[] { module });

Na primeira vez que tudo funciona ok, porque os métodos Initialize () dos módulos são executados, mas depois de Module1, Module2 e Module3 são inicializados, nada acontece quando clico para carregar Module2 novamente.

A minha pergunta: como posso activar um módulo sob demanda, após o seu método de inicialização foi executado

Obrigado por sua ajuda!

Foi útil?

Solução

You don't actually activate the module. You activate a view in a region. Take a read of this article.

The Initialize method is only called the once for any module. The fact that you are seeing a view in the module being activated when you call LoadModule I would guess is due to the fact that the Initilalize method is registering a view with a region. This will activate the view. If you had more than one view then the last registered would be the active one.

To Activate a view you need to call the Activate method of the region (assuming an injected IUnityContainer and IRegionManager)...

// Get a view from the container.
var view = Container.Resolve<MyView>();

// Get the region.
var region = RegionManager.Regions["MyRegion"];

// Activate the view.
region.Activate(view);

Depending on the type of region control this will either replace the view that is there or add to it.

Outras dicas

You can remove a View by calling Regions's Remove method.

public void RemoveViewFromRegion(string viewName, string regionName, object defaultView)
    {
      IRegion region = regionManager.Regions[regionName];
      object view = region.GetView(viewName);
      region.Remove(view);
      region.Activate(defaultView); 
    }

You should have a ContentControl that will be your region. Then you will need to add all your modules to this region. When you click on the menu you should use Activate(...) method of the region in order to activate the particular module.

Does this mean when yuou activate module, then other modules that may be overlapped by it are set to Visibility.Collapsed?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top