문제

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

도움이 되었습니까?

해결책

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?

다른 팁

And where is your Binding View->ViewModel?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top