我在Star size网格列中有一个Silverlight 5 Listbox,在Listbox DataTemplate中有另一个Grid。
我想要做的是填充第二列的DataTemplate网格中的可用空间。如下图所示,它只填充所包含文本的扩展名。
如何让内容填满可用空间?
<ListBox x:Name="TopFaultsListBox" Margin="2" ItemsSource="{Binding TopFaults, Mode=OneWay}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectedIndex="-1" Background="{x:Null}"
BorderThickness="5" BorderBrush="#FFB1925C" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="#FFE29826">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock x:Name="FailureCount" Foreground="Red" FontSize="40" Grid.Row="0" Grid.RowSpan="3" Text="{Binding FaultCount}" Margin="10"/>
<TextBlock x:Name="AssemblyName" FontSize="20" Text="{Binding AssemblyName}" Grid.Column="1" Grid.Row="1"/>
<TextBlock x:Name="FaultInformation" FontSize="20" Text="{Binding FaultInformation}" Grid.Column="1" Grid.Row="2"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
答案 0 :(得分:3)
您需要在ListBox的HorizontalContentAlignment
中指定ItemContainerStyle
并将其设置为Stretch
。默认值为Left。
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>