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>