标签绑定到两个单选按钮不起作用 - WPF

Binding of label to two radio buttons not working- WPF

我有 2 个单选按钮和标签。 我希望只有在选中其中一个单选按钮的情况下,标签的可见性 属性 才会 "visible"。

在 MainWindow.xaml:

<Label x:Name="outputFolderLabel" Content="Select destination folder:"     
Height="30" Grid.Row="1" Grid.Column="0" FontSize="13.333" Margin="5 10">
  <Label.Visibility>
      <MultiBinding Converter="{StaticResource FilterConverter}">
          <Binding ElementName ="RadioButNew" Path="IsChecked" Mode="OneWay"/>
          <Binding ElementName ="RadioButUpdate" Path="IsChecked" Mode="OneWay"/>
      </MultiBinding>
   </Label.Visibility>
</Label>

在 MainWindow.xaml.cs:

public class SearchFilterConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return (bool)values[0] || (bool)values[1];
    }
    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

而且它不起作用..有什么建议吗? 我是 WPF 新手..

谢谢!

您正在 return 从您的转换器中获取布尔值。 而不是你必须 return a System.Windows.Visibility.

是:

public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
   if (values[0] is bool && values[1] is bool)
     if ((bool)values[0] || (bool)values[1])
       return Visibility.Visible;

   return Visibility.Collapsed;
}