Horizontal orientated WrapPanel within ItemsControl lists vertically

后端 未结 1 1156
走了就别回头了
走了就别回头了 2021-02-08 20:34

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

1条回答
  •  一生所求
    2021-02-08 20:57

    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

    enter image description here

    0 讨论(0)
提交回复
热议问题