In an event handler for a Command for a DataGrid, I get DataGridCell in ExecutedRoutedEventArgs. However, I couldn't figure out how to get its associated DataGrid and DataGridRow. Your help is much appreciated.
相关问题
- VNC control for WPF application
- WPF Binding from System.Windows.SystemParameters.P
- XAML: Applying styles to nested controls
- How can I add a horizontal line (“goal line”) for
- How to properly change a resource dictionary
You probably want to set some sort of
RelativeSource
binding that can get you the "parent grid/row" via a{RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}
, but your question got me thinking...You could:
Use Reflection:
Use the
VisualTreeHelper
:Here is what I think is a complete answer...
One way you could do is by passing one or both of the needed elements in as a CommandParameter:
If you need both, you could add a multi-value converter that combines them into a
Tuple
(or leave it as an object[])Then in your code-behind you can access it by using
e.Parameter