An app I\'m working on requires a ConverterParameter to be an enum. For this, the regular way to do would be:
{Binding whatever,
Converter={StaticResour
This works for me in a UWP:
<Button Command="{Binding CheckWeatherCommand}">
<Button.CommandParameter>
<local:WeatherEnum>Cold</local:WeatherEnum>
<Button.CommandParameter>
</Button>
This is an answer utilizing resources and without Converters:
View:
<Page
.....
xmlns:local="using:EnumNamespace"
.....
>
<Grid>
<Grid.Resources>
<local:EnumType x:Key="EnumNamedConstantKey">EnumNamedConstant</local:SettingsCats>
</Grid.Resources>
<Button Content="DoSomething" Command="{Binding DoSomethingCommand}" CommandParameter="{StaticResource EnumNamedConstantKey}" />
</Grid>
</Page>
ViewModel
public RelayCommand<EnumType> DoSomethingCommand { get; }
public SomeViewModel()
{
DoSomethingCommand = new RelayCommand<EnumType>(DoSomethingCommandAction);
}
private void DoSomethingCommandAction(EnumType _enumNameConstant)
{
// Logic
.........................
}
There is no Static Markup Extension on UWP (and WinRT platform too).
One of the possible solutions is to create class with enum values as properties and store instance of this class in the ResourceDictionary.
Example:
public enum Weather
{
Cold,
Hot
}
Here is our class with enum values:
public class WeatherEnumValues
{
public static Weather Cold
{
get
{
return Weather.Cold;
}
}
public static Weather Hot
{
get
{
return Weather.Hot;
}
}
}
In your ResourceDictionary:
<local:WeatherEnumValues x:Key="WeatherEnumValues" />
And here we are:
"{Binding whatever, Converter={StaticResource converterName},
ConverterParameter={Binding Hot, Source={StaticResource WeatherEnumValues}}}" />
The most concise way I know of...
public enum WeatherEnum
{
Cold,
Hot
}
Define the enum value in XAML:
<local:WeatherEnum x:Key="WeatherEnumValueCold">Cold</local:WeatherEnum>
And simply use it:
"{Binding whatever, Converter={StaticResource converterName},
ConverterParameter={StaticResource WeatherEnumValueCold}}"