Quantcast
Channel: WPF Reflections » Databinding
Viewing all articles
Browse latest Browse all 10

Re-using data template across controls

$
0
0

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.


Viewing all articles
Browse latest Browse all 10

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>