2012-07-11 6 views
0

ListBox에 대해 여러 개의 열을 지정하고 싶지만 내 인터넷 검색 기술이 실패했습니다.ListBox의 ItemsPanelTemplate 레이아웃을 어떻게 사용자 정의합니까?

표시된 열을 사용자 정의하려면 ListBoxItemsPanelTemplate을 어떻게 수정할 수 있습니까?

편집 : 나는

이 나는 ​​수직 스크롤

+0

'ItemsPanelTemplate'을 수정하려는 제어 도구는 무엇입니까? – Rachel

+0

'ListBox'는 블렌드가 자동 생성 한 기능이기 때문에 ... 덜 정교한 앨범 아트보기와 같이 목록의 항목을 표에 표시하려고합니다. – humanstory

+1

실제로 ListBox의 선택 기능이 필요합니까? 그렇지 않다면, 나는'ItemsControl'로 전환 할 것을 권하고, [ItemsControl Examples] (http://rachel53461.wordpress.com/2011/09/17/wpf-itemscontrol-example/) 내 블로그에 'ItemsPanelTemplate' 설정에 대한 예제를 포함하십시오 – Rachel

답변

0

그것은 shoudln't을 잃게 제외하고 작동 코드

<ItemsPanelTemplate x:Key="ItemsPanelTemplate1"> 
     <UniformGrid Columns="3" /> 
    </ItemsPanelTemplate> 

을 시도했습니다 이미 시도했던 것을 넣어 깜빡 어렵지는 않지만 의존합니다 - 각 항목에 대해 눈금 또는 일부 컨트롤을 사용하고 그 안에 가변 너비의 항목이있는 동일한 너비가 아닌 열을 신경 쓰지 않으면 ItemTemplate에 눈금을 추가하면됩니다. 해야 할 것 . 그렇지 않으면 당신은 명시 적으로, 크기를 설정하거나하자 - 조금 더 복잡 될 경우에 - 당신은 모든 격자 열은 가변 크기의 콘텐츠와 같은 크기 원하는 경우

<ItemTemplate> 
    <DataTemplate> 
     <Grid> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition> 
       <ColumnDefinition> 
       <ColumnDefinition> 
      </Grid.ColumnDefinitions> 
      <SomeControl Grid.Column="0" /> 
      <SomeControl Grid.Column="1" /> 
      <SomeControl Grid.Column="2" /> 
     </Grid> 
    </DataTemplate> 
</ItemTemplate> 

유일한 문제는 내용은 열 너비를 "Auto"으로 설정하여 크기를 결정합니다.

0

3 열, 항목 줄 바꿈 및 주변 레이아웃에 따라 작동하는 자동 세로 스크롤을 사용하여 내가 생각하는 것의 간단한 예가 있습니다.

<ListBox HorizontalContentAlignment="Stretch"> 
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <UniformGrid Columns="3"/> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <Border MinHeight="150" Margin="5" Background="Green" CornerRadius="4"> 
       <TextBlock Text="{Binding}" Foreground="White"/> 
      </Border> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 

    <System:String>One</System:String> 
    <System:String>Two</System:String> 
    <System:String>Three</System:String> 
    <System:String>Four</System:String> 
    <System:String>Five</System:String> 
    <System:String>Six</System:String> 
    <System:String>Seven</System:String> 
    <System:String>Eight</System:String> 
    <System:String>Nine</System:String> 
    <System:String>Ten</System:String> 
</ListBox> 
관련 문제