m0s
m0s

Reputation: 4280

How to dynamically set DataTemplate based on item type?

The objective is to have different layout for items in a ListView depending on the item's type. For example some items would have text and a button, other text and image, others text and check-box etc.

Having a DataTemplate for each kind of item would solve the problem. I looked into DataTrigger but it seems to allow only change properties of items, but not the layout template. Does the framework provider any convenient way of doing this?

Upvotes: 0

Views: 339

Answers (2)

Yuval Peled
Yuval Peled

Reputation: 5038

I believe DataTemplateSelector is what you're looking for. Or use DataType.

Upvotes: 1

blindmeis
blindmeis

Reputation: 22445

does each item's type has is own class?

so item1 is classA, item2 is classB? if yes then you can simply create one datatemplate for each type.

if not you can create style and trigger to handle your conditions. maybe you post some code so we can helk you better

Upvotes: 0

Related Questions