.... <sdk:DataGridTemplateColumn Header="Site Address" SortMemberPath="SortableAddress"> <sdk:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding FormattedAddress}" VerticalAlignment="Center" /> </DataTemplate> </sdk:DataGridTemplateColumn.CellTemplate> </sdk:DataGridTemplateColumn> .....
private void MyDataGridName_MouseRightButtonUp(object sender, MouseButtonEventArgs e) { SelectDataRow(MyDataGridName, e.GetPosition(Application.Current.RootVisual)); .......... } private void SelectDataRow(DataGrid dg, Point loc) { //Finds every control in the datagrid at the location var list = VisualTreeHelper.FindElementsInHostCoordinates(loc, dg); if (list == null || list.Count() == 0) return; var row = list.FirstOrDefault(el => el is DataGridRow) as DataGridRow; if (row != null) { dg.SelectedIndex = row.GetIndex(); // make that row selected // Find the text block at the location you clicked... var cellContent = list.FirstOrDefault(el => el is TextBlock) as TextBlock; //Sets the text to be grabbed by the clipboard... (or whatever you want to do with it) _copyText = (cellContent == null) ? "" : cellContent.Text; } else { //It wasn't a row, it was a header - select the header column... var colHeader = list.FirstOrDefault(el => el is System.Windows.Controls.Primitives.DataGridColumnHeader) as System.Windows.Controls.Primitives.DataGridColumnHeader; } }
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.