WPF Reflections

Mar 10 2008   9:39PM GMT

Re-using data template across controls



Posted by: MarkWPF
Tags:
Databinding
WPF
XAML

How do you use the same data template across different types of control?

Well you can :-)

Normally when you define the data template, you do something like the following:

<DataTemplate DataType=”{x:Type ListViewItem}>
<TextBlock Text=”{Binding Path=ISIN}” />
</DataTemplate>

However, it is a bit of a pain to then copy it for different types, but there is a way:

<DataTemplate DataType=”{x:Type local:Instrument}>
<TextBlock Text=”{Binding Path=ISIN}” />
</DataTemplate>

(where Instrument is a class in your assembly)

This template can now be used with any control type.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: