Exemplo n.º 1
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _moreButton          = GetTemplateChild("MoreButton") as Microsoft.UI.Xaml.Controls.Button;
            _primaryItemsControl = GetTemplateChild("PrimaryItemsControl") as Microsoft.UI.Xaml.Controls.ItemsControl;
        }
Exemplo n.º 2
0
 public static void UpdateLineBreakMode(this Microsoft.UI.Xaml.Controls.Button platformButton, Button button)
 {
     if (platformButton.GetContent <TextBlock>() is TextBlock textBlock)
     {
         textBlock?.UpdateLineBreakMode(button.LineBreakMode);
     }
 }
Exemplo n.º 3
0
        void AddNativeBindings(NativeBindingGalleryPage page)
        {
            if (page.NativeControlsAdded)
            {
                return;
            }

            StackLayout sl = page.Layout;

            var txbLabel = new TextBlock
            {
                FontSize   = 14,
                FontFamily = new FontFamily("HelveticaNeue")
            };

            var txbBox = new TextBox
            {
                FontSize   = 14,
                FontFamily = new FontFamily("HelveticaNeue")
            };

            var btnColor = new Microsoft.UI.Xaml.Controls.Button {
                Content = "Toggle Label Color", Height = 80
            };

            btnColor.Click += (sender, args) => txbLabel.Foreground = SolidColorBrush.Pink.ToBrush();

            var btnTextBox = new Microsoft.UI.Xaml.Controls.Button {
                Content = "Change text textbox", Height = 80
            };

            btnTextBox.Click += (sender, args) => txbBox.Text = "Hello 2 way native";

            txbLabel.SetBinding("Text", new Binding("NativeLabel"));
            txbBox.SetBinding("Text", new Binding("NativeLabel", BindingMode.TwoWay), "TextChanged");
            txbLabel.SetBinding("Foreground", new Binding("NativeLabelColor", BindingMode.TwoWay, new ColorToBrushNativeBindingConverter()));

            var grd = new StackPanel();

            grd.Children.Add(txbLabel);
            grd.Children.Add(btnColor);

            sl?.Children.Add(grd.ToView());

            sl?.Children.Add(txbBox);
            sl?.Children.Add(btnTextBox.ToView());

            page.NativeControlsAdded = true;
        }
Exemplo n.º 4
0
        void UpdateButtonBackground(Brush value)
        {
            var 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;
            }
        }
Exemplo n.º 5
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _plus = GetTemplateChild("Plus") as Microsoft.UI.Xaml.Controls.Button;
            if (_plus != null)
            {
                _plus.Click += OnPlusClicked;
            }

            _minus = GetTemplateChild("Minus") as Microsoft.UI.Xaml.Controls.Button;
            if (_minus != null)
            {
                _minus.Click += OnMinusClicked;
            }

            UpdateEnabled(Value);
            UpdateButtonBackgroundColor(ButtonBackgroundColor);
        }
Exemplo n.º 6
0
        void UpdateButtonBackgroundColor(Color value)
        {
            if (value == null)
            {
                return;
            }

            WBrush brush = value.ToPlatform();

            _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;
            }
        }
Exemplo n.º 7
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;
            }
        }
Exemplo n.º 8
0
        void AddNativeControls(NestedNativeControlGalleryPage page)
        {
            if (page.NativeControlsAdded)
            {
                return;
            }

            StackLayout sl = page.Layout;

            // Create and add a native TextBlock
            var originalText = "I am a native TextBlock";
            var textBlock    = new TextBlock
            {
                Text       = originalText,
                FontSize   = 14,
                FontFamily = new FontFamily("HelveticaNeue")
            };

            sl?.Children.Add(textBlock);

            // Create and add a native Button
            var button = new Microsoft.UI.Xaml.Controls.Button {
                Content = "Toggle Font Size", Height = 80
            };

            button.Click += (sender, args) => { textBlock.FontSize = textBlock.FontSize == 14 ? 24 : 14; };

            sl?.Children.Add(button.ToView());

            // Create a control which we know doesn't behave correctly with regard to measurement
            var difficultControl = new BrokenNativeControl
            {
                Text = "Not Sized/Arranged Properly"
            };

            var difficultControl2 = new BrokenNativeControl
            {
                Text = "Fixed"
            };

            // Add the misbehaving controls, one with a custom delegate for ArrangeOverrideDelegate
            sl?.Children.Add(difficultControl);
            sl?.Children.Add(difficultControl2,
                             arrangeOverrideDelegate: (renderer, finalSize) =>
            {
                if (finalSize.Width <= 0 || double.IsInfinity(finalSize.Width))
                {
                    return(null);
                }

                FrameworkElement frameworkElement = renderer.Control;

                frameworkElement.Measure(finalSize);

                // The broken control always tries to size itself to the screen width
                // So figure that out and we'll know how far off it's laying itself out
                var bounds         = ApplicationView.GetForCurrentView().VisibleBounds;
                double scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
                var screenWidth    = new Size(bounds.Width * scaleFactor, bounds.Height * scaleFactor);

                // We can re-center it by offsetting it during the Arrange call
                double diff = Math.Abs(screenWidth.Width - finalSize.Width) / -2;
                frameworkElement.Arrange(new Windows.Foundation.Rect(diff, 0, finalSize.Width - diff, finalSize.Height));

                // Arranging the control to the left will make it show up past the edge of the stack layout
                // We can fix that by clipping it manually
                var clip = new RectangleGeometry {
                    Rect = new Windows.Foundation.Rect(-diff, 0, finalSize.Width, finalSize.Height)
                };
                frameworkElement.Clip = clip;

                return(finalSize);
            }
                             );

            page.NativeControlsAdded = true;
        }