尝试将流查看器中选定的文本作为参数获取到命令
<FlowDocumentScrollViewer Name="_OutputBox">
<FlowDocument>
<FlowDocument.ContextMenu >
<ContextMenu>
<MenuItem Header="New"
Command="{Binding AddDefaultTriggerCommand}"
CommandParameter="{Binding ElementName=_OutputBox, Path=Selection}">
</MenuItem>
</ContextMenu>
</FlowDocument.ContextMenu>
</FlowDocument>
</FlowDocumentScrollViewer>在模型类中:
private RelayCommand<System.Windows.Documents.TextSelection> _AddDefaultTriggerCommand;
public ICommand AddDefaultTriggerCommand
{
get
{
...
this._AddDefaultTriggerCommand = new RelayCommand<TextSelection>(
AddDefaultTriggerCommandExecuted,...)
...
}
}问题是,在传递给处理程序的参数中,始终为空。
private void AddDefaultTriggerCommandExecuted(System.Windows.Documents.TextSelection parameter)...我是不是遗漏了什么?标准的windows复制命令如何获得选定的文本?
发布于 2013-04-04 18:25:01
是的,因为你没有传递参数。添加lambda表达式,它应该可以工作:
this._AddDefaultTriggerCommand = new RelayCommand<TextSelection>(
param => AddDefaultTriggerCommandExecuted(param))https://stackoverflow.com/questions/15818369
复制相似问题