We have all used WPF DataTemplates, but I bet most of you never gave thought to the meaning of the x:Key attribute. We all know the meaning of the DataType attribute, which determines to what type of data the template will apply to. But what about the x:Key why is it there? Lets tale a look at the following code:
<Window.Resources>
<DataTemplate DataType=”{x:Type data:s}”>
<Button Width=”50″ Height=”50″>
<TextBlock Text=”{Binding text}”></TextBlock>
</Button>
</DataTemplate>
</Window.Resources>
<Canvas>
<ItemsControl ItemsSource=”{Binding}”>
</ItemsControl>
</Canvas>
Continue Reading...
DataTemplates are a great feature introduced in WPF, it allows to determine how data is presented and how data binding accesses the presented data. Just as we can apply a visual style to a specific UI control, we can do it for a specific data type. There is just one problem here, DataTemplates are good [...]
Continue Reading...
Hi all.
First of all Let me give credit to Shahar A. for showing me this.
As it turns out, my latest post about DataTemplates was not the most efficient way to do this.
I used a different Template for the root and a second one for the all the rest of the data.
What i learned is that [...]
Continue Reading...
Hi all.
I am going to show you a simple example of how to use Hierarchical DataTemplates in a tree view for an easy display of hierarchical Data.
The Example shows the links in a WebPage recursively.
First we will create the data model that we want to show, note that we have two separate models, one [...]
Continue Reading...