【发布时间】:2011-11-03 00:59:43
【问题描述】:
检查这个 xaml:
<Window
x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Width="300">
<ListBox HorizontalContentAlignment="Stretch"
Grid.IsSharedSizeScope="True">
<ListBox.ItemsSource>
<x:Array Type="{x:Type sys:Int32}">
<sys:Int32>25</sys:Int32>
<sys:Int32>10</sys:Int32>
<sys:Int32>50</sys:Int32>
<sys:Int32>30</sys:Int32>
<sys:Int32>80</sys:Int32>
</x:Array>
</ListBox.ItemsSource>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem"
BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="#FFE41515">
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="name" Width="Auto"/>
<ColumnDefinition SharedSizeGroup="value"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Value:"/>
<ProgressBar
Value="{Binding Mode=OneWay}"
Grid.Column="1"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Window>
这是输出,注意ProgressBar 没有被拉伸,为什么?
如果项目是红色的,则表示每个项目都填满了整个宽度,那么为什么ProgressBar 没有拉伸??
【问题讨论】:
标签: wpf xaml listbox listboxitem stretch