我正在尝试在我的应用程序中实现 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); }
}
}
文件夹结构: