x:Key | x:Name |
---|---|
x:Key is used to uniquely identify resources in XAML | x:Name is used to uniquely identify controls (like panels, buttons, textboxes) in XAML. |
It is generally used with Resources which can defined in any of these XAML files (ResourceDictionary.XAML, App.XAML, Window.XAML, Usercontrol.XAML etc.) | It is generally used with controls to use them in the same XAML file or in its code behind. |
x:Key cannot be accessed in code behind. | x:Name can be accessed in code behind |
<Button x:Key=”myBtn”/> //it will not work | <Button x:Name=”myBtn”/> //it will work |
<Window.Resources> |
<Window.Resources> |