Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //DISCLAIMER: This code was copied from an article, and is by no means how I would code.
- //I am ashamed to even have this in my pastebin...
- private void ToggleButton_Click(object sender, RoutedEventArgs e)
- {
- DependencyObject obj = (DependencyObject)e.OriginalSource;
- while (!(obj is DataGridRow) && obj != null) obj = VisualTreeHelper.GetParent(obj);
- if (obj is DataGridRow)
- {
- if ((obj as DataGridRow).DetailsVisibility == Visibility.Visible)
- {
- (obj as DataGridRow).IsSelected = false;
- }
- else
- {
- (obj as DataGridRow).IsSelected = true;
- }
- }
- }
- public static FrameworkElement GetTemplateChildByName(DependencyObject parent, string name)
- {
- int childnum = VisualTreeHelper.GetChildrenCount(parent);
- for (int i = 0; i < childnum; i++)
- {
- var child = VisualTreeHelper.GetChild(parent, i);
- if (child is FrameworkElement && ((FrameworkElement)child).Name == name)
- {
- return child as FrameworkElement;
- }
- else
- {
- var s = GetTemplateChildByName(child, name);
- if (s != null)
- return s;
- }
- }
- return null;
- }
- private void dataGrid1_RowDetailsVisibilityChanged(object sender, DataGridRowDetailsEventArgs e)
- {
- DataGridRow row = e.Row as DataGridRow;
- FrameworkElement tb = GetTemplateChildByName(row, "RowHeaderToggleButton");
- if (tb != null)
- {
- if (row.DetailsVisibility == System.Windows.Visibility.Visible)
- {
- (tb as ToggleButton).IsChecked = true;
- }
- else
- {
- (tb as ToggleButton).IsChecked = false;
- }
- }
- }
- //DISCLAIMER: This code was copied from an article, and is by no means how I would code.
- //I am ashamed to even have this in my pastebin...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement