2014-01-09 72 views
0

說,它的一個ListView綁定到一個集合 我修復列表視圖寬度爲100自動父大小

ItemTemplate模板內調整的DataTemplate就像下面

<DataTemplate> <Border> 
    <TextBlock Foreground="{Binding Path=Color}" 
       Text="{Binding Path=Name}" 
       TextTrimming="CharacterEllipsis"/> 
</Border> </DataTemplate> 

我希望能夠到一些東西

the templates with multiple data

最大允許有3如何使文本框修剪到uniformresize自己親每個大小給其他文本框的空間

我不想讓C#代碼寫入是否可以實現只使用XAML?

回答

0

您可以將ItemsPanel更改爲UniformGrid,這將在您的項目之間平均分配可用空間。下面是一個例子ItemsControl

<ItemsControl ItemsSource="{Binding Path=Items}" > 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
     <UniformGrid Rows="1"/> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
     <Border> 
      <TextBlock 
       Foreground="{Binding Path=Color}" 
       Text="{Binding Path=Name}" 
       TextTrimming="CharacterEllipsis"/> 
     </Border> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 
1

試試這個

<ListView Width="100"> 
    <ListView.ItemsPanel> 
     <ItemsPanelTemplate> 
      <UniformGrid Width="100" Columns="3"/> 
     </ItemsPanelTemplate> 
    </ListView.ItemsPanel> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
      <Border> 
       <TextBlock Foreground="{Binding Path=Color}" Text="{Binding Path=Name}" TextTrimming="CharacterEllipsis"/> 
      </Border> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView>