首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

DataTemplate中的Grid解决方法

2013-03-12 
DataTemplate中的GridListBox.ItemTemplateDataTemplateGrid BackgroundYellow Grid.RowDefinit

DataTemplate中的Grid
<ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Background="Yellow" >
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            
                            <TextBlock Text="{Binding}" Grid.Row="0" Grid.Column="0" FontSize="10"/>
                            <TextBlock Text="{Binding}" Grid.Row="0" Grid.Column="1" FontSize="30"/>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>

当Grid在ListBox的DataTemplate时,Grid的Width并没有充满ListBoxItem的Width,而是有多宽就扩展多宽。

如下图的黄色部分,求大神指点,如何让Grid自动充满一行啊
DataTemplate中的Grid解决方法

[解决办法]
横向对齐设置成 stretch.
[解决办法]
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="HorizontalContentAlignment"
                            Value="Stretch" />


                </Style>
            </ListBox.ItemContainerStyle>


热点排行