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

}

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

相关推荐
damo王16 小时前
云浏览器:让 AI Agent 真正拥有“眼睛“——火山引擎 ArkClaw 新功能体验
人工智能·microsoft·火山引擎·ai agent
波波00716 小时前
告别 JIT?.NET 10 Native AOT 实践指南
.net
独断万古他化17 小时前
Selenium 实战 —— 抽奖系统 UI 自动化测试框架搭建
java·selenium·测试工具·ui·自动化·测试
无风听海17 小时前
.NET10之C# Extension Members深入分析
大数据·c#·.net·extensionmember
唐青枫18 小时前
C#.NET 分布式事务 深入解析:TCC、Saga、Outbox 与落地取舍
c#·.net
jf加菲猫18 小时前
第10章 数据处理
xml·开发语言·数据库·c++·qt·ui
智算菩萨19 小时前
【Tkinter】14 事件处理机制深度解析:从基础绑定到高级传播,构建交互式绘图笔记应用
开发语言·笔记·python·microsoft·ui·ai编程·tkinter
余衫马19 小时前
在 IIS 部署 .NET6 WebApi 应用
运维·c#·iis·.net·发布
无风听海19 小时前
.NET10之C# File-Scoped Namespace 深度解析
c#·.net·.net10
枫叶丹420 小时前
【HarmonyOS 6.0】ArkUI 闪控球功能深度解析:从API到实战
开发语言·microsoft·华为·harmonyos