How to create grid lists with C # in WPF?

0

I'm new to C #. I would like to know how to create a grid list that contains images, something similar to what android has:

Thank you in advance.

    
asked by anonymous 15.01.2018 / 20:32

1 answer

0

Content must be placed within ItemsControl like this:

<ItemsControl 
            ItemsSource="{Binding Tasks, UpdateSourceTrigger=PropertyChanged}"  
            ScrollViewer.CanContentScroll="True"
            ScrollViewer.VerticalScrollBarVisibility="Auto"
            ScrollViewer.HorizontalScrollBarVisibility="Auto"
            >
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel Orientation="Horizontal"  
                    AllowDrop="True" 
                    Width="{Binding ActualWidth, ElementName=itmWrapPanel}" 
                    Height="{Binding ActualHeight, ElementName=itmWrapPanel}"  />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate  >
            <local:ucTask  />  <!-- esse ucTask é um usercontrol com o que será exibido -->
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

ucTask

<UserControl x:Class="blablabla.ucTask"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
>
    <Grid Focusable="False" >
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" Margin="0,5">
            <Image  Source="{Binding Imagem}"  Focusable="False"/>
        </Grid>
        <Grid Grid.Row="1" HorizontalAlignment="Center">
            <Label Content="{Binding Texto}" FontSize="10"/>
        </Grid>
    </Grid>
</UserControl>

Q: Positioning and / or alignment customizations are not in this example, and are on your own.

P.S.2: The WrapPanel is to distribute the items in its ItemsControl the alignment and positioning should be checking on it tb

    
05.02.2018 / 14:24