0

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

Nick Tsui
  • 524
  • 2
  • 9
  • 29

2 Answers2

1

And where is your Binding View->ViewModel?

MikroDel
  • 6,705
  • 7
  • 39
  • 74
  • XAML file is named TooBarView.xaml under View folder; C# code is named ImageReviewViewModel.cs under View Model folder. There is a ImageReview.cs in Model folder. Most stuff in ImageReviewViewModel.cs is related with MainWindow.xaml in root folder. – Nick Tsui Nov 02 '12 at 14:35
  • So can you show me please your code where you connect View to you ViewModel? Or maybe you using some kind of MVVM Frameworks? – MikroDel Nov 02 '12 at 14:41
1

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?

Rhyous
  • 6,510
  • 2
  • 44
  • 50