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

}

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

相关推荐
Leinwin7 小时前
微软发布新一代存储优化型虚拟机:Azure Laosv4、Lasv4 和 Lsv4 系列
microsoft·azure
共享ui设计和前端开发人才10 小时前
UI前端大数据处理安全性保障:数据加密与隐私保护策略
ui
ui设计前端开发老司机10 小时前
UI前端大数据处理性能瓶颈突破:分布式计算框架的应用
ui
前端开发与ui设计的老司机10 小时前
UI前端与数字孪生结合实践探索:智慧物流的货物追踪与配送优化
前端·ui
蹦蹦跳跳真可爱58913 小时前
Python----大模型(使用api接口调用大模型)
人工智能·python·microsoft·语言模型
Triv202513 小时前
ECU开发工具链1.10版:更强大的测量、校准与数据分析体验.
microsoft·数据分析·汽车电子开发·校准流程自动化·高速信号采集·测试台架集成·实时数据监控
UI设计和前端开发从业者14 小时前
从UI设计到数字孪生实战应用:构建智慧金融的智能风控平台
ui·金融
爱奥尼欧15 小时前
【Linux 系统】基础IO——Linux中对文件的理解
linux·服务器·microsoft
不惑_19 小时前
动感阴影生成器,一键生成立体效果,提升设计质感
microsoft