private void TryExpandTree(TreeViewItem element) { var parents = VisualTreeAssist.GetParentsUntil <TreeViewItem, TreeView>(element).ToList(); parents.ForEach(p => p.IsExpanded = true); element.BringIntoView(); }
/// <summary> /// Converts a TreeListViewExpander in a TreeListViewItem level to the left distance /// </summary> /// <param name="value">The TreeListViewExpander value to convert</param> /// <param name="targetType">This parameter is not used</param> /// <param name="parameter">This parameter is not used</param> /// <param name="culture">This parameter is not used</param> /// <returns>The left distance for the given level</returns> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null) { var container = VisualTreeAssist.FindParent <TreeListViewItem>(value); return(container?.Level * 10); } return(null); }
private static void CloseButton_Click(object sender, RoutedEventArgs e) { if (GetIsClose((DependencyObject)sender)) { var button = sender as Button; var window = VisualTreeAssist.FindParent <Window>(button); if (window != null) { window.Close(); } } }
/// <summary> /// Checks if the tree view item is a child item and can be collapsed and calculates the intending by the level. /// </summary> /// <param name="value">The tree view item container.</param> /// <param name="targetType">This parameter is not used.</param> /// <param name="parameter">This parameter is not used.</param> /// <param name="culture">This parameter is not used.</param> /// <returns></returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null) { var container = VisualTreeAssist.FindParent <TreeListViewItem>(value as DependencyObject); if (container != null) { return(container.Level * 10); } } return(null); }
private static void Eement_Loaded(object sender, RoutedEventArgs e) { var element = (DependencyObject)sender; var behavior = GetOrSetBehavior(element); if (!behavior._isCatchedAlready) { var presenter = VisualTreeAssist.FindChild <GridViewHeaderRowPresenter>(element); if (presenter != null) { behavior.Handle(element, presenter.Columns); } } }
private void TryApplyStyle <T>(Style style) where T : FrameworkElement { if (style == null) { return; } var controls = VisualTreeAssist.GetChildren <T>(this); foreach (var control in controls) { control.Style = style; } }
private void TryReadColumns() { var presenter = VisualTreeAssist.FindChild <GridViewHeaderRowPresenter>(_owner); if (presenter != null) { _columns = presenter.Columns; } if (_columns != null) { SetOriginalWidths(); _columns.CollectionChanged += (a, b) => Reset(); } }
private void GetColumns(DependencyObject sender) { var behavior = GetOrSetBehavior(sender); var presenter = VisualTreeAssist.FindChild <GridViewHeaderRowPresenter>(_owner); if (presenter != null) { _columns = presenter.Columns; } if (_columns != null) { foreach (var column in _columns) { column.HeaderTemplate = GetNeutralHeaderTemplate(sender); } } }
private void RibbonLoaded(object sender, RoutedEventArgs e) { Ribbon ribbon = (Ribbon)sender; var child = VisualTreeAssist.FindChild <Grid>(ribbon);// VisualTreeHelper.GetChild((DependencyObject)sender, 0) as Grid; if (child != null) { child.RowDefinitions[0].Height = new GridLength(0, System.Windows.GridUnitType.Pixel); child.RowDefinitions[1].Height = new GridLength(0, System.Windows.GridUnitType.Pixel); } var lines = VisualTreeAssist.GetChilds <Line>(ribbon); if (lines != null) { foreach (Line line in lines) { line.Visibility = Visibility.Collapsed; } } }
private static void DialogResultButton_Click(object sender, RoutedEventArgs e) { var button = sender as Button; var window = VisualTreeAssist.FindParent <Window>(button); if (window != null) { var resultCommand = GetDialogResultCommand(button); if (resultCommand != null) { var args = new WindowClosingArgs(); resultCommand.Execute(args); if (!args.Cancel) { window.DialogResult = args.DialogResult; } } else { window.DialogResult = GetDialogResult(button); } } }
private ScrollContentPresenter FindPresenter() { var internalScrollViewer = VisualTreeAssist.FindChild <ScrollViewer>(_owner); return(VisualTreeAssist.FindChild <ScrollContentPresenter>(internalScrollViewer)); }