prism5 regionManager.RequestNavigate显示System.object

时间:2014-10-24 17:20:24

标签: wpf mvvm prism prism-4

我在regionManager中使用prism5。以下是我如何注册我的观点以及我如何尝试浏览。

_container.RegisterType<IMyView,MyView>("MyView"); 

这就是我导航的方式

_regionManager.RequestNavigate("MyViewRegion", new Uri("MyView", UriKind.Relative);

这个导航到MyViewRegion但只显示System.Object

有人说通过注册以下视图来解决这个问题

_container.RegisterType<object,MyView>("MyView");

但我仍想用界面类型注册我的视图。那么我怎么能用RequestNavigate();

解决这个问题

由于

3 个答案:

答案 0 :(得分:0)

我曾经遇到过这个问题,这个问题是在尝试导航到未加载的视图时引起的。因此,在调用.RequestNavigate方法检查视图是否已加载之前,我使用了一个简单的函数:

    private void LoadViewInRegion<TViewType>(IRegion region, string viewName)
    {
        object view = region.GetView(viewName);
        if (view == null)
        {
            view = _container.Resolve<TViewType>();

            region.Add(view, viewName);
        }
    }

因此显示视图的代码如下:

IRegion region = _regionManager.Regions["MyViewRegion"];

LoadViewInRegion<IMyView>(region, "MyView");

_regionManager.RequestNavigate("MyViewRegion", new Uri("MyView", UriKind.Relative);

答案 1 :(得分:0)

我修改了你的代码,我在我的模块类Initialize方法中加载代码。网上的大多数其他建议对Prism 5没有帮助。

    public void Initialize()
    {
        _regionManager.RegisterViewWithRegion("MainNavigationRegion",
            typeof(Views.TestDocumentNavigationView));

        LoadViewInRegion<TestDocumentView>("MainRegion");
    }


    /// <summary>
    /// You must load the views in order for the navigation to resolve
    /// </summary>
    void LoadViewInRegion<TViewType>(string regionName)
    {
        IRegion region = _regionManager.Regions[regionName];
        string viewName = typeof(TViewType).Name;

        object view = region.GetView(viewName);
        if (view == null)
        {
            view = _container.Resolve<TViewType>();

            region.Add(view, viewName);
        }
    }

答案 2 :(得分:0)

尝试在Module.cs / App.xaml.cs中注册视图:

if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
} //added brace

//database insertion here

您的问题将得到解决:)