// For most of the UWP controls, this custom VisualStateManager is injected to prevent the default Windows
        // VSM from handling states which the Forms VSM is already managing.
        // The exception are the controls which are built on TextBox (SearchBar, Entry, Editor); there's a UWP
        // bug wherein the GoToStateCore override for those controls is never called (Item 10976357 in VSTS)
        // So until that's resolved, the FormsTextBox control is doing that work as best it can.

        protected override bool GoToStateCore(Control control, FrameworkElement templateRoot, string stateName,
                                              Microsoft.UI.Xaml.VisualStateGroup @group, Microsoft.UI.Xaml.VisualState state, bool useTransitions)
        {
            // If this custom VSM is in play, it's because the control is using the Forms VSM or the user has disabled
            // legacy color handling. Either way, we may need to prevent the Windows VSM from transitioning to the new
            // state. So we intercept the transition here.

            if (ShouldIntercept(control, state, stateName))
            {
                return(false);
            }

            return(base.GoToStateCore(control, templateRoot, stateName, @group, state, useTransitions));
        }
Пример #2
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _rootGrid = GetTemplateChild("RootGrid") as Microsoft.UI.Xaml.Controls.Grid;
            if (_rootGrid != null)
            {
                var stateGroups = WVisualStateManager.GetVisualStateGroups(_rootGrid).ToList();
                _DeleteButtonVisibleStateGroups = stateGroups.SingleOrDefault(sg => sg.Name == "ButtonStates");
                if (_DeleteButtonVisibleStateGroups != null)
                {
                    _DeleteButtonVisibleState = _DeleteButtonVisibleStateGroups.States.SingleOrDefault(s => s.Name == "ButtonVisible");
                }
                UpdateClearButtonVisible();
            }

            _scrollViewer = GetTemplateChild("ContentElement") as ScrollViewer;
        }
Пример #3
0
        VisualStateCache PseudoDisable(Control control)
        {
            if (VisualTreeHelper.GetChildrenCount(control) == 0)
            {
                control.ApplyTemplate();
            }

            WVisualStateManager.GoToState(control, "Disabled", true);

            var rootElement = (FrameworkElement)VisualTreeHelper.GetChild(control, 0);

            var cache = new VisualStateCache();
            IList <WVisualStateGroup> groups = WVisualStateManager.GetVisualStateGroups(rootElement);

            WVisualStateGroup common = null;

            foreach (var group in groups)
            {
                if (group.Name == "CommonStates")
                {
                    common = group;
                }
                else if (group.Name == "FocusStates")
                {
                    cache.FocusStates = group;
                }
                else if (cache.FocusStates != null && common != null)
                {
                    break;
                }
            }

            if (cache.FocusStates != null)
            {
                groups.Remove(cache.FocusStates);
            }

            if (common != null)
            {
                foreach (WVisualState state in common.States)
                {
                    if (state.Name == "Normal")
                    {
                        cache.Normal = state;
                    }
                    else if (state.Name == "Pressed")
                    {
                        cache.Pressed = state;
                    }
                    else if (state.Name == "PointerOver")
                    {
                        cache.PointerOver = state;
                    }
                }

                if (cache.Normal != null)
                {
                    common.States.Remove(cache.Normal);
                }
                if (cache.Pressed != null)
                {
                    common.States.Remove(cache.Pressed);
                }
                if (cache.PointerOver != null)
                {
                    common.States.Remove(cache.PointerOver);
                }
            }

            return(cache);
        }
Пример #4
0
        void UpdateOnColor()
        {
            if (!(Cell is SwitchCell switchCell))
            {
                return;
            }

            var color = switchCell.OnColor == Color.Default
                                ? _defaultOnColor
                                : new WSolidColorBrush(switchCell.OnColor.ToWindowsColor());

            var nativeSwitch = FrameworkElementExtensions.GetFirstDescendant <ToggleSwitch>(this);

            // change fill color in switch rectangle
            var rects = nativeSwitch.GetDescendantsByName <Microsoft.UI.Xaml.Shapes.Rectangle>("SwitchKnobBounds");

            foreach (var rect in rects)
            {
                rect.Fill = color;
            }

            // change color in animation on PointerOver
            var grid = nativeSwitch.GetFirstDescendant <Microsoft.UI.Xaml.Controls.Grid>();
            var gridVisualStateGroups = Microsoft.UI.Xaml.VisualStateManager.GetVisualStateGroups(grid);

            Microsoft.UI.Xaml.VisualStateGroup vsGroup = null;
            foreach (var visualGroup in gridVisualStateGroups)
            {
                if (visualGroup.Name == "CommonStates")
                {
                    vsGroup = visualGroup;
                    break;
                }
            }
            if (vsGroup == null)
            {
                return;
            }

            Microsoft.UI.Xaml.VisualState vState = null;
            foreach (var visualState in vsGroup.States)
            {
                if (visualState.Name == "PointerOver")
                {
                    vState = visualState;
                    break;
                }
            }
            if (vState == null)
            {
                return;
            }

            var visualStates = vState.Storyboard.Children;

            foreach (ObjectAnimationUsingKeyFrames item in visualStates)
            {
                if ((string)item.GetValue(Storyboard.TargetNameProperty) == "SwitchKnobBounds")
                {
                    item.KeyFrames[0].Value = color;
                    break;
                }
            }
        }
Пример #5
0
        void UpdateOnColor()
        {
            if (!(Cell is SwitchCell switchCell))
            {
                return;
            }

            var color = switchCell.OnColor.IsDefault()
                                ? _defaultOnColor
                                : new WSolidColorBrush(switchCell.OnColor.ToWindowsColor());

            var nativeSwitch = this.GetFirstDescendant <ToggleSwitch>();

            // change fill color in switch rectangle
            var rects = nativeSwitch.GetDescendantsByName <Microsoft.UI.Xaml.Shapes.Rectangle>("SwitchKnobBounds");

            foreach (var rect in rects)
            {
                rect.Fill = color;
            }

            // change color in animation on PointerOver
            var grid = nativeSwitch.GetFirstDescendant <Microsoft.UI.Xaml.Controls.Grid>();
            var gridVisualStateGroups = Microsoft.UI.Xaml.VisualStateManager.GetVisualStateGroups(grid);

            Microsoft.UI.Xaml.VisualStateGroup vsGroup = null;
            foreach (var visualGroup in gridVisualStateGroups)
            {
                if (visualGroup.Name == "CommonStates")
                {
                    vsGroup = visualGroup;
                    break;
                }
            }
            if (vsGroup == null)
            {
                return;
            }

            Microsoft.UI.Xaml.VisualState vState = null;
            foreach (var visualState in vsGroup.States)
            {
                if (visualState.Name == "PointerOver")
                {
                    vState = visualState;
                    break;
                }
            }
            if (vState == null)
            {
                return;
            }

            var visualStates = vState.Storyboard.Children;

            foreach (var state in visualStates)
            {
                // in XF we were setting the MinWidth of the ToggleSwitch to zero which looks to
                // setup the visual states of ToggleSwitch to all be ObjectAnimationUsingKeyFrames.
                // This MinWidth was removed which is why this check was added
                //
                // If you find yourself here trying to figure out a SwitchCell issue
                // Try setting the MinWidth on ToggleSwitch to zero
                if (state is ObjectAnimationUsingKeyFrames item)
                {
                    if ((string)item.GetValue(Storyboard.TargetNameProperty) == "SwitchKnobBounds")
                    {
                        item.KeyFrames[0].Value = color;
                        break;
                    }
                }
            }
        }