private static void DataGridCellLoaded(DataGridCell sender, RoutedEventArgs e) { DataGridCell dataGridCell = (DataGridCell)sender; if (DataGridCellHelper.GetDataGrid(dataGridCell) == null) { DataGridCellHelper.SetDataGrid(dataGridCell, dataGridCell.TryFindParent <DataGrid>()); } }
private void menuCreateAwl_Click(object sender, RoutedEventArgs e) { if (sender is DependencyObject) { DependencyObject depObj = (DependencyObject)e.OriginalSource; ContextMenu contextMenu = depObj.TryFindParent <ContextMenu>(); DataGridCell dataCell = (DataGridCell)contextMenu.PlacementTarget; DataGridRow dataRow = dataCell.TryFindParent <DataGridRow>(); DataGrid dataGrid = dataCell.TryFindParent <DataGrid>(); ProjectBlockInfo prjBlkInfo = (ProjectBlockInfo)dataGrid.ItemContainerGenerator.ItemFromContainer(dataRow); Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.DefaultExt = ".AWL"; dlg.Filter = "AWL-Code (.AWL)|*.AWL"; if (dlg.ShowDialog() == true) { string filename = dlg.FileName; StreamWriter wrt = new StreamWriter(filename, false, Encoding.GetEncoding("ISO-8859-1")); wrt.Write(prjBlkInfo.GetSourceBlock()); wrt.Close(); } } }
private static void CellPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { DataGridCell dataGridCell = dependencyObject as DataGridCell; if (dataGridCell != null && e.NewValue != e.OldValue && e.NewValue is bool) { dataGridCell.Loaded -= new RoutedEventHandler(DataGridCellHelper.DataGridCellLoaded); dataGridCell.Unloaded -= new RoutedEventHandler(DataGridCellHelper.DataGridCellUnloaded); DataGrid dataGrid = null; if ((bool)e.NewValue) { dataGrid = dataGridCell.TryFindParent <DataGrid>(); dataGridCell.Loaded += new RoutedEventHandler(DataGridCellHelper.DataGridCellLoaded); dataGridCell.Unloaded += new RoutedEventHandler(DataGridCellHelper.DataGridCellUnloaded); } DataGridCellHelper.SetDataGrid(dataGridCell, dataGrid); } }