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开发者_JAVA技巧 on a form?
You can put a ContentControl into your user control, and set its ContentTemplate
to your DataTemplate
.
<ContentControl ContentTemplate="{StaticResource keyOfDataTemplate}"/>
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.
精彩评论