.ico 中的图像作为 DynamicResource
情况如下:
- 我的应用程序中有很多图标,并且它们以几种不同的尺寸使用。
我使用图标作为动态资源,例如:
一些图标采用.xaml格式,一些采用.png格式
我添加新图标,例如:
问题:
我想要 .ico 格式的图标,我可以将其用作动态资源。
我想要 .ico 格式的图像,因为这种文件格式允许在一个文件中包含几种不同的图像大小。 .xaml 中的图标可以完全调整大小,但加载需要很长时间(因为我真的有很多图标!)。
是否可以将 .ico 文件添加为 DynamicResource
并向其添加 x:key
?
即使我以某种方式添加这些 .ico 图像,它们会改变大小(取决于它们有多少位置)?
Situation looks like that:
- I have many icons in application and they are used in few different sizes.
I use icons as DynamicResource for example like that:
<igRibbon:MenuTool (...) LargeImage="{DynamicResource IconAdd}" />
<s:Item (...) Icon="{DynamicResource IconAdd}"/>
Some of icons are in .xaml and some in .png format
I add new icons for example like that:
<BitmapImage x:Key="IconAdd" UriSource="../Icons/IconAdd.png" />
The problem:
I would like to have icons in .ico format that I can use as DynamicResource.
I want images in .ico because this file format allows to have few different image sizes in one file. Icons in .xaml are fully resizable but they took to much time to load (because I have really a lot of them!).
Is it possible to add .ico file as DynamicResource
and add x:key
to it?
Even if I somehow add those .ico images, will they change size (depending on how much place they have)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,可以将 .ico 文件添加为
DynamicResource
(当然,因为它是资源,所以它必须有一个x:Key
)。然而,它们不会自动改变大小。每个尺寸都可以像这样从 .ico 中提取,其中我为每个图标的框架创建一个
Image
,设置为框架的确切尺寸,然后添加该Image
> 到名为imageStack
的StackPanel
:当您直接使用 .ico 时,它将选择具有最大像素分辨率的帧,并根据该位图的大小调整该位图的大小
图像
控件,或无论您的Image
、Button
或显示它的其他控件有什么内容对齐/大小调整属性。用于控制添加哪个框架的一些选项并不完整,但可以作为解决方案的想法:
BitmapFrames
并将它们添加到ResourceDictionary
> 带有'MyIcon16'
、'MyIcon32'
等键。MarkupExtension
或IValueConverter
以提取符合特定条件(例如索引或大小)的帧。DynamicResource
,因此您可以随时更改与特定资源键关联的框架。'MyIcon'
键将 32x32 帧作为Window
的ResourceDictionary
中的资源,并将 64x64 帧作为在不同范围内具有相同键的资源,例如该Window
内的Grid
。在Grid
中使用{DynamicResource MyIcon}
的任何内容都将显示 64x64 帧,而窗口中的其他所有内容都显示 32x32 帧。Yes, it is possible to add .ico files as a
DynamicResource
(and of course, because it is a resource, it must have anx:Key
).They will not automatically change size, however. Each size is extractable from the .ico like this, in which I make an
Image
for each of the icon's frames set to the exact size of the frame, and then add thatImage
to aStackPanel
calledimageStack
:When you just use the .ico directly, it will choose whichever frame has the largest pixel resolution and resize that bitmap based on the size of the
Image
control, or whatever content alignment/sizing properties are in place for yourImage
,Button
, or other control that is displaying it.A few options for controlling which frame is added that aren't complete, but may serve as ideas towards a solution:
BitmapFrames
and add them to theResourceDictionary
with keys like'MyIcon16'
,'MyIcon32'
, and so on.MarkupExtension
orIValueConverter
to extract a frame matching certain criteria such as index or size.DynamicResource
, you can change which frame is associated with a particular resource key at any time.Window
'sResourceDictionary
with the key'MyIcon'
, and have the 64x64 frame as a resource with the same key in a different scope, such as aGrid
within thatWindow
. Anything using{DynamicResource MyIcon}
in theGrid
will show the 64x64 frame, while everything else in the window shows the 32x32 frame.