Difference between key and name in wpf



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>
<Style x:Key="myBtnStyle" TargetType="{x:Type Button}">
..
</Style>
</Window.Resources>
<Button Style ="{StaticResource myBtnStyle}">Seekyourcareer</Button> //it will work fine
<Window.Resources>
<Style x:Name="myBtnStyle" TargetType="{x:Type Button}">
..
</Style>
</Window.Resources>
<Button Style ="{StaticResource myBtnStyle}">Seekyourcareer</Button> //it will not work fine