Below you see the stackPanel where the user has to choose an option from the enum using radio buttons. So, CoffeeStrength is an enumeration and using a converter, I am able to set the right value.
<StackPanel Grid.Column="0" Orientation="Vertical" HorizontalAlignment="Center">
<Label FontWeight="Bold">Strength</Label>
<RadioButton GroupName="Strength" IsChecked="{Binding Path=CoffeeStrength, Converter={StaticResource EnumToBool}, ConverterParameter=Weak}">Weak</RadioButton>
<RadioButton GroupName="Strength" IsChecked="{Binding Path=CoffeeStrength, Converter={StaticResource EnumToBool}, ConverterParameter=Normal}">Normal</RadioButton>
<RadioButton GroupName="Strength" IsChecked="{Binding Path=CoffeeStrength, Converter={StaticResource EnumToBool}, ConverterParameter=Strong}">Strong</RadioButton>
</StackPanel>
Below you see my button, which uses a custom class as CommandParameter. I would like to add the value above (CoffeeStrength) as an additional parameter in this command, instead of saving the value to CoffeeStrength in my ViewModel (see binding).
<Button Content="Cappuccino + sugar"
Command="{Binding DrinkCommand}"
Style="{StaticResource DrinkButton}">
<Button.CommandParameter>
local:DrinkCommandParameters Name="Cappuccino" Milk="False" Sugar="True"/>
</Button.CommandParameter>
</Button>
In other words, I would like to remove the CoffeeStrength property from my ViewModel and only pass it into DrinkCommand. Since I only need to know the value when the command is activated. Below you see the enum and the unneeded? property in the viewmodel. The setter is never used in the code, since the user decides the strength.
public enum Strength
{
Normal = 0, Weak, Strong
}
private Strength _coffeeStrength;
public Strength CoffeeStrength
{
get { return _coffeeStrength; }
set { _coffeeStrength = value; RaisePropertyChanged(() => CoffeeStrength); }
}
Is there a way to remove the CoffeeStrength property from the ViewModel and pass the value directly to the DrinkCommand in XAML?
CoffeeStrengthto yourDrinkCommandParametersclass? I have absolutely no idea what you're getting at about "saving it to the viewmodel first", so you might also want to provide a much more clear and complete explanation of what you're trying to do. I think you may be leaving out a few steps.local:DrinkCommandParameters Name="Cappuccino" Milk="False" Sugar="True" Strength={Binding CoffeeStrength}/>without having any issues. But what I'm looking for is a way to bind the value directly from the radio buttons to DrinkCommandParameters. Do you understand what I mean? @EdPlunkettDrinkCommandParameters.CoffeeStrengthto the selected value of that radio button group?