Example #1
0
        /// <summary>
        /// Determines whether the visual object is an ancestor of the descendant visual object.
        /// </summary>
        /// <param name="element">The <see cref="UIElement"/>.</param>
        /// <param name="descendant">The <see cref="DependencyObject"/>.</param>
        /// <returns>
        /// <see langword="true"/> if the <paramref name="element"/> is an ancestor of
        /// <paramref name="descendant"/>; otherwise, <see langword="false"/>.
        /// </returns>
        public static bool IsAncestorOf(this UIElement element, DependencyObject descendant)
        {
            if (element == null || descendant == null)
                return false;

            if (element == descendant)
                return true;

            return descendant.GetVisualAncestors().Contains(element);
        }
        private static void OnVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue != e.OldValue) {
                var appbar = ((BindableAppBar)d).ApplicationBar;

                appbar.IsVisible = (bool)e.NewValue;

                var page = d.GetVisualAncestors().OfType<PhoneApplicationPage>().FirstOrDefault();

                // Swapping bars?
                if (page != null && appbar.IsVisible && page.ApplicationBar != appbar) {
                    page.ApplicationBar = appbar;

                    Log.Info("Set appbar as foreground appbar");
                }
            }
        }
        private static void OnYAxisChanged(DependencyObject element, DependencyPropertyChangedEventArgs eventArgs)
        {
            if (eventArgs.OldValue == eventArgs.NewValue)
                return;

            var chartPanel = element.GetVisualAncestors()
                                    .OfType<ChartPanel>()
                                    .FirstOrDefault();

            if (element is IChartElement)
            {
                var chartElement = (IChartElement)element;
                var yAxis = (Axis)eventArgs.NewValue;

                // Synchronize the attached dependency property ChartPanel.XAxis with 
                // the dependency property ChartElement.XAxis.
                chartElement.YAxis = yAxis;
            }
            else if (element is UIElement)
            {
                // Size of the element might have changed.
                // --> Re-measure element.
                var uiElement = (UIElement)element;
                uiElement.InvalidateMeasure();

                // Reposition element in ChartPanel.
                if (chartPanel != null)
                    chartPanel.InvalidateArrange();
            }

            if (chartPanel != null)
                chartPanel.DetectAxes();
        }
Example #4
0
 private static void OnViewportWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     d.GetVisualAncestors().OfType<DataGrid>().Last().OnViewportWidthChanged(e);
 }
        //--------------------------------------------------------------
        #region Methods
        //--------------------------------------------------------------

        private static void OnPositioningChanged(DependencyObject element, DependencyPropertyChangedEventArgs eventArgs)
        {
            var chartPanel = element.GetVisualAncestors().OfType<ChartPanel>().FirstOrDefault();
            if (chartPanel != null)
                chartPanel.InvalidateArrange();
        }