C#棱镜navigationProblem [英] C# Prism navigationProblem

查看:327
本文介绍了C#棱镜navigationProblem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个区域。导航区和主要区域。

我的导航区域包含两个按钮调用其中的RequestNavigate方法。 第一个按钮加载视图不带任何参数

  this.tRegionManager.RequestNavigate(RegionNames.MainRegion,ViewNames.VInfoMainViewUri);
 

第二个按钮应加载一些参数相同的观点

  this.tRegionManager.RequestNavigate(RegionNames.MainRegion,新的URI(ViewNames.VInfoMainViewUri.OriginalString ++ query.ToString(),UriKind.Relative));
 

如果没有加载来看这工作得很好。如果加载任何观点,任何按钮点击会导致什么。

我想从我区取出所有活动视图,但是这将导致一个错误

  IViewsCollection COL = tRegionManager.Regions [args.RegionName] .Views;
的foreach(在山坳VAR OBJ)
{
   tRegionManager.Regions [args.RegionName]上卸下摆臂(OBJ);

}
 

  

该区域不包含指定的视图。   参数名:查看

我怎样才能解决这个probem?

解决方案

如果你想创建一个新的观点,即使已经有同类型的在该地区的现有视图,您需要实现 INavigationAware 接口,无论是在您的视图或视图模型(棱镜将检查第一的观点,如果不执行 INavigationAware 这也将检查视图模型)。

您是专门在 IsNavigationTarget 的方法,它告诉棱镜如果针对目前的实例应该被重用,或者有兴趣,如果另一个实例应建立满足导航请求。所以,总是创建一个新的视图,你会怎么做:

 公共类MyViewModel:INavigationAware {
    布尔INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
    {
        返回false;
    }

    无效INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
    {
    }

    无效INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
    {
    }
}
 

所有这些更详细地解释在棱镜4文档的第8章;他们也有<一个href="http://msdn.microsoft.com/en-us/library/gg430861%28v=pandp.40%29.aspx#TheRegionNavigationSequence"相对=nofollow>它是如何工作的一个例子。

I have two regions. A navigation region and a main region.

My navigation region contains two buttons which call the RequestNavigate method. The first button loads a view without any parameters

this.tRegionManager.RequestNavigate(RegionNames.MainRegion, ViewNames.VInfoMainViewUri);

The second button should load the same view with some parameters

  this.tRegionManager.RequestNavigate(RegionNames.MainRegion, new Uri(ViewNames.VInfoMainViewUri.OriginalString + "" + query.ToString(), UriKind.Relative));

This works fine if no view is loaded. If any view is loaded, a click on any button causes nothing.

I tried to remove every active view from my region, but this causes an error

IViewsCollection col = tRegionManager.Regions[args.RegionName].Views;
foreach (var obj in col)
{
   tRegionManager.Regions[args.RegionName].Remove(obj);

}

The region does not contain the specified view. Parameter name: view

How can I fix this probem?

解决方案

If you want to create a new view even when there is already an existing view of the same type in the region, you need to implement the INavigationAware interface either in your View or your ViewModel (Prism will check first the view, and if it doesn't implement INavigationAware it will also check the ViewModel).

You are interested specifically in the IsNavigationTarget method, which tells Prism if the current instance of the View should be reused, or if another instance should be created to satisfy the navigation request. So, to always create a new View you would do:

public class MyViewModel : INavigationAware {
    bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
    {
        return false;
    }

    void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
    {
    }

    void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
    {
    }
}

All of this is explained in greater detail in Chapter 8 of the Prism 4 documentation; they also have an illustration of how it works.

这篇关于C#棱镜navigationProblem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆