无法使用Prism进行导航

时间:2016-03-07 14:52:02

标签: c# mvvm prism

我无法让Prism中的导航工作。当我点击按钮转到相应的视图时,没有任何反应。

这是Man View(Shell)XAML:

cap someenv deploy

及其ViewModel:

string getpathforexe[] = themethord;
foreach(string printvalue in getpathforexe)
{
     messagebox.show(printvalue.tostring());
}

和Bootstrapper:

<Window x:Class="MVVMPractice2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:prism="http://prismlibrary.com/" 
        prism:ViewModelLocator.AutoWireViewModel="True" 
        xmlns:Views="clr-namespace:MVVMPractice2.Views"
        Title="MainWindow" Height="350" Width="525"> 

        <Grid>
            <Button Margin="108,130,331.4,152.8" Content="View A" Command="{Binding NavigateCommand}" CommandParameter="ViewA"/>
            <Button Margin="254,130,185.4,152.8" Content="View B" Command="{Binding NavigateCommand}" CommandParameter="ViewB"/>

            <ContentControl prism:RegionManager.RegionName="ContentRegion"/> <!--PRISM POWER-->
        </Grid>
</Window>

我将不胜感激。

2 个答案:

答案 0 :(得分:0)

我通过仅在UserControls上使用prism:ViewModelLocator.AutoWireViewModel="True"而不是窗口来让我工作。我假设你正在使用棱镜6。

所以我做的是,我首先创建了MainWindow,它将包含我所有的UserControls,然后我创建了一个MainUserControl来容纳所有其他UserControl。我在blog posthttp://brianlagunas.com/getting-started-prisms-new-viewmodellocator/)之后实现了这一切。请记住创建MVVM文件夹(View和ViewModel)文件夹及其各自的内容作为博客亮点。

希望这有帮助。

答案 1 :(得分:-1)

首先,您应该将ICommand公开给按钮的命令属性,而不是委托命令,这是ICommand的具体实现。

您可以通过实现摆脱视图模型定位器的约定 应用程序类启动覆盖方法中的ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType)

欲了解更多信息,请搜索Brian Lagunas viewmodellocator博客

相关问题