public Badge(double width, double height, bool autoWidth) { HeightRequest = height; WidthRequest = width; box = new RoundedBoxView(); box.CornerRadius = HeightRequest / 2; box.StrokeThickness = 2d; box.SetBinding(RoundedBoxView.StrokeProperty, new Binding("StrokeColor", source: this)); box.SetBinding(VisualElement.BackgroundColorProperty, new Binding("BoxColor", source: this)); Children.Add(box); label = new MvvmAspire.Controls.Label(); label.SetBinding(Xamarin.Forms.Label.TextProperty, new Binding("Text", source: this)); label.SetBinding(Xamarin.Forms.Label.FontSizeProperty, new Binding("TextSize", source: this)); label.HorizontalTextAlignment = Xamarin.Forms.TextAlignment.Center; label.VerticalTextAlignment = Xamarin.Forms.TextAlignment.Center; label.FontAttributes = FontAttributes.Bold; label.HorizontalOptions = LayoutOptions.Center; Children.Add(label); if (autoWidth) { // Auto-width SetBinding(VisualElement.WidthRequestProperty, new Binding("Text", BindingMode.OneWay, new BadgeWidthConverter(WidthRequest), source: this)); } // Hide if no value SetBinding(VisualElement.IsVisibleProperty, new Binding("Text", BindingMode.OneWay, new BadgeVisibleValueConverter(), source: this)); }
void SetCornerRadius(RoundedBoxView element) { if (Frame.Width > 0) { this.SetCornerRadius((nfloat)element.CornerRadius, UIRectCorner.AllCorners); ClipsToBounds = true; } }