2011-05-17 20 views
3

ラジオボタンがチェックされているかチェックされていないかに基づいてコンテンツを非表示にする必要があるシナリオがあります。なんらかの理由で、私はこれを期待通りに動作させることができません。その振る舞いは、私が期待しているものの反対です。私が実際に見ている振る舞いに対応するためにxamlを調整すると、すべてが隠されてしまいます。DataTrigger on RadioButton IsChecked

私が持っているのは、固定とサイクルという2つのラジオボタンです。 Fixedがチェックされている場合、Fixedに関連付けられているテキストボックスには、表示されているフォアグラウンドがあり、Cycleに関連付けられているテキストボックスには透明なフォアグラウンドが付いています。私が見ているのは正反対です。

は、ここに私のトリガーです:

<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> 

ここにあります私のラジオボタンと関連するテキストボックス:

<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> 

任意のアイデアは?

+0

キーボードとユーザーの間に問題があることがわかります。明らかに、チームの開発者は、自分のテキストボックスで使用していたLightForegroundスタイルを、自分の背景と同じ色に変更して透明な外観にしました。 @ H-Bと@ robert-rossneyに感謝します。 – KyleLib

答えて

1

テキストを透明にするだけで、ユーザーは透明な状態で編集することができます。コードはやや難解で冗長ですが、同じセッターを含むTextBoxの2つのスタイルを作成せず、ベーススタイルを作成し、サブスタイルに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> 
+0

入力いただきありがとうございます。私はテキストを隠すことに関するあなたの声明に同意します。 FWIW、私はまた、テキストボックスを含むドックパネルを無効にして、ユーザーがそれに焦点を当てないようにします。この要件は、ユーザーが数値サンプルのストリームを平均する方法を指定する設定機能を提供することです。選択肢は、固定**時間間隔、またはヘルツで分解された**サイクル**です。追加されたコンテンツは時間の単位などのテキストボックスと一緒に表示されますが、簡潔さのために省略されていますが、これはチェックされているチェックボックスの文脈では意味がありません。 – KyleLib

1

あなたの場合あなたのラジオボタンの値を設定するバインディングを使用している、グループを使用しないでください。グループを使用している場合は、バインディングを使用しないでください。 2人は一緒にうまく遊ばない。

これはあなたが見ているものの原因ではないかもしれません。しかし、私はそれが賭ける。また、ボタンをクリックしてもバインディングが機能しなくなるため、問題を診断する能力は確かに妨げられています。

関連する問題