Ejemplo n.º 1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Slider> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                if (Control == null)
                {
                    var slider = new FormsSlider();
                    SetNativeControl(slider);

                    slider.Ready += (sender, args) =>
                    {
                        UpdateThumbColor();
                        UpdateThumbImage();
                    };

                    Control.Minimum = e.NewElement.Minimum;
                    Control.Maximum = e.NewElement.Maximum;
                    Control.Value   = e.NewElement.Value;
                    Control.IsThumbToolTipEnabled = false;

                    slider.ValueChanged += OnNativeValueChanged;

                    defaultforegroundcolor = slider.Foreground;
                    defaultbackgroundcolor = slider.Background;

                    // Even when using Center/CenterAndExpand, a Slider has an oddity where it looks
                    // off-center in its layout by a smidge. The default templates are slightly different
                    // between 8.1/UWP; the 8.1 rows are 17/Auto/32 and UWP are 18/Auto/18. The value of
                    // the hardcoded 8.1 rows adds up to 49 (when halved is 24.5) and UWP are 36 (18). Using
                    // a difference of about 6 pixels to correct this oddity seems to make them both center
                    // more correctly.
                    //
                    // The VerticalAlignment needs to be set as well since a control would not actually be
                    // centered if a larger HeightRequest is set.
                    if (Element.VerticalOptions.Alignment == LayoutAlignment.Center && Control.Orientation == Microsoft.UI.Xaml.Controls.Orientation.Horizontal)
                    {
                        Control.VerticalAlignment = Microsoft.UI.Xaml.VerticalAlignment.Center;

                        slider.Margin = WinUIHelpers.CreateThickness(0, 7, 0, 0);
                    }

                    _pointerPressedHandler  = new PointerEventHandler(OnPointerPressed);
                    _pointerReleasedHandler = new PointerEventHandler(OnPointerReleased);

                    Control.AddHandler(PointerPressedEvent, _pointerPressedHandler, true);
                    Control.AddHandler(PointerReleasedEvent, _pointerReleasedHandler, true);
                    Control.AddHandler(PointerCanceledEvent, _pointerReleasedHandler, true);
                }

                double stepping = Math.Min((e.NewElement.Maximum - e.NewElement.Minimum) / 1000, 1);
                Control.StepFrequency = stepping;
                Control.SmallChange   = stepping;
                UpdateFlowDirection();
                UpdateSliderColors();
            }
        }
Ejemplo n.º 2
0
        public static void SetForeground(this FrameworkElement element, WBrush foregroundBrush)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            element.SetValue(GetForegroundProperty(element), foregroundBrush);
        }
Ejemplo n.º 3
0
        void ControlOnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            WireUpFormsVsm();

            // The defaults from the control template won't be available
            // right away; we have to wait until after the template has been applied
            _defaultBrush      = Control.Foreground;
            _defaultFontFamily = Control.FontFamily;
            UpdateFont();
            UpdateTextColor();
        }
Ejemplo n.º 4
0
 void SetDefaultSwitchColor()
 {
     if (_defaultOnColor == null && Cell is SwitchCell)
     {
         var nativeSwitch = FrameworkElementExtensions.GetFirstDescendant <ToggleSwitch>(this);
         var rects        = nativeSwitch.GetDescendantsByName <Microsoft.UI.Xaml.Shapes.Rectangle>("SwitchKnobBounds");
         foreach (var rect in rects)
         {
             _defaultOnColor = rect.Fill;
         }
         UpdateOnColor();
     }
 }
Ejemplo n.º 5
0
        void UpdateButtonBackgroundColor(Color value)
        {
            WBrush brush = value.ToBrush();

            _minus = GetTemplateChild("Minus") as Microsoft.UI.Xaml.Controls.Button;
            _plus  = GetTemplateChild("Plus") as Microsoft.UI.Xaml.Controls.Button;
            if (_minus != null)
            {
                _minus.Background = brush;
            }
            if (_plus != null)
            {
                _plus.Background = brush;
            }
        }
Ejemplo n.º 6
0
        void UpdateButtonBackgroundColor(Color value)
        {
            if (value == null)
            {
                return;
            }

            WBrush brush = Maui.ColorExtensions.ToNative(value);

            _minus = GetTemplateChild("Minus") as Microsoft.UI.Xaml.Controls.Button;
            _plus  = GetTemplateChild("Plus") as Microsoft.UI.Xaml.Controls.Button;
            if (_minus != null)
            {
                _minus.Background = brush;
            }
            if (_plus != null)
            {
                _plus.Background = brush;
            }
        }