How to dynamically change a gridview item?

I have a Grid View, which is used to display β€œtags”, which is a list of rows that are dynamic in size. Using the following code:

<GridView ItemsSource="{Binding Tags}" ItemTemplate="{StaticResource TagTemplate}" VerticalAlignment="Bottom" Grid.RowSpan="2" SelectionMode="None" /> 

I use the following template for elements:

 <DataTemplate x:Name="TagTemplate"> <Border BorderBrush="Gray" BorderThickness="1" Opacity="75"> <TextBlock Text="{Binding}"/> </Border> </DataTemplate> 

When added to the grid, the size of each of the elements has the same size as the first:

enter image description here

How to dynamically change elements in a gridview?

+4
source share
1 answer

So something like;

 <ScrollViewer> <ItemsControl ItemsSource="{Binding Tags}"> <!-- ItemsPanelTemplate --> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> <!-- Or use WrapPanel depending on its display --> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <!-- ItemContainerStyle --> <ItemsControl.ItemTemplate> <DataTemplate> <Border BorderBrush="Gray" BorderThickness="1" Opacity="75" Padding="3" Margin="3,0"> <TextBlock Text="{Binding}"/> </Border> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </ScrollViewer> 
+1
source

Source: https://habr.com/ru/post/1444386/


All Articles