2016-10-04 62 views
1

我有標籤時單選FirstSecondIsChecked=true和摺疊是建議立即進行刪除可見當ThirdFourthIsChecked=false。 是否只有一種方法可以將按鈕的名稱傳遞給轉換器,並在轉換器中決定是否摺疊或可見?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模式與框架如MVVM Light。然後在視圖模型中,您可以擁有Label綁定到的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; 

    }