// Don't update content until done transitioning
        private static object CoerceContent(object element, object value)
        {
            TransitionPresenter te = (TransitionPresenter)element;

            if (te.IsTransitioning)
            {
                return(te.CurrentContentPresenter.Content);
            }
            return(value);
        }
        private static object CoerceTransition(object element, object value)
        {
            TransitionPresenter te = (TransitionPresenter)element;

            if (te.IsTransitioning)
            {
                return(te._activeTransition);
            }
            return(value);
        }
        // Force clip to be true if the active Transition requires it
        private static object CoerceClipToBounds(object element, object value)
        {
            TransitionPresenter transitionElement = (TransitionPresenter)element;
            bool clip = (bool)value;

            if (!clip && transitionElement.IsTransitioning)
            {
                Transition transition = transitionElement.Transition;
                if (transition.ClipToBounds)
                {
                    return(true);
                }
            }
            return(value);
        }
Exemplo n.º 4
0
        //public Grid ayLayerAboveArea = null;

        #region 为元素注册事件
        public override void OnApplyTemplate()
        {
            ControlTemplate baseWindowTemplate = this.Template;

            this.StateChanged += AyWindowShellNew_StateChanged;
            TransitionPresenter tp = (TransitionPresenter)baseWindowTemplate.FindName("tpMainImage", this);

            if (tp != null)
            {
                int a;
                if (int.TryParse(AyWindowShellConfigSetting.GetXmlValue("skinSwitchAnimation"), out a))
                {
                    tp.Transition = AyTransitionGetter.AyTransitionOneWay()[a];
                }
                else
                {
                    tp.Transition = AyTransitionGetter.AyTransitionOneWay()[16];
                }
            }

            Button skinBtn = (Button)baseWindowTemplate.FindName("PART_SKIN", this);

            if (skinBtn != null)
            {
                skinBtn.Click += delegate
                {
                    if (SkinWindowMethodOverride != null)
                    {
                        SkinWindowMethodOverride();
                    }
                    else
                    {
                        OpenSkinWindowShow();
                    }
                };
            }
            Button closeBtn = (Button)baseWindowTemplate.FindName("PART_CLOSE", this);

            if (closeBtn != null)
            {
                closeBtn.Click += delegate
                {
                    try
                    {
                        if (CloseWindowMethodOverride != null)
                        {
                            CloseWindowMethodOverride();
                        }
                        else
                        {
                            DoCloseWindow();
                        }
                    }
                    catch
                    {
                    }
                };
            }


            Button minBtn = (Button)baseWindowTemplate.FindName("PART_MIN", this);

            if (minBtn != null)
            {
                minBtn.Click += delegate
                {
                    if (MinWindowMethodOverride != null)
                    {
                        MinWindowMethodOverride();
                    }
                    else
                    {
                        DoMinWindow();
                    }
                };
            }

            Button maxBtn = (Button)baseWindowTemplate.FindName("PART_MAX", this);

            if (maxBtn != null)
            {
                maxBtn.Click += delegate
                {
                    if (MaxWindowMethodOverride != null)
                    {
                        MaxWindowMethodOverride();
                    }
                    else
                    {
                        DoRestoreOrMax();
                    }
                };
            }

            Button menuWindow = (Button)baseWindowTemplate.FindName("PART_MENU", this);

            if (menuWindow != null)
            {
                if (WindowMenu != null)
                {
                    WindowMenuVisibility       = Visibility.Visible;
                    WindowMenu.Placement       = PlacementMode.Bottom;
                    WindowMenu.PlacementTarget = menuWindow;
                }

                menuWindow.Click += delegate
                {
                    if (MenuWindowMethodOverride != null)
                    {
                        MenuWindowMethodOverride();
                    }
                    else
                    {
                        ShowWindowMenu();
                    }
                };
            }

            Button restoreBtn = (Button)baseWindowTemplate.FindName("restoreWindow", this);

            if (restoreBtn != null)
            {
                restoreBtn.Click += delegate
                {
                    if (MaxWindowMethodOverride != null)
                    {
                        MaxWindowMethodOverride();
                    }
                    else
                    {
                        DoRestoreOrMax();
                    }
                };
            }
            AllCP = (ContentPresenter)baseWindowTemplate.FindName("AllCP", this);

            ayLayerArea      = (Grid)baseWindowTemplate.FindName("AyLayerArea", this);
            ayLayerAboveArea = (Grid)baseWindowTemplate.FindName("AyLayerAboveArea", this);
            AyWindowMaskArea = GetTemplateChild("AyWindowMaskArea") as Rectangle;

            if (this.WindowState == WindowState.Normal)
            {
                restoreWindowVisibility = Visibility.Collapsed;
                maxWindowVisibility     = Visibility.Visible;
            }
            else
            {
                restoreWindowVisibility = Visibility.Visible;
                maxWindowVisibility     = Visibility.Collapsed;
            }



            if (WindowState == WindowState.Maximized)
            {
            }
            if (p != null)
            {
                p.Radius          = CornerRadius.TopLeft;
                p.StrokeThickness = BorderThickness.Top;
                p.Stroke          = BorderBrush;
                this.BgData       = p;
            }

            AyBackgroundBehindLayer = (Border)baseWindowTemplate.FindName("AyBackgroundBehindLayer", this);
            AyBackgroundLayer       = (Border)baseWindowTemplate.FindName("AyBackgroundLayer", this);
        }
        private static void OnContentTemplateSelectorChanged(object element, DependencyPropertyChangedEventArgs e)
        {
            TransitionPresenter te = (TransitionPresenter)element;

            te.CurrentContentPresenter.ContentTemplateSelector = (DataTemplateSelector)e.NewValue;
        }
        private static void OnContentChanged(object element, DependencyPropertyChangedEventArgs e)
        {
            TransitionPresenter te = (TransitionPresenter)element;

            te.BeginTransition();
        }