Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6247405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:51:56+00:00 2026-05-24T12:51:56+00:00

If I have a multi-resolution icon file (.ico), how can I insure that WPF

  • 0

If I have a multi-resolution icon file (.ico), how can I insure that WPF picks the right sized one? Does setting the width and height of the Image force it, or does WPF simply resize the first icon in the ico file?

This is what I’m using currently (it works, but I’d like to avoid the resizing if that’s what’s happening).

<MenuItem.Icon>
    <Image Source="MyIcons.ico" Width="16" Height="16"  />
</MenuItem.Icon>

I’d like to declare this in Xaml if possible without having to code for it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:51:57+00:00Added an answer on May 24, 2026 at 12:51 pm

    I use simple Markup Extension for that:

    /// <summary>
    /// Simple extension for icon, to let you choose icon with specific size.
    /// Usage sample:
    /// Image Stretch="None" Source="{common:Icon /Controls;component/icons/custom.ico, 16}"
    /// Or:
    /// Image Source="{common:Icon Source={Binding IconResource}, Size=16}"
    /// </summary> 
    public class IconExtension : MarkupExtension
    {
        private string _source;
    
        public string Source
        {
            get
            {
                return _source;
            }
            set
            {
                // Have to make full pack URI from short form, so System.Uri recognizes it.
               _source = "pack://application:,,," + value;
            }
        }
    
        public int Size { get; set; }
    
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var decoder = BitmapDecoder.Create(new Uri(Source), 
                                               BitmapCreateOptions.DelayCreation,
                                               BitmapCacheOption.OnDemand);
    
            var result = decoder.Frames.SingleOrDefault(f => f.Width == Size);
            if (result == default(BitmapFrame))
            {
                result = decoder.Frames.OrderBy(f => f.Width).First();
            }
    
            return result;
        }
    
        public IconExtension(string source, int size)
        {
            Source = source;
            Size = size;
        }
    
        public IconExtension() { }
    }
    

    Xaml usage:

    <Image Stretch="None"
           Source="{common:Icon Source={Binding IconResource},Size=16}"/>
    

    or

    <Image Stretch="None"
           Source="{common:Icon /ControlsTester;component/icons/custom-reports.ico, 16}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have multi-part install that needs a reboot to continue. We added a RunOnce
Modern browsers have multi-tab interface, but JavaScript function window.showModalDialog() creates a modal dialog that
I have a multi-line string that I want to do an operation on each
I have a multi-threaded C++ app which does 3D rendering with the OpenSceneGraph library.
I have a multi-timezone web application that stores all of the datetime values in
I have a multi-threaded Windows application that occasionally deadlocks. Inevitably this happens on a
What is the best way to design the Domain objects which can have multi-lingual
We have multi-website(5) multi-store-view(13) shop. What we need is that only 3 store view
I have multi-thread application that I want to create a thread with different user
Let's suppose that we have multi-site CMS and every website in this CMS having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.