0

I'm trying to add an image to my ItemTemplate in ListViewm however, I am not getting past the "address" of the image by databinding. I can display the names perfectly, only the images that does not. How can I pass the name of the image to ImageBrushand not to Image.Source

Here is my code in C#:

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

        List<User> items = new List<User>();
        items.Add(new User() { BitmapImage = "default-user-image.png", Name = "John Doe"});
        items.Add(new User() { BitmapImage = "default-user-image.png", Name = "Jane Doe"});
        items.Add(new User() { BitmapImage = "default-user-image.png", Name = "Sammy Doe"});
        lvDataBinding.ItemsSource = items;
    }
}

public class User
{
    public string BitmapImage { get; set; }

    public string Name { get; set; }

    public int Age { get; set; }

    public string Mail { get; set; }
}

As it can be observed, I have a User object, and the BitmapImage as String.

And here's my XAML code, which gets the items from the list:

<ListView Name="lvDataBinding" Grid.Column="0">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Ellipse Width="40" Height="40">
                            <Ellipse.Fill>
                                <ImageBrush ImageSource="{Binding BitmapImage}"/>
                            </Ellipse.Fill>
                        </Ellipse>
                        <TextBlock Text="{Binding Name}" FontWeight="Bold" />
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
Roberto Pinheiro
  • 1,260
  • 13
  • 30

0 Answers0