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 コピー コマンドは、選択したテキストをどのように取得しますか?

4

1 に答える 1

1

はい、パラメーターを渡さなかったからです。ラムダ式を追加すると、機能するはずです。

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