I
I
iRumba2015-08-14 09:14:41
WPF
iRumba, 2015-08-14 09:14:41

How to arrange elements in UniformGrid using Binding?

Hello. Found this way

<ItemsControl ItemsSource="{Binding Path=Pages}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Border BorderThickness="1" BorderBrush="Black" Background="AliceBlue" Margin="10" Width="150" Height="100">
                    <TextBox Text="{Binding Path=Header}"/>
                </Border>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Columns="4"/>
                <!--<WrapPanel/>-->
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>

Everything is fine except for one moment. ItemsControl.ItemTemplate doesn't work. That is, the ItemsSource="{Binding Path=Pages}" elements appear in the grid in its pure form and the template is not applied to each element. I can even remove the ItemTemplate block and nothing will change. If we replace the UniformGrid with another panel, the result will be the same.
Tell me what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question