Andrew Lichtenberg
Andrew Lichtenberg

Reputation: 123

WPF emended ItemTemplateSelector in a DataTemplates

Hey there I am new to WPF and I have a project where I want to use an ItemTemplate selector inside a DataTemplate

<DataTemplate x:Key="PicTemp">
...
</DataTemplate>
<DataTemplate x:key="MsgTemp">
...
</DataTemplate>
<DataTemplate x:key="PuttingItTogether">
<TextBlock Text="HeaderText" />
???<ItemTemplateSelector="{StaticResource Select Either PicTemp or MsgTemp>}"/>
</DataTemplate>

In the third Data Template how can I setup a template selctor to choose either the PicTemp or MsgTem DataTempalte?

Upvotes: 0

Views: 3161

Answers (2)

HCL
HCL

Reputation: 36765

An ItemsTemplateSelector is used for ItemsControl such as ListBox, ListView and ItemsPresenter.
It can be used to select a DataTemplate based on the items source object. However in most cases, it is more easy to specify the DataType-property of the corresponding DataTemplate.

In your example I don't see how exactly you want to use the TemplateSelector, since you don't have an ItemsControl.

Upvotes: 0

Dan J
Dan J

Reputation: 16708

ItemTemplateSelector is a property of an ItemsControl. You need to apply a style to the ItemsControl in order to set it. And you need to set it to an instance of an ItemTemplateSelector subclass that contains logic to return the appropriate DataTemplate for each item in the ItemsControl based on some property of the item.

I found this tutorial useful for learning how to correctly implement a DTS.

Upvotes: 1

Related Questions