1

Windows phone での要素の配置に常に問題がありました。誰かが私を助けてくれることを願っています:私はリストボックスをコードビハインドから動的に入力しました:

<ListBox Name="list" Grid.Row="1" HorizontalAlignment="Center">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Name}"  Style="{StaticResource list_service_item}"/>
            </DataTemplate>
        </ListBox.ItemTemplate>

スタイルは App.xaml で定義されています。

<Style x:Key="list_service_item" TargetType="TextBlock">
        <Setter Property="FontSize" Value="25"/>
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="Foreground" Value="Peru" />
        <Setter Property="TextWrapping" Value="Wrap"/>
        <Setter Property="HorizontalAlignment" Value="Center"/>
        <Setter Property="Margin" Value="0 0 0 5"/>
    </Style>

配置プロパティを除いて、正しく機能しているように見えます。

リストボックスのアイテムが同じ長さの場合はすべてうまく機能しますが、そのうちの 1 つが長い場合、他のすべてのアイテムは中央に配置されずに、長いアイテムの先頭に揃えられます。

ここに画像の説明を入力

どうすればこれを解決できますか?

4

2 に答える 2

1

各 ListBoxItem の ItemContainer を ListBox の幅まで伸ばす必要があります。

<ListBox.ItemContainerStyle>
  <Style TargetType="ListBoxItem">
    <Setter Property="HorizontalContentAlignment"
            Value="Stretch" />
  </Style>
</ListBox.ItemContainerStyle>
于 2013-10-09T13:37:58.243 に答える