Reputation: 147
say its a listview bound to a collection i fix the listview width to 100
the itemtemplate is some thing like below
<DataTemplate> <Border>
<TextBlock Foreground="{Binding Path=Color}"
Text="{Binding Path=Name}"
TextTrimming="CharacterEllipsis"/>
</Border> </DataTemplate>
i want to be able to
maximum allowed is 3 how do i make the text box trim to a uniformresize itself to a proper size giving space to other textboxes
i don't wanto have c# code written is it possible to achieve using only XAML ?
Upvotes: 0
Views: 130
Reputation: 8634
try this
<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>
Upvotes: 1
Reputation: 33364
You can change ItemsPanel
to UniformGrid
which will split available space evenly between your items. Here's an ItemsControl
example
<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>
Upvotes: 0