How to change item template of existing ListViewItem when window size changed?

aluzi liu 486 Reputation points
2023-10-27T10:56:26.08+00:00

I have a WinUI3 C# project, I use a ListView to display data.

I have total of 5 type of data, so I create 5 ListViewItem template, use it when window size less than 800px;

If window size is greater than 800px, I need to use another 5 type template to show data.

My requirement is when size exceed 800px, the item in the listview can automatically change to large size template.

So how to do it?

Windows development | Windows App SDK
Developer technologies | .NET | Other
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,736 Reputation points Microsoft External Staff
    2023-11-03T03:09:04.26+00:00

    Hello @aluzi liu,

    I have tested that the ItemTemplate property can be changed dynamically using the WinUI-Gallery sample(MessageViewTemplate -> null).

    GIF 11-3-2023 11-03-00 AM

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.