prag :
Hi I am bit new to WPF (XAML) having an itemControl with list of UI elements . where Binding is done with a Collection property . Now my requirement is initially to show only 1st element from the list and having a +Show More button option upon at the end of list click of it to show rest of the items from the Collection ..
<ItemsControl x:Name="ContentRoot" ItemsSource="{Binding MyCollections}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<grid>
<TextBox Text="{Binding }" />
<TextBox Text="{Binding }" />
</grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
Corentin Pane :
You can have both a ContentControl
(which displays the first item of the collection) and an ItemsControl
(which displays the whole collection) displayed only when a ToggleButton
is checked for example.
<StackPanel>
<StackPanel.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<DataTemplate DataType="{x:Type local:MyViewModel}">
<Grid>
<TextBox Text="{Binding}" />
</Grid>
</DataTemplate>
</StackPanel.Resources>
<ContentControl Content="{Binding MyCollection[0]}"/>
<ToggleButton x:Name="toggle" Content="Show more"/>
<ItemsControl ItemsSource="{Binding MyCollection}" Visibility="{Binding ElementName=toggle, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</StackPanel>
You can then adapt this to fit your exact needs.
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=368521&siteId=1