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); }
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) }); } }
void UpdatePadding(TextBlock textBlock) { textBlock.Padding = WinUIHelpers.CreateThickness( Element.Padding.Left, Element.Padding.Top, Element.Padding.Right, Element.Padding.Bottom); }
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(); } }
void UpdatePadding() { Control.Padding = WinUIHelpers.CreateThickness( Element.Padding.Left, Element.Padding.Top, Element.Padding.Right, Element.Padding.Bottom ); }
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 ); }
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(); } }
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); }
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); } }
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); }
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)); }
void UpdateBorderWidth() { Control.BorderThickness = Element.BorderWidth == (double)Button.BorderWidthProperty.DefaultValue ? WinUIHelpers.CreateThickness(3) : WinUIHelpers.CreateThickness(Element.BorderWidth); }
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); } }
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); }
void UpdatePeekAreaInsets() { ListViewBase.Padding = WinUIHelpers.CreateThickness(CarouselView.PeekAreaInsets.Left, CarouselView.PeekAreaInsets.Top, CarouselView.PeekAreaInsets.Right, CarouselView.PeekAreaInsets.Bottom); UpdateItemsSource(); }