|
<buttons:SfSegmentedControl x:Name="segmentedControl"
Margin="10,0"
CornerRadius="15"
SelectedIndex="1"
ItemsSource = "{Binding ImageTextCollection}"
DisplayMode="ImageWithText"
VisibleSegmentsCount="3"
>
<buttons:SfSegmentedControl.FontIconFontFamily>
<OnPlatform Android="Font Awesome 5 Free-Solid-900.otf#Font Awesome 5 Free Solid"
iOS="Font Awesome 5 Free Solid"/>
buttons:SfSegmentedControl.FontIconFontFamily>
buttons:SfSegmentedControl> |
|
<buttons:SfSegmentedControl
BorderColor="Black"
HeightRequest="80"
HorizontalOptions="Center"
x:Name="segmentedControl"
VisibleSegmentsCount="2"
BackgroundColor="Transparent"
ItemsSource="{Binding ViewItems}"
SegmentPadding="5">
</buttons:SfSegmentedControl> |
|
public class ViewModel
{
public ObservableCollection<View> ViewItems { get; set; }
public ViewModel()
{
Label label = new Label()
{
Text = "Text",
FontSize = 20,
VerticalTextAlignment = TextAlignment.Center,
HorizontalTextAlignment = TextAlignment.Center,
TextColor = Color.Black,
};
Icon icon = new Icon();
ViewItems = new ObservableCollection<View>();
ViewItems.Add(label);
ViewItems.Add(icon);
}
} |
|
public class Icon : Frame
{
private readonly SKCanvasView canvasView = new SKCanvasView();
public Icon()
{
Padding = new Thickness(0);
BackgroundColor = Color.Transparent;
HasShadow = false;
Content = canvasView;
canvasView.PaintSurface += CanvasViewOnPaintSurface;
}
private static void RedrawCanvas(BindableObject bindable, object oldvalue, object newvalue)
{
Icon svgIcon = bindable as Icon;
svgIcon?.canvasView.InvalidateSurface();
}
private void CanvasViewOnPaintSurface(object sender, SKPaintSurfaceEventArgs args)
{
SKCanvas canvas = args.Surface.Canvas;
canvas.Clear();
if (string.IsNullOrEmpty("SimpleSample.level2.svg"))
return;
using (Stream stream = GetType().Assembly.GetManifestResourceStream("SimpleSample.level2.svg"))
{
SKSvg svg = new SKSvg();
svg.Load(stream);
SKImageInfo info = args.Info;
canvas.Translate(info.Width / 2f, info.Height / 2f);
SKRect bounds = svg.ViewBox;
float xRatio = info.Width / bounds.Width;
float yRatio = info.Height / bounds.Height;
float ratio = Math.Min(xRatio, yRatio);
canvas.Scale(ratio);
canvas.Translate(-bounds.MidX, -bounds.MidY);
canvas.DrawPicture(svg.Picture);
}
}
} |