• 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文件

  • 相关阅读:
    ELK部署Redis+Keepalived高可用环境
    oracle 不支持的字符集 orai18n.jar ZHS16GBK 异常问题解决
    SAP Web IDE 安装使用
    18.1. Fabric2.2 区块链农产品溯源系统 - 多Peer部署(扩展)
    Kafka3.0.0版本——消费者(消费者组初始化流程图解)
    51单片机学习笔记5 流水灯实现及蜂鸣器控制
    JS案例----轮播图
    华为5700系列清除console口密码
    Unity-CharacterController(角色控制器)
    报错:crbug/1173575 non-js module files deprecated
  • 原文地址:https://blog.csdn.net/confused_kitten/article/details/133674339