Directory Freebies VS CheatSheet Forum

RSS

Email

Translate

Home About Archive Privacy Contact Advertise Write for Dev102
Posted by Amit on Jun 13th, 2008 | Filed under .Net, WPF | 2 Comments

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...
Write Article for Dev102

Write for Dev102!

We pay for user submitted tutorials and articles that we publish. Anyone can send in a contribution

Learn More