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

前提:

Avalonia版本11.0.0

1.配置文件

1.1 添加配置文件

1.2 读取配置文件 

添加System.Configuration.ConfigurationManager

using Avalonia.Controls;
using System.Configuration;

namespace AvaloniaApplication7.Views
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            // 读取配置项
            var DBOption = ConfigurationManager.AppSettings["DBOption"];
        }
    }
}

2.样式

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

<Styles xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
	<Design.PreviewWith>
	</Design.PreviewWith>
	<Style Selector="TextBlock">
		<Setter Property="Foreground" Value="White" />
		<Setter Property="FontSize" Value="16" />
		<Setter Property="FontWeight" Value="Normal"/>
	</Style>
</Styles>
 2.2 引用样式

       打开App.axaml文件,添加<StyleInclude Source="你要用的样式文件.axaml"/>,添加后该样式在整个应用生效。

   <Application.Styles>
       <FluentTheme />
	<StyleInclude Source="/Assets/Styles/CommonStyles.axaml"/>
   </Application.Styles>

3.资源文件

3.1 添加资源文件

<ResourceDictionary xmlns="https://github.com/avaloniaui"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
	<SolidColorBrush x:Key="WindowDefaultBackground">#336699</SolidColorBrush>
	<!--Disabled颜色-->
	<Color x:Key="DisabledColor">#545454</Color>
	<Brush x:Key="EditWordColor">#FFFFFA</Brush>
	<Brush x:Key="ComboBoxBackground">#003366</Brush>
	<Brush x:Key="ComboBoxPopupBackground">#003366</Brush>

	<SolidColorBrush x:Key="GridColor1">#003e62</SolidColorBrush>
	<!--表头背景色-->
	<SolidColorBrush x:Key="ColumnHeaderBackground">#666699</SolidColorBrush>
	<!--行背景色-->
	<SolidColorBrush x:Key="RowBackground">#111B59</SolidColorBrush>
	<!--Grid背景色-->
	<Brush x:Key="GridBackground">#06173E</Brush>
	<!--Grid背景色-->
	<Brush x:Key="GridBackground1">#111B59</Brush>
	<SolidColorBrush x:Key="SystemControlBackgroundAltHighBrush">#1f497d</SolidColorBrush>
	<!--Memu的下级Popup背景色-->
	<SolidColorBrush x:Key="MenuFlyoutBackground">#052350</SolidColorBrush>
	<!--默认字体-->
	<FontFamily x:Key="DefaultFontFamily">Microsoft YaHei</FontFamily>
</ResourceDictionary>
3.2 引用资源文件

   打开App.axaml文件,添加<MergeResourceInclude Source="你要用的样式文件.axaml"/>,添加后该样式在整个应用生效。

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

4. 项目启动页面

打开App.axaml.cs文件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值