.net 8 发布了,试下微软最近强推的MAUI

先看下实现的效果:

下面发下XAML文件:

复制代码
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp2.MainPage">

    <ScrollView>
        <VerticalStackLayout
            Padding="30,0"
            Spacing="25">
            <Label x:Name="txt_label" Text="Value :0 "></Label>
            <Slider x:Name="slider_1" Minimum="0" Maximum="1"  ValueChanged="Slider_ValueChanged" />
            <Image
                Source="dotnet_bot.png"
                HeightRequest="185"
                Aspect="AspectFit"
                SemanticProperties.Description="dot net bot in a race car number eight" />

            <Label
                Text="Hello, World!"
                Style="{StaticResource Headline}"
                SemanticProperties.HeadingLevel="Level1" />

            <Label
                Text="Welcome to &#10;.NET Multi-platform App UI"
                Style="{StaticResource SubHeadline}"
                SemanticProperties.HeadingLevel="Level2"
                SemanticProperties.Description="Welcome to dot net Multi platform App U I" />

            <Button
                x:Name="CounterBtn"
                Text="Click me" 
                SemanticProperties.Hint="Counts the number of times you click"
                Clicked="OnCounterClicked"
                HorizontalOptions="Fill" />
        </VerticalStackLayout>
    </ScrollView>

</ContentPage>

.cs文件:

复制代码
namespace MauiApp2
{
    public partial class MainPage : ContentPage
    {
        int count = 0;

        public MainPage()
        {
            InitializeComponent();
        }

        private void OnCounterClicked(object sender, EventArgs e)
        {
            count++;

            if (count == 1)
                CounterBtn.Text = $"Clicked {count} time";
            else
                CounterBtn.Text = $"Clicked {count} times";

            SemanticScreenReader.Announce(CounterBtn.Text);
        }

        private void Slider_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            this.txt_label.Text = this.slider_1.Value.ToString();
        }
    }

}

下一个示例实现调用手机的蓝牙或者一些设备。

相关推荐
鼎道开发者联盟2 小时前
构建活的界面:AIGUI底板的动态布局
人工智能·ui·ai·aigc·gui
余栀丶2 小时前
Microsoft Edge 禁止更新
microsoft·edge
Lan.W2 小时前
element UI + vue2 + html实现堆叠条形图 - 横向分段器
前端·ui·html
shizhenshide4 小时前
隐形杀手:无感验证(Invisible CAPTCHA)的工作原理与存在性检测方法
microsoft·验证码·ezcaptcha
幌才_loong5 小时前
.NET 8 中 EF Core 的 DbContext 配置全解析
后端·.net
尤老师FPGA7 小时前
使用ZYNQ芯片和LVGL框架实现用户高刷新UI设计系列教程(第四十二讲)
android·java·ui
阿蔹7 小时前
UI测试自动化--Web--Python_Selenium-元素定位
前端·ui·自动化
IT古董7 小时前
【前端】Headless UI 深度实战:构建可访问、可定制的现代前端组件
前端·ui
XXYBMOOO8 小时前
全面解析 Qt `QMessageBox` 类及其常用方法
开发语言·qt·microsoft
hpz12239 小时前
对Element UI 组件的二次封装
javascript·vue.js·ui