I recently started learning WPF myself. What is the difference when declaring a name against x: name?

For example, 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 am very happy to learn about something new .: D

+6
c # wpf
source share
2 answers

wpfwiki

In principle, there is no difference between the two.

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

Many structure classes expose a Name Property that exactly does this. For these classes, both are x: Name and you can use the Name property interchangeably.

+10
source share

You will have the answer here.

Basically, x: the name is used by WPF to access Runtime and XAML to generate fields in the code.

0
source share

All Articles