2012-02-13 3 views
0

(アイテム用の)リストボックステンプレートを作成しようとしています。これは私が持っているものです。TextBlock =リストボックステンプレートにストレッチする方法は?

<Window.Resources> 
    <DataTemplate x:Key="ItemTemplate"> 
     <Grid Margin="5"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="60"/> 
       <ColumnDefinition Width="*"/> 
      </Grid.ColumnDefinitions> 
      <StackPanel Grid.Column="0"> 
       <TextBlock Text="TEKS" FontSize="20" FontWeight="Bold" Background="#FF502F8F" Foreground="White" Width="{Binding Path=Width, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type StackPanel}}}" TextAlignment="Center" /> 
       <TextBlock Text="{Binding Level}" FontSize="24" Background="#FF058C44" HorizontalAlignment="Center" Width="{Binding Path=Width, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type StackPanel}}}" Foreground="White" TextAlignment="Center" FontFamily="Segoe UI Light" /> 
      </StackPanel> 
      <TextBlock Grid.Column="1" Text="{Binding Owner}" FontSize="20" FontWeight="Bold" TextWrapping="Wrap" /> 
     </Grid> 
    </DataTemplate> 
</Window.Resources> 

<Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}}"> 
    <ListBox ItemTemplate="{DynamicResource ItemTemplate}" ItemsSource="{Binding Collection}" Margin="44,39,82,103" Style="{DynamicResource ListBoxStyle}"/> 
</Grid> 

これはイメージです。

enter image description here

あなたはテキストブロックは、より多くの幅を拡張して見ることができますか?リストボックス内に文字列の折り返しを表示したい。私は間違って何をしていますか?

+0

- さもなければそれは内容を収容するように成長するでしょう。 –

+0

テキストブロックにwidth = autoを試しましたか? –

答えて

2
  1. 無効に水平スクロール:

    <ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ...> 
    
  2. 有効にテキストの折り返し(すでにケース):私はあなたがテキストブロックの幅を設定する必要があると思う

    <TextBlock TextWrapping="Wrap" ...> 
    
+0

Guau、それはH.B.もう1つの質問ですが、スタックパネル内のすべてのテキストブロックをどのように整列させるかはわかります(私はstrentchを意味します)。 –

+0

現在、 'Stretch'に設定されるべき' TextBlock'の下に 'Horizo​​ntalAlignment =" Center "を設定しています。 –

+0

ありがとうH.B.それは仕事です! –

関連する問題