WPF 图标库
WPF icon repository
我有图标列表,这些图标将为不同的按钮显示,即保存删除。
我想要做的是列出一些 xaml 文件中的所有图标,例如 app.xaml
<Resource x:Key="error" Source="Icons/Error.ico" />
<Resource x:Key="save" Source="Icons/save.ico" />
然后想要访问单个文件中的相同内容,如下所示。
Icon="{Binding save}"
如果有人建议我正确的方法,我将不胜感激。
- 创建资源字典
Images.xaml
以这种形式将所有图像添加到该词典
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<BitmapImage x:Key="Icon1"
UriSource="Images/icon1.png" />
.....
</ResourceDictionary>
想用的时候
<Image Source={StaticResource Icon1} />
别忘了将 Image.xaml 添加到您要使用它的地方...实际上您可以将它直接合并到 App.xaml
中的主词典中
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Images.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
我有图标列表,这些图标将为不同的按钮显示,即保存删除。 我想要做的是列出一些 xaml 文件中的所有图标,例如 app.xaml
<Resource x:Key="error" Source="Icons/Error.ico" />
<Resource x:Key="save" Source="Icons/save.ico" />
然后想要访问单个文件中的相同内容,如下所示。
Icon="{Binding save}"
如果有人建议我正确的方法,我将不胜感激。
- 创建资源字典
Images.xaml
以这种形式将所有图像添加到该词典
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <BitmapImage x:Key="Icon1" UriSource="Images/icon1.png" /> ..... </ResourceDictionary>
想用的时候
<Image Source={StaticResource Icon1} />
别忘了将 Image.xaml 添加到您要使用它的地方...实际上您可以将它直接合并到 App.xaml
中的主词典中<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Images.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>