WPF GridViewRowPresenter in ItemsControl

I'm just starting to learn WPF, and I'm trying to use the GridViewRowPresenter inside an ItemsControl to essentially duplicate the functionality of a simple table in HTML. ListView is not suitable as it is interactive (which I don't want). I am attached to a general list of objects of unknown magnitude.

I have a list of a custom object that has two string properties: FirstName and LastName. The following code works:

<ItemsControl Name="myItemsControl">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=FirstName}"/>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

while nothing is displayed:

<ItemsControl Name="myItemsControl">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <GridViewRowPresenter>
                <GridViewRowPresenter.Columns>
                    <GridViewColumnCollection>
                        <GridViewColumn DisplayMemberBinding="{Binding Path=FirstName}"></GridViewColumn>
                        <GridViewColumn DisplayMemberBinding="{Binding Path=LastName}"></GridViewColumn>
                    </GridViewColumnCollection>
                </GridViewRowPresenter.Columns>
            </GridViewRowPresenter>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

I am not sure where to go from here, and I would really appreciate any help! Thanks!

+4
source share
1 answer

, ItemsControl Grid, :

<ItemsControl ItemsSource="{Binding Items}" Grid.IsSharedSizeScope="True">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" SharedSizeGroup="FirstName"/>
                    <ColumnDefinition Width="*" SharedSizeGroup="LastName"/>
                </Grid.ColumnDefinitions>

                <TextBlock Text="{Binding FirstName}"/>
                <TextBlock Grid.Column="1" Text="{Binding LastName}"/>
            </Grid>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

Panel, Grid (, Grid), . Panel ItemsPanel ItemsControl.

+10

All Articles