0

Little rusty here. I'm trying to display a image in a WPF Gridview. Below is the XAML for the template column. The converter is also below, which is calling and finding the image and returning the correct BitmapImage. The image data loads and the column scales to size but the image is not displayed. What is it I'm missing...

<DataGridTemplateColumn Header="JIRA ICON CONVERTER" Width="SizeToCells" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Source="{Binding TaskType, Converter={StaticResource IconConverter}}" Stretch="None"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

Converter

<Window.Resources>
    <local:EnumToIconConverter x:Key="IconConverter"/>
</Window.Resources>
public class EnumToIconConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            switch ((JiraType)value)
            {
                case JiraType.Task:
                    return new BitmapImage(new Uri("TaskIcon.png", UriKind.Relative));
                    
                case JiraType.Story:
                    return new BitmapImage(new Uri("StoryIcon.png", UriKind.Relative));
                    
                default:
                    return new BitmapImage(new Uri("StoryIcon.png", UriKind.Relative));
            }           
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
M.Powell
  • 23
  • 4
  • You would typically store and load such images as assembly resources, i.e. add the image files to your Visual Studio project, set their Build Action to Resource, and load them by [Resource File Pack URIs](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/app-development/pack-uris-in-wpf?redirectedfrom=MSDN&view=netframeworkdesktop-4.8#Resource_File_Pack_URIs___Local_Assembly) like `new BitmapImage(new Uri("pack://application:,,,/TaskIcon.png"))`. E.g. as shown here: https://stackoverflow.com/a/25714375/1136211 – Clemens Sep 19 '22 at 21:27
  • @M.Powell: What does "The image data loads" mean if you can't see the image? Did you confirm that the paths are valid? – mm8 Sep 20 '22 at 12:36

0 Answers0