【发布时间】:2010-10-21 20:44:28
【问题描述】:
<ItemsPanelTemplate x:Key="lbWrapPanelItemsPanelTemplate">
<wp:WrapPanel Margin="2" Background="Beige" HorizontalAlignment="Stretch">
</wp:WrapPanel>
</ItemsPanelTemplate>
.....
<Grid Background="LightCoral" MinWidth="500" MinHeight="500">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<sdk:GridSplitter Grid.Column="0" Background="AliceBlue" />
<StackPanel Grid.Column="0" FlowDirection="LeftToRight">
<Button Width="40">Left</Button>
<Button Width="40">Right</Button>
</StackPanel>
<Grid Background="Bisque" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="100"></RowDefinition>
</Grid.RowDefinitions>
<ListBox ItemsPanel="{StaticResource lbWrapPanelItemsPanelTemplate}" x:Name="bookListBox" HorizontalAlignment="Stretch" Grid.Row="0" ItemsSource="{Binding Path=BookSource}" ItemTemplate="{StaticResource dirtSimple}" />
<wp:WrapPanel Grid.Row="1">
<Button Width="200" Command="{Binding Path=AddItemCommand}">Bottom</Button>
<Button Width="200" Command="{Binding ChangeTemplateCommand}" CommandParameter="{StaticResource vmDataTemplate}">White</Button>
<Button Width="200" Command="{Binding ChangeTemplateCommand}" CommandParameter="{StaticResource vmDataTemplate2}">Lavender</Button>
</wp:WrapPanel>
</Grid>
</Grid>
ListBox 工作完美,除了(米色)WrapPanel 似乎延伸到无穷大。随着更多项目添加到 ListBox,它只是向右滚动而不是换行。如果我在 WrapPanel 中添加一个具体的大小,这会导致东西被换行,但(显然)会导致 LB 中的项目显示在所有可用空间的子集中。
有没有办法告诉 WrapPanel 只占用所有可用空间?
【问题讨论】:
标签: silverlight silverlight-toolkit