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

  • Home
  • SEARCH
  • 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 785029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:48:31+00:00 2026-05-14T20:48:31+00:00

I want to show a different icon/image depending on an enum value. For example,

  • 0

I want to show a different icon/image depending on an enum value. For example, if I had the following enum:

  public enum UploadStatus
  {
      Unknown = 0,
      WaitingToUpload = 10,
      Uploading = 20,
      Uploaded = 30,
      UploadFailed = 40
  }

I’d like to write XAML that looks something like this:

...

<EnumImage Value="{Binding Path=CurrentStatus}">
  <EnumImageItem Value="Unknown"         Image="/images/unknown.png" />
  <EnumImageItem Value="WaitingToUpload" Image="/images/clock.png" />
  <EnumImageItem Value="Uploading"       Image="/images/upload.png" />
  <EnumImageItem Value="Uploaded"        Image="/images/tick.png" />
  <EnumImageItem Value="UploadFailed"    Image="/images/error.png" />
</EnumImage>

...

I’ve found many posts suggesting custom IValueConverters, but those solutions don’t fit the XAML paradigm.

Any pointers or suggestions?

  • 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-14T20:48:32+00:00Added an answer on May 14, 2026 at 8:48 pm

    Here is a Value converter which maintains the “XAML paradigm” that is the relationship between enum values and images is maintained in XAML.

    [ContentProperty("Items")]
    public class EnumToObjectConverter : IValueConverter
    {
        public ResourceDictionary Items { get; set; }
    
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string key = Enum.GetName(value.GetType(), value);
            return Items[key];
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException("This converter only works for one way binding");
        }
    }
    

    Note that this is very generic it actually maps values of any enum type to any arbitary object. This is what its usage looks like in Xaml:-

    <Grid.Resources>
      <local:EnumToObjectConverter x:Key="Icons">
        <ResourceDictionary>
     <BitmapImage x:Key="Unknown" UriSource="/images/unknown.png" />
          <BitmapImage x:Key="WaitingToUpload" UriSource="/images/clock.png" />        
          <BitmapImage x:Key="Uploading"       UriSource="/images/upload.png" />        
          <BitmapImage x:Key="Uploaded"        UriSource="/images/tick.png" />        
          <BitmapImage x:Key="UploadFailed"    UriSource="/images/error.png" />        
        </ResourceDictionary>
      </local:EnumToObjectConverter>
    </Grid.Resources>
    

    This converter can be used when binding property of the enum type:-

     <Image Source="{Binding Status, Converter={StaticResource Icons}}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 538k
  • Answers 538k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your project build type must be 'Class Library' to generate… May 17, 2026 at 1:53 am
  • Editorial Team
    Editorial Team added an answer No, it's not possible as the client-side code can never… May 17, 2026 at 1:53 am
  • Editorial Team
    Editorial Team added an answer You need to make sure you're also dealing with stderr,… May 17, 2026 at 1:53 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

How can I handle different views in XCode? Let's say I want to show
I want to show multiple lines with different text styles for each item in
I want to make two different app icons, and programmatically switch betweem then. When
I've put a little app together that has three tabs to show three different
I want to show hidden div on hover of <div class=thumb> and i have
My application (C++ WinAPI) creates an icon in the system tray. I have set
I was wondering if the type of javascript errors can be grouped into different
I have 3 tables that have same columns,but different data ( deposits,withdrawals,transfers ) CREATE
I'm developing a webchat system which shows the current 'members' of the chat as
What's the best way to align icons (left) and text (right) or the opposite

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.