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>