DataTrigger on RadioButton IsChecked

I have a scenario where I need to hide some content based on whether the checkbox is checked or not checked. For some reason, I can't get this to work the way I expect. The behavior is the opposite of what I expect. If I configure my xaml to post the actual behavior that I see, everything becomes hidden.

In fact, I have two radio buttons labeled Fixed and Cycle. When the Fixed checkbox is selected, I want the text field associated with Fixed to have a visible foreground and the text field associated with the loop to have a transparent foreground and vice versa. What I see is the exact opposite.

Here is my trigger:

<Grid.Resources>
  <Style TargetType="TextBox" x:Key="FixedModeStyle">
    <Setter Property="Foreground" Value="Transparent" />
    <Setter Property="Width" Value="40" />
    <Setter Property="Height" Value="20" />
    <Setter Property="Margin" Value="10" />
    <Style.Triggers>
      <DataTrigger Binding="{Binding IsChecked, 
                             ElementName=rbtFixedMode}" Value="True" >
        <Setter Property="Foreground" 
                Value="{DynamicResource My.Fonts.Global.LightForeground}" />
      </DataTrigger>
      </Style.Triggers>                  
  </Style>
  <Style TargetType="TextBox" x:Key="CycleModeStyle">
    <Setter Property="Foreground" Value="Transparent" />
    <Setter Property="Width" Value="40" />
    <Setter Property="Height" Value="20" />
    <Setter Property="Margin" Value="10" />
    <Style.Triggers>
      <DataTrigger Binding="{Binding IsChecked, 
                   ElementName=rbtCycleMode}" Value="True" >
        <Setter Property="Foreground" 
                Value="{DynamicResource My.Fonts.Global.LightForeground}" />
      </DataTrigger>
    </Style.Triggers>
  </Style>
</Grid.Resources>

Here are my radio buttons and related text fields:

<RadioButton x:Name="rbtFixedMode" Content="Fixed" 
             GroupName="AveragingMode"
             Foreground="{DynamicResource My.Fonts.Global.LightForeground}" 
             IsChecked="{Binding AveragingWindowMode, 
                  Converter={StaticResource EnumToBooleanConverter}, 
                  ConverterParameter={x:Static  Processors:AveragingMode.Fixed}}" />
<DockPanel Grid.Row="1" IsEnabled="{Binding IsChecked, ElementName=rbtFixedMode}">
  <TextBox x:Name="txtFixedIntervalLength" 
           Style="{StaticResource FixedModeStyle}" DockPanel.Dock="Left" 
           Text="{Binding AveragingWindowFixedLength}" />
</DockPanel>

<RadioButton x:Name="rbtCycleMode" Content="Cycle" 
             GroupName="AveragingMode" Grid.Row="2"
             Foreground="{DynamicResource My.Fonts.Global.LightForeground}"                           
             IsChecked="{Binding AveragingWindowMode, 
                  Converter={StaticResource EnumToBooleanConverter}, 
                  ConverterParameter={x:Static Processors:AveragingMode.Cycles}}" />

<DockPanel Grid.Row="3" IsEnabled="{Binding IsChecked, ElementName=rbtCycleMode}">
  <TextBox x:Name="txtCycleIntervalLength" 
           Style="{StaticResource CycleModeStyle}" DockPanel.Dock="Left"  
           Text="{Binding AveragingWindowCycleLength}"/>
  <TextBlock x:Name="txbCycles" Text="Cycles" Margin="4,10"
             Foreground="{DynamicResource My.Fonts.Global.LightForeground}" />
</DockPanel>

Any ideas?

+3
2

- , , . , - , TextBox, , BasedOn .

, , , , , , Kaxaml:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <Page.Resources>

  </Page.Resources>
  <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
      <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
      </Grid.ColumnDefinitions>
        <RadioButton Name="rbCycle" GroupName="g1" Content="Cycle"/>
        <RadioButton Name="rbFixed" GroupName="g1" Content="Fixed" Grid.Column="1"/>
        <TextBox Grid.Row="1" Text="cycle box">
            <TextBox.Style>
                <Style TargetType="{x:Type TextBox}">
                    <Setter Property="Visibility" Value="Hidden"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsChecked, ElementName=rbCycle}" Value="True">
                            <Setter Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBox.Style>
        </TextBox>
        <TextBox Grid.Row="1" Grid.Column="1" Text="fixed box">
            <TextBox.Style>
                <Style TargetType="{x:Type TextBox}">
                    <Setter Property="Visibility" Value="Hidden"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsChecked, ElementName=rbFixed}" Value="True">
                            <Setter Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBox.Style>
        </TextBox>
      </Grid>
  </ScrollViewer>
</Page>
+1

, . , . .

, . , . , , , , , .

+1

All Articles