这里有一个部分答案:WPF Multiple Enum Flags to Converter Parameter?,其中所提出的解决方案确实松散了编译时类型检查,因为它使用字符串值而不是实际枚举值。这可能会在运行时导致错误。
为经验丰富的开发人员提供的其他信息:这与在nameof存在之前的INotifyPropertyChange存在多年的相同问题,或者对于替代的soso替代品来说都是lamda的问题。
实际上,我们可以将一个枚举参数传递为:ConverterParameter = {x:Static module:MyEnum.MyEnumValue},并且仍然保持编译时类型检查。
但是如何在XAML中继续对带有标志值的倍数枚举进行编译时类型检查?
我想做的事的例子:
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=Item.SimulationNatureType}"
Value="{x:Static core:SimulationNatureType.TimeDomain | x:Static core:SimulationNatureType.FrequencyScan}">
</Condition>
...
同时
<MultiDataTrigger.Conditions>
<Condition ... Value="TimeDomain,FrequencyScan">
</Condition>
</MultiDataTrigger.Conditions>
只需将字符串传递给条件的值,以下方法应该起作用:
<MultiDataTrigger.Conditions>
<Condition ...>
<Condition.Value>
<core:SimulationNatureType>TimeDomain,FrequencyScan</core:SimulationNatureType>
</Condition.Value>
</Condition>
</MultiDataTrigger.Conditions>
就像其他信息一样,这就是答案对我的帮助:
((我知道我的通用转换器不好...对不起... 1 = true,2 = false,4 = null)
<Style TargetType="Image" x:Key="ImageStyleForSimulatedInfoSimulationValues">
<Style.Setters>
<Setter Property="Source" Value="pack://application:,,,/WpfUtil;component/Images/NotApplicable16x16.png"></Setter>
</Style.Setters>
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Value="True">
<Condition.Binding>
<Binding Path="Item.SimulationNatureType" Converter="{StaticResource EnumWithFlagsHavingSomeSpecificFlagSetToBoolean}">
<Binding.ConverterParameter>
<core:SimulationNatureType>TimeDomain, FrequencyScan</core:SimulationNatureType>
</Binding.ConverterParameter>
</Binding>
</Condition.Binding>
</Condition>
<Condition Value="True" Binding="{Binding Path=Item.IsValidForValues, ConverterParameter=1,
Converter={StaticResource NullableBooleanToBooleanUniversalConverter}}">
</Condition>
</MultiDataTrigger.Conditions>
<Setter Property="Source" Value="pack://application:,,,/WpfUtil;component/Images/OkSmall16x16.png" />
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Value="True">
<Condition.Binding>
<Binding Path="Item.SimulationNatureType" Converter="{StaticResource EnumWithFlagsHavingSomeSpecificFlagSetToBoolean}">
<Binding.ConverterParameter>
<core:SimulationNatureType>TimeDomain, FrequencyScan</core:SimulationNatureType>
</Binding.ConverterParameter>
</Binding>
</Condition.Binding>
</Condition>
<Condition Value="True" Binding="{Binding Path=Item.IsValidForValues, ConverterParameter=6,
Converter={StaticResource NullableBooleanToBooleanUniversalConverter}}">
</Condition>
</MultiDataTrigger.Conditions>
<Setter Property="Source" Value="pack://application:,,,/WpfUtil;component/Images/Warning16x16.png" />
</MultiDataTrigger>
</Style.Triggers>
</Style>