Getting Started Firstly, start VS2010, and create a new WPF project.
Ensure that you have Nuget installed.
Manage Nuget Package References and add ‘MVVM Light’MVVM Light has now added a ViewModel folder containing the MainViewModel and the ViewModelLocator.
Edit the Main WindowSimply add a button, and defer the DataContext binding to the ViewModelLocator (elided):
<Window x:Class="MvvmLightTest.MainWindow"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<Grid>
<Button Command="{Binding ShowPopUp}" Content="Show Pop Up" />
</Grid>
</Window>Then in the MainViewModel we define the ShowPopUp command:
public class MainViewModel : ViewModelBase
{
public MainViewModel()
{
ShowPopUp = new RelayCommand(() => ShowPopUpExecute(), () => true);
} public ICommand ShowPopUp { get; private set; } private void ShowPopUpExecute()
{
MessageBox.Show("Hello!");
}
}Read more: Codeproject
QR:
Ensure that you have Nuget installed.
Manage Nuget Package References and add ‘MVVM Light’MVVM Light has now added a ViewModel folder containing the MainViewModel and the ViewModelLocator.
Edit the Main WindowSimply add a button, and defer the DataContext binding to the ViewModelLocator (elided):
<Window x:Class="MvvmLightTest.MainWindow"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<Grid>
<Button Command="{Binding ShowPopUp}" Content="Show Pop Up" />
</Grid>
</Window>Then in the MainViewModel we define the ShowPopUp command:
public class MainViewModel : ViewModelBase
{
public MainViewModel()
{
ShowPopUp = new RelayCommand(() => ShowPopUpExecute(), () => true);
} public ICommand ShowPopUp { get; private set; } private void ShowPopUpExecute()
{
MessageBox.Show("Hello!");
}
}Read more: Codeproject
QR:
0 comments:
Post a Comment