0
votes

I've searched and discovered several proposed solutions, but I still can't make this work:

I'm using .Net 4.5, WPF, MVVM

I want to implement three radio buttons to allow a user to select which method (Primary, Secondary, Tertiary) to view. The UI, looks like this:

[ 1 ] [ 2 ] [ 3 ] (I had an image, here, but, apparently, I can't post that unless I have a 10 rep...)

My XAML:

<StackPanel Grid.Column="4" Orientation="Horizontal">
  <RadioButton x:Name="rb1" Style="{StaticResource Radio1Button}" Command="{Binding Path=Select1ReceivingMethodCommand}" IsChecked="{Binding Path=ReceivingMethod1IsSelected}" />
  <RadioButton x:Name="rb2" Style="{StaticResource Radio2Button}" Command="{Binding Path=Select2ReceivingMethodCommand}" IsChecked="{Binding Path=ReceivingMethod2IsSelected}" />
  <RadioButton x:Name="rb3" Style="{StaticResource Radio3Button}" Command="{Binding Path=Select3ReceivingMethodCommand}" IsChecked="{Binding Path=ReceivingMethod3IsSelected}" />
</StackPanel>

Style for Radio1Button: (Others are similar, obviously)

<Style x:Key="Radio1Button" TargetType="{x:Type RadioButton}">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type RadioButton}">
        <Image Name="Button_Image" Source="/Resources/1.Normal.png" SnapsToDevicePixels="True" Width="20" Height="20" />
        <ControlTemplate.Triggers>
          <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Source" Value="/Resources/1.Hover.png" TargetName="Button_Image" />
          </Trigger>
          <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Source" Value="/Resources/1.Disabled.png" TargetName="Button_Image" />
          </Trigger>
          <Trigger Property="IsChecked" Value="True">
            <Setter Property="Source" Value="/Resources/1.Pressed.png" TargetName="Button_Image" />
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

My view model exposes bool properties for the state of each radio button, as indicated in the IsChecked propery for each. I have commands defined, as indicated, as well.

For some reason, the bool properties bound to the IsChecked property on each radio button never get called. (Neither getter nor setter). There are all sorts of other controls on the page and binding is working just dandy-like for them. The UI bits seem to work fine. The proper button images are shown for the state of the button and they function mutually exclusively, as expected. But there is no interaction with my view model.

I've tried pulling out the Command bindings, wondering if they were getting in the way, but no change. I've tried using converters, but the converter was never called.

I would also like a button to be disabled if there is no method assigned. (i.e. If only Primary and Secondary methods are defined, then the '3' radio button should be disabled. I was hoping the Command binding would help with that.)

What am I missing? What is the best way to implement this? (A controls other than radio buttons?)

2

2 Answers

0
votes

it works on my computer, maybe you need to check your DataSource or see the output window from visual studio.

0
votes

Never mind... There was a legacy DataContext assignment getting in the way. Once I cleaned that up, it worked as expected.

Sorry to bother... As you were.. Nothing to see here...