How do I set CommandParameter in XAML?

后端 未结 2 348
慢半拍i
慢半拍i 2020-12-18 14:48

I have the following XAML:

   
       
            


        
相关标签:
2条回答
  • 2020-12-18 15:17

    I believe it should be this

    <dxg:GridControl Name="theGrid" DataSource="{Binding Path=Groupings}">
      <dxg:GridControl.ContextMenu>
        <ContextMenu>
          <MenuItem x:Name="gridprint"
            Command="{Binding Path=GridPrintCommand}"
            CommandParameter="{Binding ElementName=theGrid}"
          />
        </ContextMenu>
      </dxg:GridControl.ContextMenu>
    

    0 讨论(0)
  • 2020-12-18 15:27

    Try using this:

    <MenuItem x:Name="gridprint"
        CommandParameter="{Binding PlacementTarget, RelativeSource=
             {RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" />
    

    ContextMenus are not part of the WPF's normal VisualTree, so you have to bind using the PlacementTarget to get the object the ContextMenu is attached to

    0 讨论(0)
提交回复
热议问题