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​​​​​​​

相关推荐
aini_lovee28 分钟前
C#与倍福PLC(通过ADS协议)通信上位机源程序实现
开发语言·c#
2501_930707781 小时前
使用C#代码压平 PDF 表单字段
数据库·pdf·c#
IT知识分享4 小时前
数字上标、下标如何打,6种常用方法详解
开发语言·c#·xhtml
码农学院5 小时前
itextsharp .net中如何设置两个表格的间距设为0,取网站的域名,协议、端口、当前站点目录的地址
开发语言·c#·.net
monkeyhlj6 小时前
Agent Skills简单理解
开发语言·c#
星河耀银海7 小时前
Unity C#入门:变量的定义与访问权限(public/private)
unity·c#·lucene
asdzx677 小时前
使用 C# 添加或读取 Excel 公式:完整指南
开发语言·c#·excel
加号37 小时前
【C#】 中 BCD 字节数组转十进制字符串的原理与实现思路
开发语言·c#
周杰伦fans7 小时前
C# 从 List 中移除另一个集合
windows·c#
大空大地20267 小时前
C#进阶语法**总结
c#