avalonia 资源文件引用

1-引用本项目内资源文件

创建资源文件Option.axmal:

使用字符串要添加此引用:
xmlns:system=“clr-namespace:System;assembly=System.Runtime”

<ResourceDictionary xmlns="https://github.com/avaloniaui"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
					xmlns:system="clr-namespace:System;assembly=System.Runtime">
    <!-- Add Resources Here -->
	<system:String x:Key="Person" >Person</system:String>
</ResourceDictionary>

在App.xml中添加资源文件引用,否则报错

注意:ResourceInclude 和WPF中的ResourceDictionary不同
“Source”的值,Common是项目下第一层文件夹
Source=“/Common/Option.axaml”/

<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"			
             x:Class="TestClient.App">
	<Application.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceInclude Source="/Common/Option.axaml"/>
			</ResourceDictionary.MergedDictionaries>
		</ResourceDictionary>
	</Application.Resources>
</Application>

在控件中引用:

<TextBox Text="{StaticResource Person}" FontSize="14" Height="30" />

2-引用其他项目的资源文件

项目App.axaml文件添加引用

 <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>             
                <ResourceInclude Source='avares://TestResource/SvgIcons.axaml'/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>  

页面使用引用

<Button Click="Btn_Click" Classes="IconStyle" IsVisible="{Binding ElementName=rdoBtn,Path=IsChecked}" >
       <Image Stretch="Uniform" Width="20" Height="20" >
            <DrawingImage Drawing="{StaticResource DelDrawingGroup}"/>
       </Image>
</Button>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值