如果枚举值为(A | B | C),我需要一个可见的控件。
我知道如何使用转换器将控件的可见性绑定到SINGLE枚举(A)。
对于这种情况,我该如何做同样的事情?参数会怎么样?
这是我使用的转换器:
public class EnumToVisibilityConverter : IValueConverter {
public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) {
if ( value == null || parameter == null || !( value is Enum ) )
return Visibility.Hidden;
string State = value.ToString( );
string parameterString = parameter.ToString( );
foreach ( string state in parameterString.Split( ',' ) ) {
if ( State.Equals( state ) )
return Visibility.Visible;
}
return Visibility.Hidden;
}
public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) {
throw new NotImplementedException( );
}
}
这是XAML绑定:
<UserControl.Visibility>
<Binding
Path="GameMode" Source="{x:Static S:Settings.Default}" Converter="{StaticResource ETVC}"
ConverterParameter="{x:Static E:GameMode.AudiencePoll}" Mode="OneWay"/>
</UserControl.Visibility>
如何将(A | B | C)传递给转换器参数?它只是简单地说{x:Static E:Enum.A | E:Enum.B | E:Enum.C}
吗?
答案 0 :(得分:8)
我能够找到答案here
为了节省每个人的旅行
<Binding Path="PathGoesHere" Source="{x:Static SourceGoesHere}" Converter="{StaticResource ConverterKeyGoesHere}">
<Binding.ConverterParameter>
<EnumTypeGoesHere>A,B,C</EnumTypeGoesHere>
</Binding.ConverterParameter>
</Binding>
答案 1 :(得分:1)
概述here语法应为
<Binding Path="PathGoesHere" Source="{x:Static SourceGoesHere}" Converter="{StaticResource ConverterKeyGoesHere}">
<Binding.ConverterParameter>
A|B|C
</Binding.ConverterParameter>
</Binding>
因为逗号分隔XML并且参数始终是一个单独的枚举值。虽然
没有智能感知