Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can you describe what is incorrect in my WPF project&

I’m new to WPF. This is my code for 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>

and this code for 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);
}

I’m not getting any errors, but nothing works. When i click on radio button there are no messages and it doesn’t change the view.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The first thing that caught my eye was that the commands were bound to the wrong properties that were declared in the ViewModel.

enter image description here

enter image description here

There may be other errors, but to understand this you need more complete fragments of your code. Including how you instantiate the ViewModel and pass it to the Data Context.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading