Exemple #1
0
 void SetDafaultColor()
 {
     if (_defaultOnColor == null && Cell is SwitchCell)
     {
         var nativeSwitch = FrameworkElementExtensions.GetFirstDescendant <ToggleSwitch>(this);
         var rects        = nativeSwitch.GetDescendantsByName <Windows.UI.Xaml.Shapes.Rectangle>("SwitchKnobBounds");
         foreach (var rect in rects)
         {
             _defaultOnColor = rect.Fill;
         }
         UpdateOnColor();
     }
 }
Exemple #2
0
        protected void UpdateTabStop()
        {
            if (_control == null)
            {
                return;
            }
            _control.IsTabStop = Element.IsTabStop;

            // update TabStop of children for complex controls (like as DatePicker, TimePicker, SearchBar and Stepper)
            var children = FrameworkElementExtensions.GetChildren <Control>(_control);

            foreach (var child in children)
            {
                child.IsTabStop = _control.IsTabStop;
            }
        }
Exemple #3
0
        void UpdateOnColor()
        {
            if (!(Cell is SwitchCell switchCell))
            {
                return;
            }

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

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

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

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

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

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

            Windows.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;
                }
            }
        }