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 207503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:44:29+00:00 2026-05-11T17:44:29+00:00

I have a WPF App that implements a ListView. I would like to show

  • 0

I have a WPF App that implements a ListView. I would like to show an image (a small icon) in one of the columns depending on the type of the data that row represents. Sort of like the display you see in Windows Explorer.

I am using DataTriggers elsewhere in my XAML, it seems like a similar method could be used to swap out entire cell contents, but I can’t find an example of anyone doing that.

Any thoughts?

  • 1 1 Answer
  • 1 View
  • 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-11T17:44:30+00:00Added an answer on May 11, 2026 at 5:44 pm

    There are three common techniques for this.

    1) DataTrigger:

    <DataTemplate x:Key="ImageColumn">
        <Grid>
            <Image x:Name="img" Source="MyImage.png"/>
            <Rectangle x:Name="rect" Fill="Red" Visibility="Hidden"/>
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding TriggerProperty}" Value="2">
                <Setter TargetName="rect" Property="Visibility" Value="Visible"/>
                <Setter TargetName="img" Property="Visibility" Value="Hidden"/>
            </DataTrigger>
            <!--etc...-->
        </DataTemplate.Triggers>
    </DataTemplate>
    

    2) ValueConverters:

    public class MyConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string strVal = value as string;
            switch (strVal)
            {
                case "2":
                    Rectangle rect = new Rectangle();
                    rect.Fill = Brushes.Red;
                    return rect;
    
                default:
                    Image img = new Image();
                    ImageSourceConverter s = new ImageSourceConverter();
                    img.Source = (ImageSource)s.ConvertFromString("MyImage.png");
                    return img;
            }
        }
    }
    

    3) MVVM (Model-View-ViewModel):

    Create a ViewModel class that wraps your data model. This ViewModel would evaulate the properties in the data model and combine them with logic into a new property.

    public UIElement Icon
    {
        get
        {
            if (TriggerProperty == "2")
            {
                Rectange rect = new Rectangle();
                rect.Fill = Brushes.Red;
                return rect;
            }
    
            else
            {
                Image img = new Image();
                ImageSourceConverter s = new ImageSourceConverter();
                img.Source = (ImageSource)s.ConvertFromString("MyImage.png");
                return img;
            }
        }
    }
    

    And the XAML:

    <DataTemplate x:Key="ImageColumn">
        <ContentControl Content="{Binding Icon}"/>
    </DataTemplate>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF app that starts another application, I'd like for my application
i have a wpf app that is updating date/time in one dispatchertimer, another is
This is an interesting conundrum. We have a WPF app that has a Vista-like
I have a WPF app that is using the MVVM pattern. Hooking up buttons
I have a wpf app that needs to communicate(exchange data) with a custom designed
We have a WPF app that allows our users to download encrypted content and
I have a WPF app, my purpose is that the app can be automatically
I have a folder in my WPF app Images that has several .png files
Ok, I have a ResourceDictionary definition that I used for a WPF app below:
I have a WPF application that is a fullscreen kiosk app. It's actually a

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.