Reputation: 7515
I am trying to pass 2 hardcoded parameters through a CommandParameter to a DelegateCommand. I currently have my delegate command set up as follows because it seemed to make the most sense given the limitations
private DelegateCommand<Tuple<string, PartImportType>> _mySettingsImportCommandAsync;
public object MyImportCommandAsync
{
get
{
if (_mySettingsImportCommandAsync == null)
{
_mySettingsImportCommandAsync = new DelegateCommand<Tuple<string, PartImportType>>(async partPayload => await OnOpenPartsSelectorCommandAsync(partPayload.Item1, partPayload.Item2));
}
return _mySettingsImportCommandAsync;
}
}
The problem becomes how do I pass the tuple in the xaml? I want to do something like this, but obviously this doesn't work
<Button Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" Content="Import Settings From DB" Command="{Binding MySettingsImportCommandAsync}" CommandParameter="{system:Tuple<string, PartImportType> ("Event", viewEnums:PartImportType.SimEvent}" Margin="5">
How can I do this? Or is there a better way to get this information from my XAML to my viewmodels? I've looked at the multi-binding approach but can't seem to make that work given that I'm not binding to anything in the view...just trying to pass some hard coded values.
After taking the suggestion in the first answer my updated XAML looks like
<Button Grid.Row="1" Grid.Column="1"
Content="{Binding Part}"
Command="{Binding Path=OpenPartsSelectorCommandAsync}">
<Button.CommandParameter>
<enum:PartImportCommand
Argument="Part"
PartImportType="{x:Static enum:PartImportType.GenericPart}"
Location="Front"/>
</Button.CommandParameter>
</Button>
Upvotes: 0
Views: 561
Reputation: 128060
Instead of a Tuple (which has no parameterless constructor), use a class or struct with two read/write properties (with more appropriate names than Item1 and Item2):
public class MyParam
{
public string Item1 { get; set; }
public PartImportType Item2 { get; set; }
}
and use it like this:
<Button ...>
<Button.CommandParameter>
<paramNamespace:MyParam
Item1="Event"
Item2="{x:Static viewEnums:PartImportType.SimEvent}"/>
</Button.CommandParameter>
</Button>
Upvotes: 1