Hi,@Stefan Grönberg . Welcome Microsoft Q&A.
I test your code results as follows. Could you point out where the problem is, and what is your expected result?
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace ListViewDemo
{
public partial class MainWindow : Window, INotifyPropertyChanged
{
public MainWindow()
{
InitializeComponent();
DataContext = this;
this.Avatars.ItemsSource = new AvatarClass[]
{
new AvatarClass { AvatarName = "Animals_1", ImageData = LoadImage("C:
new AvatarClass { AvatarName = "Animals_2", ImageData = LoadImage("C:
new AvatarClass { AvatarName = "Animals_3", ImageData = LoadImage("C:
new AvatarClass { AvatarName = "Animals_4", ImageData = LoadImage("C:
new AvatarClass { AvatarName = "Animals_5", ImageData = LoadImage("C:
new AvatarClass { AvatarName = "Animals_6", ImageData = LoadImage("C:
};
}
private ImageSource LoadImage(string v)
{
ImageSource _imageLocation = new BitmapImage(new Uri(v));
return _imageLocation;
}
private AvatarClass selecedItme;
public AvatarClass SelectedItem
{
get { return selecedItme; }
set
{
if (selecedItme != value)
{
selecedItme = value;
OnPropertyChanged("SelectedItem");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
public class AvatarClass
{
public string AvatarName { get; set; }
public ImageSource ImageData { get; set; }
}
}
Update:
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" Grid.IsSharedSizeScope="True" ScrollViewer.CanContentScroll="True"/>
<!--<UniformGrid Columns="5" Grid.IsSharedSizeScope="True" ScrollViewer.CanContentScroll="True"
UseLayoutRounding="True" />-->
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
The result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.