Andrey
Andrey

Reputation: 21295

How to show a DataTemplate in the window

I have declared a DataTemplate in Window.Resources; I don't intend to use it inside an ItemsControl, but rather just use it as a user control. How do I put it on a form?

Upvotes: 0

Views: 159

Answers (2)

Grokys
Grokys

Reputation: 16546

If you're using MVVM, and want to display the DataTemplate in response to a property on your ViewModel, you can use:

<ContentPresenter Content="{Binding Data}"/>

Where Data is a property of the type you registered the DataTemplate with.

Upvotes: 1

Andy
Andy

Reputation: 30418

You can put a ContentControl into your user control, and set its ContentTemplate to your DataTemplate.

<ContentControl ContentTemplate="{StaticResource keyOfDataTemplate}"/>

Upvotes: 3

Related Questions