最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MAUI使用Maui.Graphics.Controls繪制控件詳解

 更新時(shí)間:2022年02月15日 13:36:12   作者:痕跡g  
本文詳細(xì)講解了MAUI使用Maui.Graphics.Controls繪制控件的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

簡(jiǎn)介

Microsoft.Maui.Graphics是一個(gè)完全采用C#的iOS,Android,Windows,macOS,Tizen和Linux的跨平臺(tái)圖形庫(kù)。

對(duì)于MAUI項(xiàng)目當(dāng)中繪制的方案是使用不同平臺(tái)的控件來(lái)而非自繪。 當(dāng)然MAUI當(dāng)中也使用了Microsoft.Maui.Graphics,

MAUI Preview9更新中, 引入了新的API能夠輕松的將邊框、陰影、形狀添加到其中。

Microsoft.Maui.Graphics.Controls

Microsoft.Maui.Graphics.Controls是一個(gè).NET MAUI 實(shí)驗(yàn)性項(xiàng)目,該項(xiàng)目通過(guò)Microsoft.Maui.Graphics庫(kù)來(lái)繪制控件, 具有多種內(nèi)置主題,這意味著, 您可以在你現(xiàn)有的MAUI項(xiàng)目當(dāng)中使用它。

接下來(lái), 主要講解如何使用Microsoft.Maui.Graphics.Controls 以及如何擴(kuò)展自行繪制控件。

使用Microsoft.Maui.Graphics.Controls

首先, 創(chuàng)建一個(gè)MAUI項(xiàng)目, 添加新的Nuget包源并且安裝它。

確保Nuget包源的依賴(lài)版本與當(dāng)前MAUI項(xiàng)目版本移植6.0.101-preview.10.2068

打開(kāi)MauiProgram文件, 添加 ConfigureGraphicsControls

 public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                }).ConfigureGraphicsControls();

            return builder.Build();
        }

啟動(dòng)后,效果如下所示:

說(shuō)明: 可以通過(guò)ConfigureGraphicsControls(Microsoft.Maui.Graphics.Controls.DrawableType.Fluent)參數(shù)配置控件的風(fēng)格, 提供了: Cupertino, Fluent ,Material 三種選項(xiàng)。

繪制控件

如果你想要完全實(shí)現(xiàn)自定義控件或者修改控件的某些方面, 你都可以使用它來(lái)做到這一點(diǎn), 下來(lái)演示如何使用該庫(kù)來(lái)繪制自定義的圓形控件。

1.創(chuàng)建Circle類(lèi), 繼承于GraphicsView, 并且重寫(xiě)Draw方法,繪制指定寬度顏色的圓形。

 public class Circle : Microsoft.Maui.Graphics.Controls.GraphicsView
    {
        public static readonly BindableProperty ForegroundProperty =
            BindableProperty.Create(nameof(Foreground), typeof(Color),
                typeof(Circle), null);

        public Color Foreground
        {
            get => (Color)GetValue(ForegroundProperty);
            set => SetValue(ForegroundProperty, value);
        }

        public static readonly BindableProperty SizeProperty =
            BindableProperty.Create(nameof(Size), typeof(float),
                typeof(Circle), null);

        public float Size
        {
            get { return (float)GetValue(SizeProperty); }
            set { SetValue(SizeProperty, value); }
        }
         
        public override void Draw(ICanvas canvas, RectangleF dirtyRect)
        {
            base.Draw(canvas, dirtyRect);

            canvas.SaveState();

            canvas.FillColor = Foreground;

            var x = dirtyRect.X;
            var y = dirtyRect.Y;

            canvas.FillEllipse(x, y, Size, Size);

            canvas.RestoreState();
        } 
    }

2.XAML中聲明控件,設(shè)置指定大小及顏色

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MAUIRender.MainPage"
             xmlns:my="clr-namespace:MAUIRender" 
             xmlns:ctor="clr-namespace:MAUIRender.Controls" 
             BackgroundColor="{DynamicResource SecondaryColor}">
    <Grid>
        <StackLayout>
            <ctor:Circle Size="50" Foreground="Blue"/>
        </StackLayout>
    </Grid>
</ContentPage>

3.啟動(dòng)項(xiàng)目,查看控件對(duì)應(yīng)效果:

總結(jié)

本篇文章主要介紹如何在MAUI項(xiàng)目中使用Microsoft.Maui.Graphics.Controls, 以及通過(guò)它實(shí)現(xiàn)自定義控件的擴(kuò)展功能。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

高淳县| 保康县| 万全县| 四平市| 伊宁市| 淮阳县| 尖扎县| 长岛县| 福贡县| 河西区| 新沂市| 西贡区| 阿坝| 济南市| 万源市| 泽普县| 边坝县| 武山县| 尚义县| 黔西县| 抚宁县| 汕头市| 南城县| 绥中县| 民和| 阳西县| 临猗县| 柯坪县| 宁波市| 天津市| 平邑县| 孟连| 峡江县| 秦皇岛市| 昌黎县| 兴宁市| 新源县| 通化市| 平阳县| 高陵县| 文成县|