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

}

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

相关推荐
左手厨刀右手茼蒿6 小时前
Flutter for OpenHarmony: Flutter 三方库 image_size_getter 零加载极速获取图片尺寸(鸿蒙 UI 布局优化必备)
android·服务器·flutter·ui·华为·harmonyos
钛态6 小时前
Flutter for OpenHarmony:dio_cookie_manager 让 Dio 发挥会话管理能力,像浏览器一样自动处理 Cookie 深度解析与鸿蒙适配指南
android·linux·运维·flutter·ui·华为·harmonyos
山岚的运维笔记8 小时前
SQL Server笔记 -- 第85章:查询提示
数据库·笔记·sql·microsoft·sqlserver
用户2986985301410 小时前
C#中如何创建目录(TOC):使用Spire.Doc for .NET实现Word TOC自动化
后端·c#·.net
我命由我1234511 小时前
Photoshop - Ps还原和历史记录
学习·ui·职场和发展·求职招聘·职场发展·学习方法·photoshop
我命由我1234511 小时前
Photoshop - Ps工作界面
学习·ui·职场和发展·求职招聘·职场发展·学习方法·photoshop
a11177612 小时前
卡通风格 UI 组件库html (TRIZ UI Kit [特殊字符])
前端·ui·html
fs哆哆16 小时前
在VB.NET中,随机打乱列表顺序的算法与方法
算法·.net
天一生水water17 小时前
MCP入门教程
人工智能·microsoft
菜鸟小芯19 小时前
【GLM-5 陪练式创意 UI 实战】第一篇:创意魔法盒 —— 用 AI 生成 “开心” 主题 Flutter UI,搞定深浅色与响应式
人工智能·flutter·ui