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

}

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

相关推荐
Crazy Struggle4 小时前
.NET 8 微服务框架长什么样?集成 AI 智能体、多租户、自动调度与实时通信
微服务·.net·.net 8.0
天庭鸡腿哥5 小时前
macOS的功能,在Windows上也能实现
windows·microsoft·macos·visual studio·everything
克喵的水银蛇7 小时前
Flutter 通用轮播图组件:BannerSlider 一键实现自动轮播与灵活定制
windows·microsoft
玩泥巴的7 小时前
一分钟实现.NET与飞书长连接的WebSocket架构
c#·.net·二次开发·飞书
mudtools7 小时前
一分钟实现.NET与飞书长连接的WebSocket架构
后端·c#·.net
宝桥南山9 小时前
Azure - 尝试使用一下Kusto Query Language(KQL)
sql·microsoft·微软·database·azure·powerbi
2016bits9 小时前
photoshop将一张图片的水印加到另一张图片上
ui·photoshop
SEO-狼术10 小时前
FastGrid delivers clean Crack
.net
cdming10 小时前
微软发布Win11 26220.7344更新,新增MCP原生支持与统一应用更新
microsoft
心.c10 小时前
《从零开始:打造“核桃苑”新中式风格小程序UI —— 设计思路与代码实现》
开发语言·前端·javascript·ui