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

}

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

相关推荐
月明长歌31 分钟前
个人测试项目:一个可跑、可扩、可复用的 Selenium UI 自动化博客系统全链路测试拆解
selenium·ui·自动化
缺点内向41 分钟前
在 C# 中为 Word 段落添加制表位:使用 Spire.Doc for .NET 实现高效排版
开发语言·c#·自动化·word·.net
晚霞的不甘2 小时前
Flutter for OpenHarmony《智慧字典》中的沉浸式学习:成语测试与填空练习等功能详解
学习·flutter·ui·信息可视化·前端框架·鸿蒙
Eiceblue3 小时前
通过 C# 解析 HTML:文本提取 + 结构化数据获取
c#·html·.net·visual studio
一叶星殇3 小时前
.NET 6 NLog 实现多日志文件按业务模块拆分的实践
开发语言·.net
l1t3 小时前
在Windows的WSL中试用GizmoSQL UI连接GizmoSQL数据库服务器
数据库·windows·ui
时光追逐者4 小时前
一款基于 .NET Avalonia 开源免费、快速、跨平台的图片查看器
c#·.net·图片查看器
CamilleZJ4 小时前
多端ui方案
前端·ui
满栀5854 小时前
企业后台管理系统菜单模块重构
microsoft·重构
Yeats_Liao4 小时前
星图平台快速搭建 Clawdbot:私有化本地 Qwen3-VL:30B 并接入飞书平台(上篇)
人工智能·microsoft·飞书