0

尝试将流查看器中的选定文本作为参数获取到命令

 <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,...)
         ...
     }
 }

问题是传递给处理程序的参数始终为 null

 private void AddDefaultTriggerCommandExecuted(System.Windows.Documents.TextSelection parameter)...

我错过了什么吗?标准的 windows Copy 命令如何获取选定的文本?

4

1 回答 1

1

是的,因为你没有传递参数。添加一个 lambda 表达式,它应该可以工作:

this._AddDefaultTriggerCommand = new RelayCommand<TextSelection>(
                 param => AddDefaultTriggerCommandExecuted(param))
于 2013-04-04T18:25:01.990 回答