Suppose you have MainWindow, and buttons are placed in it.
Create MainWindowViewModeland install it as DataContextfor MainWindow.
ICommand ViewModel bind ICommand, . ICommand RelayCommand, DelegateCommand , .
, , . , Enum , .
Enum
public enum ActionType
{
Action1,
Action2,
Action3 and so on...
}
:
<Button Command="{Binding CommandInstance}"
CommandParameter="{x:Type local:ActionType.Action1}"/>
<Button Command="{Binding CommandInstance}"
CommandParameter="{x:Type local:ActionType.Action2}"/>
local , enum.
enum :
private void CommandMethod(ActionType action)
{
AnotherWindow anotherWindow = new AnotherWindow(action);
anotherWindow.Show();
}
, , , , .
, ViewModel , Service , / .
UPDATE
Views, . , IMultiValueConverter.
:
<Button Command="{Binding TestCommand}">
<Button.Resources>
<sys:String x:Key="Rush">Rush</sys:String>
<sys:String x:Key="Warehouse">Warehouse</sys:String>
</Button.Resources>
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource MultiValuesReturnConverter}">
<Binding Source="{StaticResource Rush}"/>
<Binding Source="{StaticResource Warehouse}"/>
</MultiBinding>
</Button.CommandParameter>
</Button>
sys System XAML:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
, XAML, XAML . , , "" .
, , :
public class MultiValuesReturnConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType,
object parameter, CultureInfo culture)
{
return values.ToList<object>();
}
public object[] ConvertBack(object value, Type[] targetTypes,
object parameter, CultureInfo culture)
{
throw new System.NotImplementedException();
}
}
:
private void CommandMethod(object parameter)
{
IList<object> values = parameter as List<object>;
AnotherWindow anotherWindow = new AnotherWindow(action);
anotherWindow.Show();
}