WPFwiki, wpf, wiki, .net 3.0, windows presentation foundation, FAQ, free resources, solution, development, microsoft Home of the world's largest WPF FAQ
Edit

Category

XAML

Edit

Question

When should I use x:Key and when should I use x:Name when creating elements?

Edit

Answer

It depends on where you create your element.

x:Key is only valid in the scope of a ResourceDictionary element. x:Key is used as the primary identifier for elements in the ResourceDictionary. Specifying x:Name is not considered valid (it will cause an exception when accessing resources).

On the other hand, x:Name is valid in the scope of everything but a ResourceDictionary. x:Key is not valid outside the ResourceDictionary scope.

Edit

Partner Sites

gymnastics leotards

All content is Copyright ©2007 Xceed Software Inc. unless otherwise indicated. See the Terms of Service. Contributors must read and agree to the Contribution Policy. WPFwiki is brought to you by Xceed, makers of the powerful yet free Xceed DataGrid for WPF.