开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜