2014-07-08 76 views
1

我想知道如果你指导我,我如何修复在Windows手机上的网格宽度或griditem宽度。其实我是xaml和windows手机的初学者。这是我的XAML代码:固定在Windows Phone的网格宽度

 <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

+0

你有没有尝试去除ColumnDefinition上的Width =“Auto”?自动意味着它只占用它需要的空间,而不是跨越父控制。 –

+0

你想让它看起来像什么?将'Horizo​​ntalContentAlignment ='Stretch''添加到'ListBox'应该可以修复它的一部分,但是在那个图像上是否保留了空白边缘? –

+0

@ErikElkins谢谢你的回复,是的,我用过但没有改变。 –

回答

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> 

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

+0

非常感谢您的帮助!它完美地工作。 –

+0

很酷的交易,很高兴你有它:) –