• WPF向Avalonia迁移(三、项目结构)


    前提:

    Avalonia版本11.0.0

    1.配置文件

    1.1 添加配置文件

    1.2 读取配置文件 

    添加System.Configuration.ConfigurationManager

    1. using Avalonia.Controls;
    2. using System.Configuration;
    3. namespace AvaloniaApplication7.Views
    4. {
    5. public partial class MainWindow : Window
    6. {
    7. public MainWindow()
    8. {
    9. InitializeComponent();
    10. // 读取配置项
    11. var DBOption = ConfigurationManager.AppSettings["DBOption"];
    12. }
    13. }
    14. }

    2.样式

    2.1 添加样式文件至Assets文件夹下

    1. <Styles xmlns="https://github.com/avaloniaui"
    2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    3. <Design.PreviewWith>
    4. </Design.PreviewWith>
    5. <Style Selector="TextBlock">
    6. <Setter Property="Foreground" Value="White" />
    7. <Setter Property="FontSize" Value="16" />
    8. <Setter Property="FontWeight" Value="Normal"/>
    9. </Style>
    10. </Styles>
     2.2 引用样式

           打开App.axaml文件,添加,添加后该样式在整个应用生效。

    1. <Application.Styles>
    2. <FluentTheme />
    3. <StyleInclude Source="/Assets/Styles/CommonStyles.axaml"/>
    4. </Application.Styles>

    3.资源文件

    3.1 添加资源文件

    1. <ResourceDictionary xmlns="https://github.com/avaloniaui"
    2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    3. <SolidColorBrush x:Key="WindowDefaultBackground">#336699</SolidColorBrush>
    4. <!--Disabled颜色-->
    5. <Color x:Key="DisabledColor">#545454</Color>
    6. <Brush x:Key="EditWordColor">#FFFFFA</Brush>
    7. <Brush x:Key="ComboBoxBackground">#003366</Brush>
    8. <Brush x:Key="ComboBoxPopupBackground">#003366</Brush>
    9. <SolidColorBrush x:Key="GridColor1">#003e62</SolidColorBrush>
    10. <!--表头背景色-->
    11. <SolidColorBrush x:Key="ColumnHeaderBackground">#666699</SolidColorBrush>
    12. <!--行背景色-->
    13. <SolidColorBrush x:Key="RowBackground">#111B59</SolidColorBrush>
    14. <!--Grid背景色-->
    15. <Brush x:Key="GridBackground">#06173E</Brush>
    16. <!--Grid背景色-->
    17. <Brush x:Key="GridBackground1">#111B59</Brush>
    18. <SolidColorBrush x:Key="SystemControlBackgroundAltHighBrush">#1f497d</SolidColorBrush>
    19. <!--Memu的下级Popup背景色-->
    20. <SolidColorBrush x:Key="MenuFlyoutBackground">#052350</SolidColorBrush>
    21. <!--默认字体-->
    22. <FontFamily x:Key="DefaultFontFamily">Microsoft YaHei</FontFamily>
    23. </ResourceDictionary>
    3.2 引用资源文件

       打开App.axaml文件,添加,添加后该样式在整个应用生效。

    1. <Application.Resources>
    2. <ResourceDictionary>
    3. <ResourceDictionary.MergedDictionaries>
    4. <MergeResourceInclude Source="/Assets/CommonResource.axaml" />
    5. </ResourceDictionary.MergedDictionaries>
    6. </ResourceDictionary>
    7. </Application.Resources>
    3.3 使用资源 
    1. <Style Selector="TextBox">
    2. <Setter Property="Margin" Value="0 -10 0 10" />
    3. <Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}" />
    4. </Style>

    4. 项目启动页面

    打开App.axaml.cs文件

  • 相关阅读:
    VSCode(Visual Studio Code)扩展及缓存占用C盘空间问题的解决
    备战蓝桥杯Day18 - 双链表
    1、【开始】【简介】Qlib:量化平台
    机器学习评估指标 - f1, precision, recall, acc, MCC
    想转行做产品经理的人为什么这么多?
    jenkins-安装
    屏幕开发学习 -- 迪文串口屏
    Go基础八股
    《C++程序设计原理与实践》笔记 第7章 完成一个程序
    对本地存储的有效期的理解
  • 原文地址:https://blog.csdn.net/confused_kitten/article/details/133674339