---
title: "Access a UserControl from code in WPF app"  
description: "Access a UserControl from code in WPF app"  
author: "Jayden Bell"  
published: 2013-12-16  
updated: 2013-12-16  
canonical: https://www.mindstick.com/forum/1774/access-a-usercontrol-from-code-in-wpf-app  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# Access a UserControl from code in WPF app

I have a created a [usercontrol](https://www.mindstick.com/forum/12739/set-the-enabled-property-of-a-usercontrol-from-codebehind) in my [wpf](https://www.mindstick.com/forum/304/wpf) application. I have used it like so:

```
<Page x:Class="InstallerToolkit.Pages.PageVideosNvr"  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  xmlns:my="clr-namespace:MyProject.UserControls"  mc:Ignorable="d"  d:DesignHeight="525" d:DesignWidth="1050"Title="PageVideos">  <Grid>        <my:UserControlVideoPlayer Name="VideoPlayer" Margin="559,74,35,155">    </my:UserControlVideoPlayer></Grid>
```

[Now](https://yourviews.mindstick.com/view/81402/it-s-liberals-vs-progressives-in-us-politics-now) in my C# [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page) I want to [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) it but the VideoPlayer object doesnt appear when I type its [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide) in the [code behind](https://www.mindstick.com/forum/2199/call-javascript-s-function-from-code-behind) c# page.

What I do to access it as I want to set one of its properties.

## Replies

### Reply by Pravesh Singh

Hi Jayden,

Give x:Name to your UserControl instead of Name

<my:UserControlVideoPlayer x:Name="VideoPlayer" Margin="559,74,35,155">

It will be accessible now in [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) behind using this.VideoPlayer.

I would suggest to make it a thumb rule that always use x:Name whenever referring to elements in XAML.


---

Original Source: https://www.mindstick.com/forum/1774/access-a-usercontrol-from-code-in-wpf-app

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
