首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF将FlowDocumentScrollViewer中的电流选择转换为CommandParameter

WPF将FlowDocumentScrollViewer中的电流选择转换为CommandParameter
EN

Stack Overflow用户
提问于 2013-04-04 17:58:51
回答 1查看 248关注 0票数 0

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

代码语言:javascript
复制
 <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>

在模型类中:

代码语言:javascript
复制
 private RelayCommand<System.Windows.Documents.TextSelection> _AddDefaultTriggerCommand;

 public ICommand AddDefaultTriggerCommand
 {
     get
     {
         ...
         this._AddDefaultTriggerCommand = new RelayCommand<TextSelection>(
                     AddDefaultTriggerCommandExecuted,...)
         ...
     }
 }

问题是,在传递给处理程序的参数中,始终为空

代码语言:javascript
复制
 private void AddDefaultTriggerCommandExecuted(System.Windows.Documents.TextSelection parameter)...

我是不是遗漏了什么?标准的windows复制命令如何获得选定的文本?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-04 18:25:01

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

代码语言:javascript
复制
this._AddDefaultTriggerCommand = new RelayCommand<TextSelection>(
                 param => AddDefaultTriggerCommandExecuted(param))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15818369

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档