Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I've recently started learning WPF on my own. What is difference when declaring Name vs. x:Name?

Tags:

c#

wpf

For instance, I have this code:

<Grid>
    <Rectangle Name="TheRectangle" Fill="AliceBlue" Height="100" Width="100">            
    </Rectangle>
</Grid>

VS.

<Grid>
    <Rectangle x:Name="TheRectangle" Fill="AliceBlue" Height="100" Width="100">            
    </Rectangle>
</Grid>

Thank you very much for the information. I'm very excited about learning something new like this. :D

like image 252
Sergio Tapia Avatar asked Nov 11 '09 23:11

Sergio Tapia


1 Answers

wpfwiki

There is basically no difference between the two.

The "x:Name" expression is used in XAML to assign a name to an object that will be used to access the object from the code-behind.

Many classes of the framework expose a Name property, which does exactly this. For these classes, both x:Name and the Name property can be used interchangeably.

like image 67
serge_gubenko Avatar answered Sep 20 '22 12:09

serge_gubenko