Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access control in Code Behind that was 'created' in XAML

Tags:

I have a control I 'created' in XAML that I want to access through the Code Behind.

<wincontrols:LiveTileFrameElement Name="PendingAuthsFrame1" Text="Pending" />  this.PendingAuthsFrame1.Text = "334"; 

However, I get a Build Error on the second statement above stating MyApp.MainWindow does not contain a definition for 'PendingAuthsFrame1' and no extension method.... it keeps going but you get the idea I'm guessing.

What am I missing or doing wrong?

like image 381
Refracted Paladin Avatar asked Nov 26 '12 17:11

Refracted Paladin


People also ask

What is code behind in XAML?

Code-behind is a term used to describe the code that is joined with markup-defined objects, when a XAML page is markup-compiled. This topic describes requirements for code-behind as well as an alternative inline code mechanism for code in XAML.

How do we refer to WPF controls in code?

Controls in WPF are accessed by their names (and the Name property). We specify the Name property in the XAML, and then can access the control by that name directly in C# code. This allows controls to interact. Example.

Is XAML a code?

XAML is a new descriptive programming language developed by Microsoft to write user interfaces for next-generation managed applications. XAML is the language to build user interfaces for Windows and Mobile applications that use Windows Presentation Foundation (WPF), UWP, and Xamarin Forms.


1 Answers

Use x:Name instead of Name. That should do the trick.

like image 113
Paweł Motyl Avatar answered Oct 02 '22 14:10

Paweł Motyl