Exemplo n.º 1
0
        ListViewBase CreateCarouselListLayout(ItemsLayoutOrientation layoutOrientation)
        {
            Microsoft.UI.Xaml.Controls.ListView listView;

            if (layoutOrientation == ItemsLayoutOrientation.Horizontal)
            {
                listView = new FormsListView()
                {
                    Style      = (Microsoft.UI.Xaml.Style)UWPApp.Current.Resources["HorizontalCarouselListStyle"],
                    ItemsPanel = (ItemsPanelTemplate)UWPApp.Current.Resources["HorizontalListItemsPanel"]
                };

                ScrollViewer.SetHorizontalScrollBarVisibility(listView, WScrollBarVisibility.Auto);
                ScrollViewer.SetVerticalScrollBarVisibility(listView, WScrollBarVisibility.Disabled);
            }
            else
            {
                listView = new FormsListView()
                {
                    Style = (Microsoft.UI.Xaml.Style)UWPApp.Current.Resources["VerticalCarouselListStyle"]
                };

                ScrollViewer.SetHorizontalScrollBarVisibility(listView, WScrollBarVisibility.Disabled);
                ScrollViewer.SetVerticalScrollBarVisibility(listView, WScrollBarVisibility.Auto);
            }

            listView.Padding = WinUIHelpers.CreateThickness(CarouselView.PeekAreaInsets.Left, CarouselView.PeekAreaInsets.Top, CarouselView.PeekAreaInsets.Right, CarouselView.PeekAreaInsets.Bottom);

            return(listView);
        }
Exemplo n.º 2
0
        WShape CreateIndicator(int i, int position)
        {
            var indicatorSize = Element.IndicatorSize;

            if (Element.IndicatorsShape == IndicatorShape.Circle)
            {
                return(new WEllipse()
                {
                    Fill = i == position ? _selectedColor : _fillColor,
                    Height = indicatorSize,
                    Width = indicatorSize,
                    Margin = WinUIHelpers.CreateThickness(DefaultPadding, 0, DefaultPadding, 0)
                });
            }
            else
            {
                return(new WRectangle()
                {
                    Fill = i == position ? _selectedColor : _fillColor,
                    Height = indicatorSize,
                    Width = indicatorSize,
                    Margin = WinUIHelpers.CreateThickness(DefaultPadding, 0, DefaultPadding, 0)
                });
            }
        }
Exemplo n.º 3
0
 void UpdateBorderRadius()
 {
     if (_contentPresenter != null)
     {
         _contentPresenter.CornerRadius = WinUIHelpers.CreateCornerRadius(BorderRadius);
     }
 }
Exemplo n.º 4
0
 void UpdatePadding(TextBlock textBlock)
 {
     textBlock.Padding = WinUIHelpers.CreateThickness(
         Element.Padding.Left,
         Element.Padding.Top,
         Element.Padding.Right,
         Element.Padding.Bottom);
 }
Exemplo n.º 5
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 = 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();
            }
        }
Exemplo n.º 6
0
 void UpdatePadding()
 {
     Control.Padding = WinUIHelpers.CreateThickness(
         Element.Padding.Left,
         Element.Padding.Top,
         Element.Padding.Right,
         Element.Padding.Bottom
         );
 }
Exemplo n.º 7
0
        void UpdateBottomBar()
        {
            _BottomBar.Children.Clear();
            _BottomBar.ColumnDefinitions.Clear();
            var items = ShellItemController?.GetItems();

            if (items?.Count > 1)
            {
                for (int i = 0; i < items.Count; i++)
                {
                    var section = items[i];
                    var btn     = new AppBarButton()
                    {
                        Label    = section.Title,
                        Width    = double.NaN,
                        MinWidth = 68,
                        MaxWidth = 200
                    };

                    switch (section.Icon)
                    {
                    case FileImageSource fileImageSource:
                        btn.Icon = new BitmapIcon()
                        {
                            UriSource = new Uri("ms-appx:///" + fileImageSource.File)
                        };
                        break;

                    case FontImageSource fontImageSource:

                        var icon = new FontIcon()
                        {
                            Glyph      = fontImageSource.Glyph,
                            FontFamily = new FontFamily(fontImageSource.FontFamily),
                            FontSize   = fontImageSource.Size,
                        };

                        if (!fontImageSource.Color.IsDefault)
                        {
                            icon.Foreground = fontImageSource.Color.ToBrush();
                        }

                        btn.Icon = icon;
                        break;
                    }

                    btn.Click += (s, e) => OnShellSectionClicked(section);
                    _BottomBar.ColumnDefinitions.Add(new UwpColumnDefinition()
                    {
                        Width = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Star)
                    });
                    SetColumn(btn, i);
                    _BottomBar.Children.Add(btn);
                }
            }
        }
Exemplo n.º 8
0
        void UpdateCornerRadius()
        {
            float cornerRadius = Element.CornerRadius;

            if (cornerRadius == -1f)
            {
                cornerRadius = 5f;                 // default corner radius
            }
            Control.CornerRadius = WinUIHelpers.CreateCornerRadius(cornerRadius);
        }
Exemplo n.º 9
0
        void UpdatePadding()
        {
            _image.Margin = WinUIHelpers.CreateThickness(0);

            // Apply the padding to the containing button, not the image
            _formsButton.Padding = WinUIHelpers.CreateThickness(
                Element.Padding.Left,
                Element.Padding.Top,
                Element.Padding.Right,
                Element.Padding.Bottom
                );
        }
Exemplo n.º 10
0
 void UpdateBorder()
 {
     if (Element.BorderColor != Color.Default)
     {
         Control.BorderBrush     = Element.BorderColor.ToBrush();
         Control.BorderThickness = WinUIHelpers.CreateThickness(1);
     }
     else
     {
         Control.BorderBrush = new Color(0, 0, 0, 0).ToBrush();
     }
 }
Exemplo n.º 11
0
        static StackPanel CreateContentContainer(Button.ButtonContentLayout layout, WImage image, string text)
        {
            var container = new StackPanel();
            var textBlock = new TextBlock
            {
                Text = text,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            var spacing = layout.Spacing;

            container.HorizontalAlignment = HorizontalAlignment.Center;
            container.VerticalAlignment   = VerticalAlignment.Center;

            switch (layout.Position)
            {
            case Button.ButtonContentLayout.ImagePosition.Top:
                container.Orientation = Orientation.Vertical;
                image.Margin          = WinUIHelpers.CreateThickness(0, 0, 0, spacing);
                container.Children.Add(image);
                container.Children.Add(textBlock);
                break;

            case Button.ButtonContentLayout.ImagePosition.Bottom:
                container.Orientation = Orientation.Vertical;
                image.Margin          = WinUIHelpers.CreateThickness(0, spacing, 0, 0);
                container.Children.Add(textBlock);
                container.Children.Add(image);
                break;

            case Button.ButtonContentLayout.ImagePosition.Right:
                container.Orientation = Orientation.Horizontal;
                image.Margin          = WinUIHelpers.CreateThickness(spacing, 0, 0, 0);
                container.Children.Add(textBlock);
                container.Children.Add(image);
                break;

            default:
                // Defaults to image on the left
                container.Orientation = Orientation.Horizontal;
                image.Margin          = WinUIHelpers.CreateThickness(0, 0, spacing, 0);
                container.Children.Add(image);
                container.Children.Add(textBlock);
                break;
            }

            return(container);
        }
Exemplo n.º 12
0
        void UpdateBorderRadius()
        {
            var radius       = BorderRadius == -1 ? 0 : BorderRadius;
            var cornerRadius = WinUIHelpers.CreateCornerRadius(radius);

            if (_contentPresenter != null)
            {
                _contentPresenter.CornerRadius = cornerRadius;
            }

            if (_rootGrid != null)
            {
                _rootGrid.CornerRadius = cornerRadius;
            }
        }
Exemplo n.º 13
0
        void UpdateItemSpacing()
        {
            UpdateItemsSource();

            var itemSpacing = CarouselItemsLayout.ItemSpacing;

            if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
            {
                _scrollViewer.Padding = WinUIHelpers.CreateThickness(0, 0, itemSpacing, 0);
            }

            if (CarouselItemsLayout.Orientation == ItemsLayoutOrientation.Vertical)
            {
                _scrollViewer.Padding = WinUIHelpers.CreateThickness(0, 0, 0, itemSpacing);
            }
        }
Exemplo n.º 14
0
        internal void UpdateHeaderInsets()
        {
            double inset = 10;

            if (ShellContext.IsPaneToggleButtonVisible)
            {
                inset += 45;
            }

            if (Windows.Foundation.Metadata.ApiInformation.IsPropertyPresent("Microsoft.UI.Xaml.Controls.NavigationView", "IsBackButtonVisible"))
            {
                if (ShellContext.IsBackButtonVisible != Microsoft.UI.Xaml.Controls.NavigationViewBackButtonVisible.Collapsed &&
                    ShellContext.IsBackEnabled)
                {
                    inset += 45;
                }
            }

            _HeaderArea.Padding = WinUIHelpers.CreateThickness(inset, 0, 0, 0);
        }
Exemplo n.º 15
0
 Microsoft.UI.Xaml.Thickness AddMargin(Thickness original, double left, double top, double right, double bottom)
 {
     return(WinUIHelpers.CreateThickness(original.Left + left, original.Top + top, original.Right + right, original.Bottom + bottom));
 }
Exemplo n.º 16
0
 void UpdateBorderWidth()
 {
     Control.BorderThickness = Element.BorderWidth == (double)Button.BorderWidthProperty.DefaultValue ? WinUIHelpers.CreateThickness(3) : WinUIHelpers.CreateThickness(Element.BorderWidth);
 }
Exemplo n.º 17
0
 void UpdatePeekAreaInsets()
 {
     ListViewBase.Padding = WinUIHelpers.CreateThickness(CarouselView.PeekAreaInsets.Left, CarouselView.PeekAreaInsets.Top, CarouselView.PeekAreaInsets.Right, CarouselView.PeekAreaInsets.Bottom);
     UpdateItemsSource();
 }
Exemplo n.º 18
0
        public ShellItemRenderer(ShellRenderer shellContext)
        {
            Xamarin.Forms.Shell.VerifyShellUWPFlagEnabled(nameof(ShellItemRenderer));
            _ = shellContext ?? throw new ArgumentNullException(nameof(shellContext));

            ShellContext = shellContext;
            RowDefinitions.Add(new UwpRowDefinition()
            {
                Height = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Auto)
            });
            RowDefinitions.Add(new UwpRowDefinition()
            {
                Height = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Star)
            });
            RowDefinitions.Add(new UwpRowDefinition()
            {
                Height = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Auto)
            });

            _Title = new TextBlock()
            {
                Style             = Resources["SubtitleTextBlockStyle"] as UwpStyle,
                VerticalAlignment = VerticalAlignment.Center,
                TextTrimming      = TextTrimming.CharacterEllipsis,
                TextWrapping      = TextWrapping.NoWrap
            };
            _HeaderArea = new UwpGrid()
            {
                Height = 40, Padding = WinUIHelpers.CreateThickness(10, 0, 10, 0)
            };
            _HeaderArea.ColumnDefinitions.Add(new UwpColumnDefinition()
            {
                Width = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Star)
            });
            _HeaderArea.ColumnDefinitions.Add(new UwpColumnDefinition()
            {
                Width = WinUIHelpers.CreateGridLength(1, UwpGridUnitType.Auto)
            });
            _HeaderArea.Children.Add(_Title);
            Children.Add(_HeaderArea);

            _Toolbar = new ItemsControl()
            {
                ItemTemplate = UwpApplication.Current.Resources["ShellToolbarItemTemplate"] as UwpDataTemplate,
                ItemsPanel   = UwpApplication.Current.Resources["ShellToolbarItemsPanelTemplate"] as ItemsPanelTemplate,
            };
            SetColumn(_Toolbar, 1);
            _HeaderArea.Children.Add(_Toolbar);

            SectionRenderer = shellContext.CreateShellSectionRenderer();
            SetRow(SectionRenderer, 1);

            Children.Add(SectionRenderer);

            _BottomBar = new UwpGrid()
            {
                HorizontalAlignment = HorizontalAlignment.Center
            };
            _BottomBarArea = new Border()
            {
                Child = _BottomBar
            };
            SetRow(_BottomBarArea, 2);
            Children.Add(_BottomBarArea);
        }
Exemplo n.º 19
0
        protected async override void OnElementChanged(ElementChangedEventArgs <ImageButton> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                if (Control == null)
                {
                    _formsButton                 = new FormsButton();
                    _formsButton.Padding         = WinUIHelpers.CreateThickness(0);
                    _formsButton.BorderThickness = WinUIHelpers.CreateThickness(0);
                    _formsButton.Background      = null;

                    _image = new Microsoft.UI.Xaml.Controls.Image()
                    {
                        VerticalAlignment   = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        Stretch             = WStretch.Uniform,
                    };

                    _image.ImageOpened  += OnImageOpened;
                    _image.ImageFailed  += OnImageFailed;
                    _formsButton.Content = _image;

                    _formsButton.Click += OnButtonClick;
                    _formsButton.AddHandler(PointerPressedEvent, new PointerEventHandler(OnPointerPressed), true);
                    _formsButton.Loaded += ButtonOnLoaded;

                    SetNativeControl(_formsButton);
                }
                else
                {
                    WireUpFormsVsm();
                }

                //TODO: We may want to revisit this strategy later. If a user wants to reset any of these to the default, the UI won't update.
                if (Element.IsSet(VisualElement.BackgroundColorProperty) && Element.BackgroundColor != (Color)VisualElement.BackgroundColorProperty.DefaultValue)
                {
                    UpdateImageButtonBackground();
                }

                if (Element.IsSet(VisualElement.BackgroundProperty) && Element.Background != (Brush)VisualElement.BackgroundProperty.DefaultValue)
                {
                    UpdateImageButtonBackground();
                }

                if (Element.IsSet(ImageButton.BorderColorProperty) && Element.BorderColor != (Color)ImageButton.BorderColorProperty.DefaultValue)
                {
                    UpdateBorderColor();
                }

                if (Element.IsSet(ImageButton.BorderWidthProperty) && Element.BorderWidth != (double)ImageButton.BorderWidthProperty.DefaultValue)
                {
                    UpdateBorderWidth();
                }

                if (Element.IsSet(ImageButton.CornerRadiusProperty) && Element.CornerRadius != (int)ImageButton.CornerRadiusProperty.DefaultValue)
                {
                    UpdateBorderRadius();
                }

                // By default Button loads width padding 8, 4, 8 ,4
                if (Element.IsSet(Button.PaddingProperty))
                {
                    UpdatePadding();
                }

                await TryUpdateSource().ConfigureAwait(false);
            }
        }
Exemplo n.º 20
0
 void SetCornerRadius(CornerRadius cornerRadius)
 {
     Control.CornerRadius = WinUIHelpers.CreateCornerRadius(cornerRadius.TopLeft, cornerRadius.TopRight, cornerRadius.BottomRight, cornerRadius.BottomLeft);
 }