Avalonia 项目结构说明

1、接下来我将使用VSCode,项目结构如下图。

1.1、Assets:包含编译到程序中的任何嵌入式资源。例如:图片、图标、字体等,UI可能需要显示的任何内容。

1.2、Models:新建的一个空文件夹,用于存放 MVVM 模式中的"模型"部分的代码。通常包含应用程序需要的除 UI 之外的所有内容。例如:与数据库的交互、Web API 或与硬件设备的接口。

1.3、View Models:这是项目中所有视图模型的文件夹,它已经包含了一个示例。视图模型在 MVVM 模式中包含应用程序逻辑。例如:只有在用户输入了内容时按钮才可用;或者在用户点击这里时打开对话框;或者在用户输入了太大的数字时显示错误类型的逻辑。

1.4、Views:这是项目中所有视图的文件夹,它已经包含了应用程序主窗口的视图。在 MVVM 模式中,视图仅包含应用程序的展示部分,即布局和表单、字体、颜色、图标和图片。在 MVVM 中,它们只有足够的代码将它们链接到视图模型层。在 Avalonia UI 中,这里只有足够管理窗口和对话框的代码。

1.5、App.axaml:文件用于应用于整个应用程序的 XAML 样式和数据模板。

1.6、Program.cs:文件是应用程序的执行入口点。可以在此配置 Avalonia UI 的其他平台选项(如果需要的话)。

1.7、ViewLocator.cs:文件是一个特殊的辅助类,它在 App.axaml 文件中使用。

2、修改窗口的样式。

找到Demo文件夹下的App.axaml文件,将Application中的RequestedThemeVariant修改为"Dark"。

App.axaml代码如下:

XML 复制代码
<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="using:Demo"
             x:Class="Demo.App"
             RequestedThemeVariant="Dark">
             <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

    <Application.DataTemplates>
        <local:ViewLocator/>
    </Application.DataTemplates>

    <Application.Styles>
        <FluentTheme />
    </Application.Styles>
</Application>

运行效果如下图。

App.axaml代码修改如下:

XML 复制代码
<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="using:Demo"
             x:Class="Demo.App"
             RequestedThemeVariant="Light">
             <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

    <Application.DataTemplates>
        <local:ViewLocator/>
    </Application.DataTemplates>

    <Application.Styles>
        <FluentTheme />
    </Application.Styles>
</Application>

运行效果如下:

3、修改MainWindow.axaml窗体为亚克力样式的窗体,如下图。

MainWindow.axaml代码如下。

XML 复制代码
<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:Demo.ViewModels"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:views="clr-namespace:Demo.Views"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="Demo.Views.MainWindow"
        Icon="/Assets/avalonia-logo.ico"
        Title="Demo"
        TransparencyLevelHint="AcrylicBlur"
        Background="Transparent"
        ExtendClientAreaToDecorationsHint="True">
        <views:MainView />
</Window>

其中

XML 复制代码
        TransparencyLevelHint="AcrylicBlur"
        Background="Transparent"
        ExtendClientAreaToDecorationsHint="True"

这段代码是主要设置代码,这些API到哪里查找呢?可以在下面的地址中查找响应API

Avalonia UI​​​​​​​

相关推荐
唐青枫3 小时前
C#.NET 定时任务与队列利器:Hangfire 完整教程
c#·.net
hez20109 小时前
Runtime Async - 步入高性能异步时代
c#·.net·.net core·clr
mudtools1 天前
.NET驾驭Word之力:玩转文本与格式
c#·.net
唐青枫1 天前
C#.NET 数据库开发提速秘籍:SqlSugar 实战详解
c#·.net
mudtools2 天前
.NET驾驭Word之力:理解Word对象模型核心 (Application, Document, Range)
c#·.net
大飞pkz2 天前
【设计模式】C#反射实现抽象工厂模式
设计模式·c#·抽象工厂模式·c#反射·c#反射实现抽象工厂模式
唐青枫2 天前
从入门到进阶:C#.NET Stopwatch 计时与性能测量全攻略
c#·.net
未来之窗软件服务2 天前
幽冥大陆(二)RDIFSDK 接口文档:布草洗涤厂高效运营的技术桥梁C#—东方仙盟
开发语言·c#·rdif·仙盟创梦ide·东方仙盟
1uther2 天前
Unity核心概念⑨:Screen
开发语言·游戏·unity·c#·游戏引擎
阿幸软件杂货间3 天前
Office转PDF转换器v1.0.py
开发语言·pdf·c#