Silverlight - 另一个列表框下的列表框 - 数据绑定问题

发布于 2024-11-09 14:02:41 字数 4196 浏览 0 评论 0原文

我有一个包含所有类别的列表框 每个类别将包含另一个列表框中的子类别 我如何数据绑定?

每个包含“Boards”作为其子类别的“类别” 这是我的 xaml

<ListBox Background="Transparent" BorderThickness="0" Grid.Row="3" Grid.ColumnSpan="2" Margin="0" Padding="0" HorizontalContentAlignment="Stretch" ItemContainerStyle="{StaticResource ListBoxItemStyle}" ItemsSource="{StaticResource designTimeCategoriesDS}" DataContext="{StaticResource designTimeCategoriesDS}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel x:Name="Category" Orientation="Vertical" HorizontalAlignment="Stretch">
                <Border CornerRadius="6" Padding="0" Margin="0" Height="30" HorizontalAlignment="Stretch">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF6D869F" Offset="0"/>
                            <GradientStop Color="#FFA6BACE" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <sdk:Label x:Name="CategoryName" FontSize="16" Margin="8,0" Foreground="White" FontWeight="Bold" Height="30" HorizontalAlignment="Stretch"/>
                </Border>
                <ListBox x:Name="CategoryBoards" Background="Transparent" BorderThickness="0" Margin="0" Padding="0" HorizontalContentAlignment="Stretch" ItemContainerStyle="{StaticResource ListBoxItemStyle}" ItemsSource="{Binding }">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="0" HorizontalAlignment="Stretch">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="70"/>                  
                                    <ColumnDefinition Width="350*"/>                
                                    <ColumnDefinition Width="70*"/>                 
                                    <ColumnDefinition Width="70*"/>                 
                                </Grid.ColumnDefinitions>
                                <HyperlinkButton FontSize="16" Margin="0,0,0,1" Padding="8" Foreground="Black" FontWeight="Bold" VerticalAlignment="Stretch" Background="#FFE7EAEF"></HyperlinkButton>
                                <StackPanel Grid.Column="1" Margin="1,0,0,1" Background="#FFF0F4F7">
                                    <HyperlinkButton FontSize="14" Margin="0" Padding="8,8,8,0" Foreground="#FFD97B33" FontWeight="Bold" Content="{Binding Path=CategoryBoards.BoardName}" />
                                    <sdk:Label Margin="0" Padding="8,0,8,8" Foreground="Black" Content="{Binding Path=CategoryBoards.BoardDescription}" />
                                </StackPanel>
                                <StackPanel Grid.Column="2" Margin="1,0,0,1" Background="#FFE7EAEF">
                                    <sdk:Label Margin="0" Padding="8,8,8,0" Content="{Binding Path=BoardPosts}" />
                                    <sdk:Label Margin="1,0,0,1"  Padding="8,0,8,8" Content="{Binding Path=BoardTopics}" />
                                </StackPanel>
                                <StackPanel Grid.Column="3" Margin="1" Background="#FFF0F4F7">
                                    <sdk:Label Margin="0" Padding="4,2,4,0" Content="Last post by {User}"/>
                                    <sdk:Label Margin="0"  Padding="4,0,4,0" Content="in {Topic Name}"/>
                                    <sdk:Label Margin="0"  Padding="4,0,4,2" Content="on {Date}"/>
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>                                          
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

I have a ListBox which contains all the Categories
and each category will contain subcategories in an other ListBox
how do i databind?

each "Category" containing "Boards" as its subcategory
this is my xaml

<ListBox Background="Transparent" BorderThickness="0" Grid.Row="3" Grid.ColumnSpan="2" Margin="0" Padding="0" HorizontalContentAlignment="Stretch" ItemContainerStyle="{StaticResource ListBoxItemStyle}" ItemsSource="{StaticResource designTimeCategoriesDS}" DataContext="{StaticResource designTimeCategoriesDS}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel x:Name="Category" Orientation="Vertical" HorizontalAlignment="Stretch">
                <Border CornerRadius="6" Padding="0" Margin="0" Height="30" HorizontalAlignment="Stretch">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF6D869F" Offset="0"/>
                            <GradientStop Color="#FFA6BACE" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <sdk:Label x:Name="CategoryName" FontSize="16" Margin="8,0" Foreground="White" FontWeight="Bold" Height="30" HorizontalAlignment="Stretch"/>
                </Border>
                <ListBox x:Name="CategoryBoards" Background="Transparent" BorderThickness="0" Margin="0" Padding="0" HorizontalContentAlignment="Stretch" ItemContainerStyle="{StaticResource ListBoxItemStyle}" ItemsSource="{Binding }">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="0" HorizontalAlignment="Stretch">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="70"/>                  
                                    <ColumnDefinition Width="350*"/>                
                                    <ColumnDefinition Width="70*"/>                 
                                    <ColumnDefinition Width="70*"/>                 
                                </Grid.ColumnDefinitions>
                                <HyperlinkButton FontSize="16" Margin="0,0,0,1" Padding="8" Foreground="Black" FontWeight="Bold" VerticalAlignment="Stretch" Background="#FFE7EAEF"></HyperlinkButton>
                                <StackPanel Grid.Column="1" Margin="1,0,0,1" Background="#FFF0F4F7">
                                    <HyperlinkButton FontSize="14" Margin="0" Padding="8,8,8,0" Foreground="#FFD97B33" FontWeight="Bold" Content="{Binding Path=CategoryBoards.BoardName}" />
                                    <sdk:Label Margin="0" Padding="8,0,8,8" Foreground="Black" Content="{Binding Path=CategoryBoards.BoardDescription}" />
                                </StackPanel>
                                <StackPanel Grid.Column="2" Margin="1,0,0,1" Background="#FFE7EAEF">
                                    <sdk:Label Margin="0" Padding="8,8,8,0" Content="{Binding Path=BoardPosts}" />
                                    <sdk:Label Margin="1,0,0,1"  Padding="8,0,8,8" Content="{Binding Path=BoardTopics}" />
                                </StackPanel>
                                <StackPanel Grid.Column="3" Margin="1" Background="#FFF0F4F7">
                                    <sdk:Label Margin="0" Padding="4,2,4,0" Content="Last post by {User}"/>
                                    <sdk:Label Margin="0"  Padding="4,0,4,0" Content="in {Topic Name}"/>
                                    <sdk:Label Margin="0"  Padding="4,0,4,2" Content="on {Date}"/>
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>                                          
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深白境迁sunset 2024-11-16 14:02:41

只需快速浏览一下您的代码,您唯一需要做的就是将这一行更改

<ListBox x:Name="CategoryBoards" Background="Transparent" BorderThickness="0" 
         Margin="0" Padding="0" HorizontalContentAlignment="Stretch" 
         ItemContainerStyle="{StaticResource ListBoxItemStyle}" 
         ItemsSource="{Binding }">

为:

<ListBox x:Name="CategoryBoards" Background="Transparent" BorderThickness="0" 
         Margin="0" Padding="0" HorizontalContentAlignment="Stretch" 
         ItemContainerStyle="{StaticResource ListBoxItemStyle}" 
         ItemsSource="{Binding Boards}">

内部 ListBox 的 DataContext 将是类别,因此该绑定的源隐式是类别。

Just glancing at your code quickly, the only thing you should need to do is change this line:

<ListBox x:Name="CategoryBoards" Background="Transparent" BorderThickness="0" 
         Margin="0" Padding="0" HorizontalContentAlignment="Stretch" 
         ItemContainerStyle="{StaticResource ListBoxItemStyle}" 
         ItemsSource="{Binding }">

to this:

<ListBox x:Name="CategoryBoards" Background="Transparent" BorderThickness="0" 
         Margin="0" Padding="0" HorizontalContentAlignment="Stretch" 
         ItemContainerStyle="{StaticResource ListBoxItemStyle}" 
         ItemsSource="{Binding Boards}">

The DataContext of your inner ListBox will be the Category, so the source of that binding is, implicitly, the Category.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文