Example #1
0
        private static void OnIDChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if ((e.NewValue == null) || !(d is UIElement))
            {
                return;
            }

            SwitchPresenter parentPresenter = VisualTreeHelperEx.FindAncestorByType <SwitchPresenter>(d);

            if (parentPresenter != null)
            {
                parentPresenter.RegisterID(e.NewValue as string, d as FrameworkElement);
            }
            else
            {
                d.Dispatcher.BeginInvoke(DispatcherPriority.Loaded,
                                         (ThreadStart) delegate()
                {
                    parentPresenter = VisualTreeHelperEx.FindAncestorByType <SwitchPresenter>(d);
                    if (parentPresenter != null)
                    {
                        parentPresenter.RegisterID(e.NewValue as string, d as FrameworkElement);
                    }
                });
            }
        }
 internal void UnregisterPresenter(SwitchPresenter presenter, DependencyObject container)
 {
     if (container != null)
     {
         _presenters.Remove(presenter);
         presenter.SwapTheTemplate(null, false);
     }
 }
        private static void OnLoaded(object sender, RoutedEventArgs e)
        {
            SwitchPresenter sp = sender as SwitchPresenter;

            if (sp._switchRoot == null)
            {
                sp.SwitchParent = VisualTreeHelperEx.FindAncestorByType(sp, typeof(SwitchPanel), false) as SwitchPanel;
            }
        }
        protected override Size MeasureOverride(Size constraint)
        {
            // if first pass, resolve SwitchParent
            if (!_isMeasured && _switchRoot == null)
            {
                SwitchPresenter.OnLoaded(this, null);
                _isMeasured = true;
            }

            _contentPresenter.Measure(constraint);
            return(_contentPresenter.DesiredSize);
        }
        internal UIElement RegisterPresenter(SwitchPresenter presenter)
        {
            UIElement      result = null;
            AnimationPanel ignore;

            result = AnimationPanel.FindAncestorChildOfAnimationPanel(presenter, out ignore);
            if (result != null)
            {
                _presenters.Add(presenter);
                presenter.SwapTheTemplate(ActiveSwitchTemplate, false);
            }
            return(result);
        }