How do you select the right size icon from a multi-resolution .ico file in WPF?

I use simple Markup Extension for that: /// /// Simple extension for ico, let you choose icon with specific size. /// Usage sample: Image Stretch="None" Source="{common:Icon /ControlsTester;component/icons/custom-reports. Ico, 16}" /// Or: Image Source="{common:Icon Source={Binding IconResource},Size=16} " /// public class IconExtension : MarkupExtension { private string source; public string Source { get { return this.

Source; } set { // Have to make full pack URI from short form, so System. Uri can regognize it. This.

Source = "pack://application:,,," + value; } } public int Size { get; set; } #endregion #region Методы public override object ProvideValue(IServiceProvider serviceProvider) { var decoder = BitmapDecoder. Create(new Uri(this. Source), BitmapCreateOptions.

DelayCreation, BitmapCacheOption. OnDemand); var result = decoder.Frames. SingleOrDefault(f => f.

Width == this. Size); if (result == default(BitmapFrame)) result = decoder.Frames. OrderBy(f => f.

Width).First(); return result; } public IconExtension(string source, int size) { this. Source = source; this. Size = size; } public IconExtension() { } } Xaml usage: or.

I make a mistake. You can't set property in Markup Extension with binding (so can't be ) But you can easily write similar converter, that can be used with binding: – Nikolay Aug 11 at 11:55.

If the reason you're asking is that the icon looks blurry to you, check out this very good article on the topic that I used to solve that problem: blogs.msdn.com/dwayneneed/archive/2007/1... You will have to use a custom control that not only sizes the icon exactly, but ensures that it coincides exactly with the pixel grid. Only then will you avoid interpolation and therefore blurriness. Trying to find some info on your query about image size selection in icons...will post back if I find any...

Well, it's only blurry in the sense that the image was rescaled. I'm just really curious on how to pick the right image from a multi-image, multi-resolution . Ico file in Xaml.

– SergioL Jun 5 '09 at 19:07.

It doesn't appear to be possible using Xaml only.

Thats really unfortunately but thanks for the brutal honesty, it's better than no answer at all. – jpierson May 12 '10 at 15:10.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions