In my UI I have multiple buttons to call the OpenItemDialog and I would like to reuse the method to call the dialoge by using the CommandParameter to differentiate the initiating button.
How can I do this using the RelayCommand?
Solved! Go to Solution.
This community sample shows how to do this: arcgis-pro-sdk-community-samples/Map-Exploration/TableControlsDockpane at master · Esri/arcgis-pro-s...
In the xaml you can specify the CommandParameter:
<Button Command="{Binding DataContext.TableCloseCommand, RelativeSource={RelativeSource AncestorType={x:Type TabControl}}}"
CommandParameter="{Binding TableName}" >
TableName in this example is of the type string.
In the code behind you can use the CommandParameter by simple adding 'param' to your RelayCommand as shown here:
public ICommand TableCloseCommand { get; set; }
public AttributeTableViewModel()
{
TableCloseCommand = new RelayCommand((param) => OnCloseTab(param), () => true);
}
private void OnCloseTab(object param)
{
// cast the [object] param to the correct type [string]
string tableName = param.ToString();
// use your TableName CommandParameter for processing
}
This community sample shows how to do this: arcgis-pro-sdk-community-samples/Map-Exploration/TableControlsDockpane at master · Esri/arcgis-pro-s...
In the xaml you can specify the CommandParameter:
<Button Command="{Binding DataContext.TableCloseCommand, RelativeSource={RelativeSource AncestorType={x:Type TabControl}}}"
CommandParameter="{Binding TableName}" >
TableName in this example is of the type string.
In the code behind you can use the CommandParameter by simple adding 'param' to your RelayCommand as shown here:
public ICommand TableCloseCommand { get; set; }
public AttributeTableViewModel()
{
TableCloseCommand = new RelayCommand((param) => OnCloseTab(param), () => true);
}
private void OnCloseTab(object param)
{
// cast the [object] param to the correct type [string]
string tableName = param.ToString();
// use your TableName CommandParameter for processing
}
Thanks Wolf, that was precisely what I needed. 👍