自定义列表框项目未拉伸

时间:2013-12-22 02:59:41

标签: c# .net xaml windows-phone-8

如何将mainGrid水平拉伸到列表框的大小?我已将列表框设置为拉伸,自动宽度和mainGrid设置为拉伸和自动但不会拉伸到列表框的大小。

 <DataTemplate x:Key="AccountItem">
                <Grid Name="mainGrid" ShowGridLines="True">
                    <Grid.Background>
                        <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                            <GradientStop Color="#FFFFFFF3"/>
                            <GradientStop Color="DarkGray" Offset="0.672"/>
                        </LinearGradientBrush>
                    </Grid.Background>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid VerticalAlignment="Top" Grid.Row="0" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <TextBlock x:Name="accountName" TextWrapping="Wrap" Text="{Binding Name}" HorizontalAlignment="Left" Foreground="White"/>
                        <TextBlock x:Name="accountType" TextWrapping="Wrap" Text="{Binding Type}" Foreground="White" HorizontalAlignment="Right" Grid.Column="1"/>
                    </Grid>
                    <Grid VerticalAlignment="Center" Grid.Row="1" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <TextBlock TextWrapping="Wrap" Text="Balance:" HorizontalAlignment="Left" Foreground="White"/>
                        <TextBlock x:Name="accountBalance" TextWrapping="Wrap" Text="{Binding Balance}" HorizontalAlignment="Right" Foreground="White" Grid.Column="1"/>
                    </Grid>
                    <Grid VerticalAlignment="Bottom" Grid.Row="2" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <TextBlock TextWrapping="Wrap" Text="Available Balance:" HorizontalAlignment="Left" Foreground="White"/>
                        <TextBlock x:Name="accountAvailableBalance" TextWrapping="Wrap" Text="{Binding AvailableBalance}" HorizontalAlignment="Right" Foreground="White" Grid.Column="1"/>
                    </Grid>
                </Grid>
            </DataTemplate>

<Grid x:Name="LayoutRoot">
        <Grid.Background>
            <ImageBrush Stretch="Fill" ImageSource="/Assets/background.png"/>
        </Grid.Background>


        <ListBox x:Name="accountsList" Margin="20,136,20,0" ItemTemplate="{StaticResource AccountItem}"  />

    </Grid>

1 个答案:

答案 0 :(得分:0)

尝试将Horizo​​ntalContentAlignment设置为Stretch: