我是WPF的新手。这是我为MainWindow编写的代码
<StackPanel Grid.Row="1">
<RadioButton Content="ÐлавнаÑ"
Height="50"
Foreground="White"
FontSize="14"
Style="{StaticResource MenuButtonTheme}"
IsChecked="True"
Command="{Binding ChangeToHome}"/>
<RadioButton Content="ÐобавиÑÑ ÑаÑкÑаÑкÑ"
Height="50"
Foreground="White"
FontSize="14"
Style="{StaticResource MenuButtonTheme}"
Command="{Binding ChangeToDiscovery}"/>
</StackPanel>
以及MainViewModel.cs的此代码
private void ChangeToHome (object value)
{
CurrentView = HomeVM;
MessageBox.Show("Now in home", "alert", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void ChangeToDiscovery (object value)
{
CurrentView = DiscoveryVM;
MessageBox.Show("Now in Discovery", "alert", MessageBoxButton.OK, MessageBoxImage.Information);
}
private bool CanChangeView(object value)
{
return true;
}
public MainViewModel()
{
HomeVM = new HomeViewModel();
DiscoveryVM = new DiscoveryViewModel();
CurrentView = HomeVM;
HomeViewCommand = new RelayCommand(ChangeToHome, CanChangeView);
DiscoveryViewCommand = new RelayCommand(ChangeToDiscovery, CanChangeView);
}
我没有任何错误,但什么都不起作用。当我点击单选按钮时,没有消息,也不会改变视图。