Question

I know this topic has been discussed many times, but I still cannot get it work. I have 3 RadioButtons that are put in a StackPanel; I am trying to bind their IsChecked to some variable in View Model. Here is what I did:

in XAML file in View:

  <RadioButton Name="rbExpReview"
                             IsChecked="{Binding Path=rbExpReviewIsChecked, Mode=TwoWay}"
                             Foreground="White">
                    <RadioButton.Content>
                        <Label Content="Experiment Review"
                               HorizontalContentAlignment="Center"
                               VerticalContentAlignment="Center" />
                    </RadioButton.Content>
  </RadioButton>

In View Model, I have declared a variable:

_rbExpReviewIsChecked = true;

and the property that responds to IsChecked of the RadioButton:

public bool rbExpReviewIsChecked
        {
            get
            {
                return _rbExpReviewIsChecked;
            }
            set
            {

                _rbExpReviewIsChecked = value;
                OnPropertyChanged("rbExpReviewIsChecked");
            }
        }

However, when I check and uncheck the button, there is no response in the View Model code (break point is not hit.) So I am wondering what is the problem with my binding? Or anything else? I am new to XAML, so any pointer is appreciated. Nick

Was it helpful?

Solution

Your binding syntax is correct. Your property appears correct. That leaves only one possibility: the DataContext.

What happens in Visual Studio in the Output window? It should give you a binding error if your DataContext is not set properly.

DataContext could be inherited from the Parent, or could be set. What is your DataContext?

OTHER TIPS

And where is your Binding View->ViewModel?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top