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

}

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

相关推荐
sg_knight14 小时前
设计模式实战:状态模式(State)
python·ui·设计模式·状态模式·state
黄思搏15 小时前
基于标注平台数据的 Unity UI 自动化构建工作流设计与工程实践
ui·unity·蓝湖·vectoui
小樱花的樱花16 小时前
1 项目概述
开发语言·c++·qt·ui
2301_8227032017 小时前
开源鸿蒙跨平台Flutter开发:跨端图形渲染引擎的类型边界与命名空间陷阱:以多维雷达图绘制中的 dart:ui 及 StrokeJoin 异常为例
算法·flutter·ui·开源·图形渲染·harmonyos·鸿蒙
彧翎Pro17 小时前
ASP.NET Core 外部依赖调用治理实战:HttpClientFactory、Polly 与幂等边界
microsoft·asp.net·php
唐青枫17 小时前
C#.NET Monitor 与 Mutex 深入解析:进程内同步、跨进程互斥与使用边界
c#·.net
会写代码的建筑师19 小时前
.NET 控制台后台程序实践细节总结
后端·.net
极梦网络无忧19 小时前
Windows UI Automation实现抖音直播间监控(桌面端场控助手核心方案)
windows·ui
newbe3652419 小时前
Design.md:让 AI 一致性进行前端 UI 设计的解决方案
前端·人工智能·ui
火山引擎开发者社区19 小时前
从监控盲区到业务洞察:深入解读 APMPlus 生产指标
大数据·人工智能·microsoft