Silverlight - 另一个列表框下的列表框 - 数据绑定问题
我有一个包含所有类别的列表框 每个类别将包含另一个列表框中的子类别 我如何数据绑定?
每个包含“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需快速浏览一下您的代码,您唯一需要做的就是将这一行更改
为:
内部 ListBox 的 DataContext 将是类别,因此该绑定的源隐式是类别。
Just glancing at your code quickly, the only thing you should need to do is change this line:
to this:
The DataContext of your inner ListBox will be the Category, so the source of that binding is, implicitly, the Category.