【问题标题】:ViewModelLocator in Prism 6 not working棱镜 6 中的 ViewModelLocator 不起作用
【发布时间】:2018-02-20 17:08:49
【问题描述】:

我正在尝试在我的应用程序中实现 ViewModelLocator 模式,但 ViewModel 没有连接到视图。我是 prism 的新手,如果我在这里遗漏任何东西,请告诉我。

查看:

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Wpf"
        prism:ViewModelLocator.AutoWireViewModel="True"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TextBlock Text="{Binding Message}" FontSize="36" />
    </Grid>
</Window>

视图模型:

class MainWindowViewModel : BindableBase
{
    string _message = "Hello World";
    public string Message
    {
        get { return _message; }
        set { SetProperty<string>(ref _message, value); }
    }
}

文件夹结构:

【问题讨论】:

标签: c# wpf mvvm prism prism-6


【解决方案1】:

确保视图分别位于Views 命名空间中,视图模型分别位于ViewModels 中。

【讨论】:

    【解决方案2】:

    在 xaml 文件中将 WpfApp1.MainWindow 更改为 WpfApp1.Views.MainWindow,并在 ViewModels 文件夹中更改命名空间 wpfApp1.ViewModels。这对我有用。

    【讨论】:

      猜你喜欢
      • 2017-03-26
      • 2013-02-12
      • 1970-01-01
      • 1970-01-01
      • 2019-05-22
      • 2021-09-07
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多