鉴于以下类别和子类别:

  1. 动画(家庭的家伙,卡尔文&Hobes,偏僻地区,只鸭子的故事,发疯的Toons,粉红色和大脑)
  2. 芝麻街(奥斯卡,厄尼&伯特克米特德的青蛙,Elmo,饼干怪兽,Grover)

我在寻找一种方式呈现它(动态)在行和列如下:

----------------------------------------------------
| Animations                                       |
----------------------------------------------------
| Family Guy  | Calvin & Hobes | The Boondocks     |
----------------------------------------------------
| Duck Tales  | Looney Toons   | Pinky & The Brain |
----------------------------------------------------
| Sesame Street                                    |
----------------------------------------------------
| Oscar       | Ernie & Bert   | Kermit de Frog    |
----------------------------------------------------
| Elmo        | Cookie Monster | Grover            |
----------------------------------------------------

P/S:我知道该名单的控制(获取定,数据网,列表视图等等。) 并非他们似乎满足这一标准。

有帮助吗?

解决方案

什么你需要做的是创建一个查询,以某种方式组你的项目通过类别的(或者,你已经,或者您可以使用皇宫以为你层次通过一组由...进入查询)。

然后你可以用一个获取定,结合以查询结果中,显示的数据与ItemTemplate包含一个标题和另一个获取定其具有ItemsPanelTemplate设WrapPanel或UniformGrid.

假设你能得到你的数据在以下类别(对不起,VB在这里,但C#不会远离那如果你需要的话):

Public Class Category

    Private _Name As String
    Public Property CategoryName() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        End Set
    End Property

    Private _SubCategories As New List(Of SubCategory)
    Public Property SubCategories() As List(Of SubCategory)
        Get
            Return _SubCategories
        End Get
        Set(ByVal value As List(Of SubCategory))
            _SubCategories = value
        End Set
    End Property

End Class

Public Class SubCategory

    Private _Name As String
    Public Property SubCategoryName() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            _Name = value
        End Set
    End Property

End Class



<ItemsControl ItemsSource="{Binding QueryResult}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Border BorderThickness="1"
                        BorderBrush="Black">

                    <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />                            
                    </Grid.RowDefinitions>
                        <Border BorderThickness="1"
                                BorderBrush="Black">
                            <TextBlock Margin="2"
                                       Text="{Binding CategoryName}" />
                        </Border>
                            <ItemsControl Grid.Row="1"
                                          ItemsSource="{Binding SubCategories}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Border BorderThickness="1"
                                                BorderBrush="Black">

                                            <TextBlock Margin="2"
                                                       Text="{Binding SubCategoryName}" />
                                        </Border>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <UniformGrid Columns="3" />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                            </ItemsControl>
                    </Grid>
                </Border>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

这是一个非常粗略的模板,你就必须修补与边界得到你需要什么,但是,要做的伎俩。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top