private static void Expandable_Changed(DependencyObject obj, DependencyPropertyChangedEventArgs e) { var el = obj as FrameworkElement; if ((bool)e.NewValue) { // the object is marked expandable, wrap it in a ExpandableWrapper. var parent = el?.Parent as ExpandingStackPanel; if (parent == null) { return; } var index = parent.Children.IndexOf(el); if (index < 0) { return; } parent.Children.RemoveAt(index); var wrapper = new ExpandableWrapper(el); parent.Children.Insert(index, wrapper); if (DesignerProperties.GetIsInDesignMode(parent)) { wrapper.Opacity = 0.4; } else if (!parent.Expanded) { wrapper.Opacity = 0; if (parent.Orientation == Orientation.Vertical) { wrapper.Scale.ScaleY = 0; } else if (parent.Orientation == Orientation.Horizontal) { wrapper.Scale.ScaleX = 0; } el.Focusable = false; } } else { // the object is marked not expandable, remove a wrapper if it exists var wrapper = el?.Parent as ExpandableWrapper; var parent = wrapper?.Parent as ExpandingStackPanel; if (parent == null) { return; } var index = parent.Children.IndexOf(wrapper); if (index < 0) { return; } parent.Children.RemoveAt(index); parent.Children.Insert(index, el); el.Focusable = wrapper.ChildFocusableDefault; } }
private static void Expandable_Changed(DependencyObject obj, DependencyPropertyChangedEventArgs e) { var el = obj as FrameworkElement; if ((bool)e.NewValue) { // the object is marked expandable, wrap it in a ExpandableWrapper. var parent = el?.Parent as ExpandingStackPanel; if (parent == null) return; var index = parent.Children.IndexOf(el); if (index < 0) return; parent.Children.RemoveAt(index); var wrapper = new ExpandableWrapper(el); parent.Children.Insert(index, wrapper); if (DesignerProperties.GetIsInDesignMode(parent)) { wrapper.Opacity = 0.4; } else if (!parent.Expanded) { wrapper.Opacity = 0; if (parent.Orientation == Orientation.Vertical) wrapper.Scale.ScaleY = 0; else if (parent.Orientation == Orientation.Horizontal) wrapper.Scale.ScaleX = 0; el.Focusable = false; } } else { // the object is marked not expandable, remove a wrapper if it exists var wrapper = el?.Parent as ExpandableWrapper; var parent = wrapper?.Parent as ExpandingStackPanel; if (parent == null) return; var index = parent.Children.IndexOf(wrapper); if (index < 0) return; parent.Children.RemoveAt(index); parent.Children.Insert(index, el); el.Focusable = wrapper.ChildFocusableDefault; } }