PRISM 在同一模块中查看注入/导航
这是Products 模块中的ModuleInit.cs
public class ModuleInit : IModule
{
private readonly IUnityContainer _container;
private readonly IRegionManager _regionManager;
public ModuleInit(IUnityContainer container, IRegionManager regionManager)
{
_container = container;
_regionManager = regionManager;
}
#region IModule Members
public void Initialize()
{
App app = (App)Application.Current;
_regionManager.RegisterViewWithRegion(RegionNames.ModuleRegionProducts, () => _container.Resolve<Views.ProductsCycle>());
}
#endregion
}
下面是ProductsCycle.cs 中的按钮事件处理程序,用于转到仍在同一模块内的另一个视图:
private void btnForward_Click(object sender, RoutedEventArgs e)
{
IRegion productsRegion = _regionManager.Regions["ModuleRegionProducts"];
var productsListView = _container.Resolve<Views.ProductsList>();
productsRegion.Add(productsListView, "ProductsList");
productsRegion.Activate(productsListView);
}
状态:ProductsCycle 页面在首次加载时成功加载。
问题:单击 btnForward 时,视图未从 ProductCycle 页面更改为 ProductsList 页面。
我正在使用 Silverlight 4 和 PRISM2。 请您的建议,谢谢。
This is ModuleInit.cs in Products module
public class ModuleInit : IModule
{
private readonly IUnityContainer _container;
private readonly IRegionManager _regionManager;
public ModuleInit(IUnityContainer container, IRegionManager regionManager)
{
_container = container;
_regionManager = regionManager;
}
#region IModule Members
public void Initialize()
{
App app = (App)Application.Current;
_regionManager.RegisterViewWithRegion(RegionNames.ModuleRegionProducts, () => _container.Resolve<Views.ProductsCycle>());
}
#endregion
}
Below is button event handler in ProductsCycle.cs to go to another view still within same module:
private void btnForward_Click(object sender, RoutedEventArgs e)
{
IRegion productsRegion = _regionManager.Regions["ModuleRegionProducts"];
var productsListView = _container.Resolve<Views.ProductsList>();
productsRegion.Add(productsListView, "ProductsList");
productsRegion.Activate(productsListView);
}
State: ProductsCycle page is successfully loaded on first load.
Problem: View doesn't changed from ProductCycle page to ProductsList page when btnForward is clicked.
I'm using Silverlight 4 and PRISM2.
Please your advice, thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
productsRegion.Activate(productsListView);
更改为
productsRegion.Remove(this);
因为我的
productListView
不是直接从UserControl< 继承的/代码>。
change
productsRegion.Activate(productsListView);
to
productsRegion.Remove(this);
because my
productListView
is not inherited directly fromUserControl
.