2016-10-04 5 views
1

Iは、ラジオボタンFirst又はSecondIsChecked=trueおよび場合Third又はFourthIsChecked=false沈胴時表示さshoulラベルを有します。 ボタンの名前をコンバーターに渡し、コンバーターでそれを折りたたんで表示するかどうかを判断する方法は1つだけですか?WPF結合可視

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition></RowDefinition> 
     <RowDefinition></RowDefinition> 
    </Grid.RowDefinitions> 
    <StackPanel Orientation="Vertical"> 
     <RadioButton Content="Visible" x:Name="First"></RadioButton> 
     <RadioButton Content="Visible" x:Name="Second"></RadioButton> 
     <RadioButton Content="Collapsed" x:Name="Third"/> 
     <RadioButton Content="Collapsed" x:Name="Fourth"></RadioButton> 
    </StackPanel> 
    <Label Content="Test" Grid.Row="1"></Label> 
</Grid> 
+0

isSelected – Paparazzi

答えて

4

あなたはIMultiValueConverterを実装し、いくつかの値にVisibilityをバインドするためにそれを使用することができます。 例が見つかりますhere

0

MVVM LightのようなフレームワークでMVVMパターンを使用することをお勧めします。次に、ビューモデルでは、ラベルがバインドされるLabelVisiblityのプロパティを持つことができます。

MVVMパターンがオプションでない場合、各CheckBoxのCheckedイベントに対してイベントハンドラを追加できます。そこでVisilityを設定します。

public MainWindow() 
    { 
     InitializeComponent(); 

     textBlock.Visibility = Visibility.Collapsed; 

     option1.Checked += Option_Checked; 
     option2.Checked += Option_Checked; 
     option3.Checked += Option_Checked; 
     option4.Checked += Option_Checked; 
    } 

    private void Option_Checked(object sender, RoutedEventArgs e) 
    { 
     var option = (sender as RadioButton); 
     if (option.Name == "option1" || option.Name == "option2") 
      textBlock.Visibility = Visibility.Collapsed; 
     else 
      textBlock.Visibility = Visibility.Visible; 

    } 
関連する問題