修复Windows手机上的网格宽度

时间:2014-07-08 14:46:14

标签: xaml windows-phone

我想知道你是否指导我,如何在Windows手机上修复网格宽度或网格物体宽度。实际上我是xaml和windows手机的初学者。这是我的xaml代码:

       <Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0">

        <ListBox x:Name="ListBoxCountry" SelectionChanged="ListBoxCountry_SelectionChanged">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>

                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                <DataTemplate>

                    <Grid Background="#FFD0D2D3" Height="180">

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>

                        <Image Grid.Column="0" Source="Assets/images/icon_bubble_white.png" Stretch="None" Margin="-107,0,0,0" />
                        <Image  Grid.Column="0" Source="{Binding Icon}"  Height="50" Width="50" Stretch="Fill"/>
                        <TextBlock Grid.Column="1" TextAlignment="Center"  Text="{Binding Title}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" />
                    </Grid>

                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

    </Grid>

列表框的丑陋视图,您可以看到网格项目没有合适的宽度大小。 :

enter image description here

1 个答案:

答案 0 :(得分:1)

一般情况下,我希望只需HorizontalContentAlignment="Stretch" ListBox即可完成它,但无论出于何种原因,你说没有削减它,所以我们只是告诉ItemContainerStyle谁的老板是否喜欢。

带给我们更多的东西;

<Grid x:Name="ContentPanel" Grid.Row="1">

   <ListBox x:Name="ListBoxCountry" 
            SelectionChanged="ListBoxCountry_SelectionChanged"
            HorizontalContentAlignment="Stretch">
       <ListBox.ItemContainerStyle>

         <!-- Tell it to do as you wish. 
              Might also use BasedOn if you want to inherit the default stuff with it. -->

         <Style TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
         </Style>

       </ListBox.ItemContainerStyle>
       <ListBox.ItemTemplate>
           <DataTemplate>

               <Grid Background="#FFD0D2D3" Height="180">
                   <Grid.ColumnDefinitions>
                       <ColumnDefinition Width="Auto"/>
                       <ColumnDefinition Width="*"/>
                   </Grid.ColumnDefinitions>

                   <Image Source="Assets/images/icon_bubble_white.png" />
                   <Image Source="{Binding Icon}" Height="50" Width="50" Stretch="Fill"/>
                   <TextBlock Grid.Column="1" Text="{Binding Title}" 
                              HorizontalAlignment="Center" VerticalAlignment="Center" 
                              Foreground="White" />

               </Grid>

           </DataTemplate>
       </ListBox.ItemTemplate>
   </ListBox>

</Grid>

希望这会有所帮助,欢呼。