我想问一下,是否可以
我有两个标签。首先是"流程"第二个是"非流程"。取决于该字符串值,RelayCommand将执行并使用DispatcherTimer触发方法(如果是Process然后是Dispatcher1,如果是Non-Process然后是Dispatcher2)。
XAML:
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDown" >
<cmd:EventToCommand Command="{Binding EmployeeViewM.MeasurementEndExecution}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
我可以使用 CommandParameter 和 CommandParameterValue 将字符串传递给属性吗?
感谢您提出任何建议
答案 0 :(得分:1)
是的,你可以,如下所示:
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDown" >
<cmd:EventToCommand Command="{Binding EmployeeViewM.MeasurementEndExecution}" CommandParameter="Process"/>
</i:EventTrigger>
</i:Interaction.Triggers>
和/或
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDown" >
<cmd:EventToCommand Command="{Binding EmployeeViewM.MeasurementEndExecution}" CommandParameter="Non-Process"/>
</i:EventTrigger>
</i:Interaction.Triggers>
希望您的RelayCommand
(或ICommand
实施)已经接受CommandParameter
。如下所示。
public class RelayCommand : ICommand
{
#region Fields
readonly Action<object> _execute;
readonly Predicate<object> _canExecute;
#endregion // Fields
#region Constructors
/// <summary>
/// Creates a new command that can always execute.
/// </summary>
/// <param name="execute">The execution logic.</param>
public RelayCommand(Action<object> execute)
: this(execute, null)
{
}
/// <summary>
/// Creates a new command.
/// </summary>
/// <param name="execute">The execution logic.</param>
/// <param name="canExecute">The execution status logic.</param>
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
#endregion // Constructors
#region ICommand Members
public bool CanExecute(object parameter)
{
return _canExecute == null ? true : _canExecute(parameter);
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public void Execute(object parameter)
{
_execute(parameter);
}
#endregion // ICommand Members
}