我可以帮你翻译成中文。以下是翻译的结果,请查收:
我正在尝试在我的应用程序中实现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); }
}
}
文件夹结构:
ViewModelLocator
的约定配置是什么? - Haukinger<Window x:Class="WpfApp1.MainWindow"
看起来MainWindow
不在WpfApp1.Views
命名空间中... - Haukinger