码迷,mamicode.com
首页 > 其他好文 > 详细

x:Class, x:Key

时间:2014-07-16 16:06:36      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:style   color   strong   art   re   c   

x:Class:

用来创建一个partial的class, 比如默认生成的x:Class="MyTest.MainWindow", 会自动生成一个MainWindow的partial class,同时在project自动创建的MainWindow.cs partial class构造函数中,会调用一个InitializeComponent() (定义在x:Class自动生成的MainWindow.g.i.cs中)。

如果注释掉InitializeComponent(), 同时把x:Class改成如MyTest.MainWindowABC, 则会生成MainWindowABC.g.i.cs,整个程序可以正常运行。查看IL,会发现有两个class, MainWindow,MainWindowABC

 

x:Key:

对于resource比如

<Window.Resources>
<local:Human x:Key="human" Name="Tester1" Child="ChildOfTester1"/>  同时,Human必须要有一个可以访问的无参构造函数,否则会报错
</Window.Resources>

x:Key必须要指定

x:Class, x:Key,布布扣,bubuko.com

x:Class, x:Key

标签:style   color   strong   art   re   c   

原文地址:http://www.cnblogs.com/bdbw2012/p/3848542.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!