哪种控制更适合下面显示的输出?

在我对数据库和代码进行一些更改之前,我的项目运行良好。

变更前:

输出:

Tile1 Tile7 .......... Tile(Nx) Tile2 Tile8 Tile(N-x+1) Tile3 Tile9 .... Tile4 Tile10 .... Tile5 Tile11 .... Tile6 Tile12 Tile(N) 

数据库中的表: 1 ——- [主键]标题| 背景| 图片| ParentID * ——- [外键]

XAML:

                                         

目前:

要求输出:

 Text1 Text2 Text3 .......... Text(N) Tile1 Tile3 Tile7 Tile9 Tile13 Tile(Nx) ..... Tile2 Tile4 Tile8 Tile10 Tile(Nx + 1) ..... Tile5 Tile11 .... ..... Tile6 Tile12 .... Tile(N) 

数据库中的变化:

在此处输入图像描述

我在ViewModel和XAML文件中尝试了很多更改,现在它搞砸了。 所以,如果我发布这些代码,那么对任何人都没用。

我希望我已经正确地提到了一切。

更新

首先,我很抱歉。 我的互联网连接一整天都没有了。 我刚刚看过你的消息。

现在,我有了一些东西。 我可以从Design_Master_MenuItems中的数据库中获取数据。 见下图:

在此处输入图像描述

但仍然Binding无法正常工作。 我的意思是我没有填充ItemsControl中的ListBoxes。

这是我目前的XAML:

                     

这是myViewModel:

 public class MainWindowViewModel : ViewModelBase { public MainWindowViewModel() { using (Entities db = new Entities()) { ParentMenus = new ObservableCollection(from d in db.Design_Master_ParentMenus select d); if (SelectedParent != null) MenuCategories = new ObservableCollection(from d in db.Design_Master_Categories where d.ParentMenuID == SelectedParent.ParentMenuID select d); } } private ObservableCollection _parentMenus; public ObservableCollection ParentMenus { get { return _parentMenus; } set { _parentMenus = value; OnPropertyChanged("ParentMenus"); } } private Design_Master_ParentMenus _selectedParent; public Design_Master_ParentMenus SelectedParent { get { return _selectedParent; } set { _selectedParent = value; OnPropertyChanged("SelectedParent"); using (Entities db = new Entities()) { MenuCategories = new ObservableCollection(from d in db.Design_Master_Categories where d.ParentMenuID == SelectedParent.ParentMenuID select d); } } } private ObservableCollection _menuCategories; public ObservableCollection MenuCategories { get { return _menuCategories; } set { _menuCategories = value; OnPropertyChanged("MenuCategories"); } } } 

是的,我将在接下来的10个小时内无法使用。 如果您在上述代码中发现任何错误,您可以发表评论。 感谢您的帮助。

UPDATE2

是的,我现在在Output窗口中找到绑定错误:

 System.Windows.Data Error: 17 : Cannot get 'Design_Master_TileItem' value (type 'ICollection`1') from '' (type 'Design_Master_Catego_79D2EFE4D31EC6575261E40C340C9D078D37C022F94C70A5F8A88A9017957C24'). BindingExpression:Path=Design_Master_TileItem; DataItem='Design_Master_Catego_79D2EFE4D31EC6575261E40C340C9D078D37C022F94C70A5F8A88A9017957C24' (HashCode=28842409); target element is 'ListBox' (Name=''); target property is 'ItemsSource' (type 'IEnumerable') TargetInvocationException:'System.Reflection.TargetInvocationException: Property accessor 'Design_Master_TileItem' on object 'System.Data.Entity.DynamicProxies.Design_Master_Catego_79D2EFE4D31EC6575261E40C340C9D078D37C022F94C70A5F8A8 8A9017957C24' threw the following exception:'The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.' ---> System.ObjectDisposedException: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. System.Windows.Data Error: 17 : Cannot get 'Design_Master_TileItem' value (type 'ICollection`1') from '' (type 'Design_Master_Catego_79D2EFE4D31EC6575261E40C340C9D078D37C022F94C70A5F8A88A9017957C24'). BindingExpression:Path=Design_Master_TileItem; DataItem='Design_Master_Catego_79D2EFE4D31EC6575261E40C340C9D078D37C022F94C70A5F8A88A9017957C24' (HashCode=13006057); target element is 'ListBox' (Name=''); target property is 'ItemsSource' (type 'IEnumerable') TargetInvocationException:'System.Reflection.TargetInvocationException: Property accessor 'Design_Master_TileItem' on object 'System.Data.Entity.DynamicProxies.Design_Master_Catego_79D2EFE4D31EC6575261E40C340C9D078D37C022F94C70A5F8A8 8A9017957C24' threw the following exception:'The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.' ---> System.ObjectDisposedException: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. 

首先,您需要一个带有水平StackPanel的ListView作为面板模板来获取“大”块。

然后,对于每个块,您将需要一个“标题”,然后是另一个ListView,这次使用垂直WrapPanel作为面板模板。 下面是一个“shell”示例,需要一些样式和绑定才能使其看起来完全符合您的需要,但希望它能让您走上正确的轨道。

                         

更新:

要只有“一个选择”,请确保选择任一列表框都会调用您的属性上的setter。 我通常不会使用RelativeSource来做这个,所以这里有一个例子,如果你想尝试它(你的窗口/用户控件被命名为“Root”:

 "{Binding ElemantName=Root, Path=DataContext.SelectedTileItem}" 

转换器要做到这一点真的很复杂。 这个答案有一种可接受的方式来设置你想要做的事情,这可能是你想要的方式(我会使用组名路由,因为这基本上是你想要做的)。