I have two DataTemplates defined within my XAML, each used for a seperate ItemsControl panel.
The main ItemsControl lists Foo objects stored within an ObservableCollecti
I think its because you are adding each image item to a new WrapPanel
in GameImagesTemplate
, you should just have to set the ItemsControl
ItemsPanelTemplate
to WrapPanel
in the GameTemplate
Example:
Xaml:
Code:
public partial class MainWindow : Window
{
private ObservableCollection _fileList = new ObservableCollection();
public MainWindow()
{
InitializeComponent();
foreach (var item in Directory.GetDirectories(@"C:\StackOverflow"))
{
FileList.Add(new Foo
{
Name = item,
FileList = new ObservableCollection(Directory.GetFiles(item).Select(x => new Bar { FileInfo = new FileInfo(x) }))
});
}
}
public ObservableCollection FileList
{
get { return _fileList; }
set { _fileList = value; }
}
}
public class Foo
{
public string Name { get; set; }
public ObservableCollection FileList { get; set; }
}
public class Bar
{
public FileInfo FileInfo { get; set; }
}
Result