x:UWP XAML中的静态

我正在处理的应用程序需要ConverterParameter作为枚举。 为此,常规方法是:

{Binding whatever, Converter={StaticResource converterName}, ConverterParameter={x:Static namespace:Enum.Value}} 

但是,UWP平台x:名称空间似乎没有静态扩展名。

有谁知道是否有一个不依赖于x的解决方案:静态用于比较绑定中的枚举?

这在UWP中对我有用:

  

UWP(以及WinRT平台)上没有静态标记扩展。

其中一个可能的解决方案是使用枚举值作为属性创建类,并在ResourceDictionary中存储此类的实例。

例:

 public enum Weather { Cold, Hot } 

这是我们的枚举值的类:

 public class WeatherEnumValues { public static Weather Cold { get { return Weather.Cold; } } public static Weather Hot { get { return Weather.Hot; } } } 

在您的ResourceDictionary中:

  

我们在这里:

 "{Binding whatever, Converter={StaticResource converterName}, ConverterParameter={Binding Hot, Source={StaticResource WeatherEnumValues}}}" /> 

我所知道的最简洁的方式……

 public enum WeatherEnum { Cold, Hot } 

在XAML中定义枚举值:

 Cold 

并简单地使用它:

 "{Binding whatever, Converter={StaticResource converterName}, ConverterParameter={StaticResource WeatherEnumValueCold}}" 

这是一个利用资源而没有转换器的答案:

查看

    EnumNamedConstant     

视图模型

  public RelayCommand DoSomethingCommand { get; } public SomeViewModel() { DoSomethingCommand = new RelayCommand(DoSomethingCommandAction); } private void DoSomethingCommandAction(EnumType _enumNameConstant) { // Logic ......................... }