2012-01-08 8 views
4

ListBox内のアイテムに割り当てられたすべてのスペースを埋めたいとします。しかし、彼らはしません。彼らは必要なスペースだけを使います。次のようにWindows Phoneユーザーコントロールがリストボックスで伸びない

のListBoxに見えます:

<ListBox x:Name="StripesList" Grid.Row="1"> 
    <ListBox.ItemContainerStyle> 
    <Style TargetType="ListBoxItem"> 
     <Setter Property="HorizontalAlignment" Value="Stretch"/> 
     <Setter Property="Margin" Value="0,4,0,4"/> 
    </Style> 
    </ListBox.ItemContainerStyle> 
</ListBox> 

そしてListBoxの項目としてバインドされたユーザーコントロール:

<UserControl x:Class="Blip.UI.Controls.StatusStrip" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}" 
    HorizontalAlignment="Stretch"> 

    <Grid HorizontalAlignment="Stretch"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="*" MinHeight="76" /> 
       <RowDefinition Height="20" /> 
      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="64" /> 
       <ColumnDefinition Width="*" /> 
      </Grid.ColumnDefinitions> 

      <Image Grid.Column="0" Grid.Row="0" Width="64" Height="64"/> 

      <TextBlock Grid.Column="1" Grid.Row="0" Text="Test"/> 

      <Grid Grid.ColumnSpan="2" Grid.Row="1"> 
       <StackPanel Orientation="Horizontal" VerticalAlignment="Bottom"> 
        <Image Source="/Resources/1.png" Width="18" Height="18"/> 
        <TextBlock Text="Test" VerticalAlignment="Center" /> 
       </StackPanel> 
      </Grid> 
    </Grid> 
</UserControl> 

私は間違っているのでしょうか?

答えて

13

HorizonatalContentAlignmentStretchに設定する必要があります。

<ListBox x:Name="StripesList" Grid.Row="1"> 
    <ListBox.ItemContainerStyle> 
    <Style TargetType="ListBoxItem"> 
     <Setter Property="HorizontalAlignment" Value="Stretch"/> 
     <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
     <Setter Property="Margin" Value="0,4,0,4"/> 
    </Style> 
    </ListBox.ItemContainerStyle> 
</ListBox> 

そうでないコンテンツはちょうどそれがむしろ利用できるすべてのスペースを使用するよりも必要スペースを占めるためです。

+0

です。ありがとう。 –

2

HorizontalContentAlignmentを設定してください。ListBoxItemsはすでに伸びていますが、その内容には影響しません。

関連する問題