I am trying to implement ViewModelLocator pattern in my application, but ViewModel is not hooked up to the view. I am new to prism, please let me know if I am missing anything here.
View:
<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>
ViewModel:
class MainWindowViewModel : BindableBase
{
string _message = "Hello World";
public string Message
{
get { return _message; }
set { SetProperty<string>(ref _message, value); }
}
}
Folder Structure:

Make sure that the views reside in a Views namespace, and the viewmodels in ViewModels, respectively.
Change WpfApp1.MainWindow to WpfApp1.Views.MainWindow in xaml file and in ViewModels folder change namespace wpfApp1.ViewModels. This worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With