2012-02-13 1 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

당신은 TextBlock에 더에게 폭을 확장 볼 수 있을까요? 목록 상자 안에 문자열 줄 바꿈을 표시하려고합니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

+0

- 그렇지 않으면 콘텐츠를 수용 할 수있게됩니다. –

+0

텍스트 블록에 width = auto를 시도 했습니까? –

답변

2
  1. 안 수평 스크롤 :

    <ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ...> 
    
  2. 사용 텍스트 줄 바꿈 (이미 경우) : 난 당신이 텍스트 블록의 폭을 설정할 필요가 있다고 생각

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

Guau, H.B. 한 가지 더 궁금한 점이 있습니다. 스택 패널 안에 모든 텍스트 블록을 정렬하는 방법을 알고 있습니까 (저는 strentch를 의미합니다). –

+0

현재'Stretch'로 설정해야하는 하단 TextBlock에'HorizontalAlignment = "Center"를 설정했습니다. –

+0

H.B. 그게 다야! –