0

I have this model:

Public Data
{
    string name;
    string age;
    string id;
    DateTime time;
}

Currently each ListView row contains all this 4 peoperties:

<ListView.View>
        <GridViewColumn Width="20" DisplayMemberBinding="{Binding Index}" />
        <GridViewColumn Width="320" DisplayMemberBinding="{Binding Description}" />
        <GridViewColumn Width="150" DisplayMemberBinding="{Binding IPAddress}" />
        <GridViewColumn Width="150" DisplayMemberBinding="{Binding time}" />
    </GridView>
</ListView.View>

Now i want to make this ListView Width smaller so i want to each Row will contain 2 columns with 2 properties on each of them. Is it possible ?

2 Answers 2

2

You need to override the default CellTemplate of GridViewColumn inorder to display your results inside a ListView.View

<GridViewColumn >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>                            
                                    <StackPanel Orientation="Vertical">
                                        <TextBlock Text="{Binding Index}" />
                                        <TextBlock Text="{Binding Description}"/>
                                    </StackPanel>                                    
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Vertical">
                                    <TextBlock Text="{Binding IPAddress}" />
                                    <TextBlock Text="{Binding time}"/>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
Sign up to request clarification or add additional context in comments.

Comments

0

Don't use a ListView

Use a ListBox DataTemplate with a Grid

2 Comments

Then put a Grid in a ListView. I see nothing about this that requires a ListView.
What this Grid will give me ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.