开发者

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

开发者 https://www.devze.com 2022-12-10 23:58 出处:网络
For instance, I have this code: <Grid> <Rectangle Name=\"TheRectangle\" Fill=\"AliceBlue\" Height=\"100\" Width=\"100\">

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>
</Gr开发者_C百科id>

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


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.


You will have a response here

Basically, x:Name is used by WPF to be accessed in Runtime and by XAML to generate fields in the code behind.

0

精彩评论

暂无评论...
验证码 换一张
取 消