---
title: "What is the difference between X:name and x:key?"  
description: "What is the difference between X:name and x:key?"  
author: "Anonymous User"  
published: 2013-10-14  
updated: 2020-09-19  
canonical: https://www.mindstick.com/interview/1808/what-is-the-difference-between-x-name-and-x-key  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# What is the difference between X:name and x:key?

**x:Key-**X:Key identifies objects in resources section, can be accessed by resourceDictionary .x:key is used for items that are being added as values to a dictionary, most for styles and other resources that are being added to a ResourceDictionary. When setting the x:Key attribute, there is actually no corresponding property on the object or even an attached dependency property being set. It is simply used by the XAML processor to know what key to use when calling Dictionary.Add.

**x:Name-**X:name idetifies a UIElment in XAML Tree is a bit more complicated. x:Name- used to apply an associated name to an object (typically an object derived from FrameworkElement) within the scope of some parent element. This scope is called a "namescope" and the easiest way to think of it is to imagine a UserControl that contains a <TextBox x:Name="foo" />.

## Answers

### Answer by Anonymous User

**x:Key-**X:Key identifies objects in resources section, can be accessed by resourceDictionary .x:key is used for items that are being added as values to a dictionary, most for styles and other resources that are being added to a ResourceDictionary. When setting the x:Key attribute, there is actually no corresponding property on the object or even an attached dependency property being set. It is simply used by the XAML processor to know what key to use when calling Dictionary.Add.

**x:Name-**X:name idetifies a UIElment in XAML Tree is a bit more complicated. x:Name- used to apply an associated name to an object (typically an object derived from FrameworkElement) within the scope of some parent element. This scope is called a "namescope" and the easiest way to think of it is to imagine a UserControl that contains a <TextBox x:Name="foo" />.


---

Original Source: https://www.mindstick.com/interview/1808/what-is-the-difference-between-x-name-and-x-key

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
