1

私はカスタム ListBox 項目テンプレートを開発しており、これまでのところ次のコードを記述しています。

<UserControl x:Class="Application.Test"
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}"
d:DesignHeight="480" d:DesignWidth="480">

<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Image HorizontalAlignment="Right" Height="100" Grid.RowSpan="2" Grid.Column="1" VerticalAlignment="Center" Width="100" Source="ControlTemplates\arrow_white.png"/>
    <TextBlock Name="Title" TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Height="auto" Width="auto" Grid.ColumnSpan="2" Margin="10,212,119,214"/>
</Grid>

画像サンプルへのリンク: http://s7.postimg.org/oeyl8gge3/Capture2.png

この ListBoxItem を 200 px にしたいのですが、すべてのコンテンツはゴムです (両方の向きをサポートするため)。

d:DesignHeight="480" d:DesignWidth="480" を 200px に変更しようとすると、ListBoxItem は 200px になりますが、テキストは消えます...

私は何を間違っていますか?

4

1 に答える 1

0

列の定義を逆にする必要があります。

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

Imageこの方法では、固定幅のコントロールに対応するように自動的にサイズが変更されるため、右の列のサイズは固定されます。そして、最初の列はすべてのスペースを使用するために常に引き伸ばされます。

しかし、これでは十分ではありません。個々のリスト ボックス項目には、それぞれ独自の幅があります。各アイテムの幅が最大になるようにするには、次のコードを使用します。

<ListBo>
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>
于 2013-07-05T15:17:37.210 に答える