.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();
        }
    }

}

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

相关推荐
测试人社区—66791 小时前
当代码面临道德选择:VR如何为AI伦理决策注入“人性压力”
网络·人工智能·python·microsoft·vr·azure
鄃鳕2 小时前
耗时IO对象移到子线程,防止UI卡顿
ui
卤炖阑尾炎2 小时前
Web 技术基础与 Nginx 网站环境部署全解析
前端·nginx·microsoft
少云清3 小时前
【UI自动化测试】4_TPshop项目实战 _后台管理-新增商品成功
ui
宝桥南山4 小时前
GitHub Copilot - 尝试一下Plan mode
microsoft·微软·github·aigc·copilot·ai编程
步步为营DotNet5 小时前
深入理解ASP.NET Core Middleware:构建高效Web应用的关键组件
中间件·asp.net·.net
我是唐青枫5 小时前
C#.NET SignalR 深入解析:实时通信、Hub 与连接管理实战
开发语言·c#·.net
IT 行者5 小时前
每天了解几个MCP SERVER:21st.dev Magic
人工智能·ui·mcp
波波0075 小时前
每日一题:什么是.NET中的线程池?
面试·.net
FreeBuf_6 小时前
M365Pwned - 基于 Graph API 的微软 365 红队图形化攻击工具包发布
microsoft