Xaml技术:浅析为什么说一个标签就是new一个对象?
在Xaml技术中,如WPF、Silverlight等,一个标签就是一个对象。很多人不理解为什么,现在我们就来一起研究一下吧!
首先,我们新建一个WPF应用程序,并在窗口中添加一个按钮:
<Window x:Class="WpfApplication1.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="MainWindow" Height="350" Width="525"><Grid><span style="color:#ff0000;"><strong><Button Name="btnHaHa" Content="哈哈" Foreground="Red" Margin="118,64,127,141"></Button></strong></span></Grid>
</Window>
调试运行后,打开文件夹...\WpfApplication1\obj\x86\Debug,我们会发现MainWindow.g.cs和MainWindow.g.i.cs两个文件,这是干什么的呢?我们打开看看:
#################################<strong><span style="color:#ff0000;">MainWindow.g.cs</span></strong>#############################################
#pragma checksum "..\..\..\MainWindow.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "93AC7AD7A7AD9977990F9BD74B70C70D"
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.18444
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;namespace WpfApplication1 {/// <summary>/// MainWindow/// </summary>public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector {#line 6 "..\..\..\MainWindow.xaml"[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]<span style="color:#ff0000;"><strong>internal System.Windows.Controls.Button btnHaHa;</strong></span>#line default#line hiddenprivate bool _contentLoaded;/// <summary>/// InitializeComponent/// </summary>[System.Diagnostics.DebuggerNonUserCodeAttribute()][System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]public void <span style="color:#000066;"><strong>InitializeComponent</strong></span>() {if (_contentLoaded) {return;}_contentLoaded = true;System.Uri resourceLocater = new System.Uri("/WpfApplication1;component/mainwindow.xaml", System.UriKind.Relative);#line 1 "..\..\..\MainWindow.xaml"System.Windows.Application.LoadComponent(this, resourceLocater);#line default#line hidden}[System.Diagnostics.DebuggerNonUserCodeAttribute()][System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")][System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)][System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")][System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")][System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {switch (connectionId){case 1:<span style="color:#ff0000;background-color: rgb(255, 255, 255);"><strong>this.btnHaHa = ((System.Windows.Controls.Button)(target));</strong></span>return;}this._contentLoaded = true;}}
}
<pre name="code" class="csharp">#################################<strong><span style="color: rgb(255, 0, 0);">MainWindow.g.i.cs</span></strong>#############################################
#pragma checksum "..\..\..\MainWindow.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "93AC7AD7A7AD9977990F9BD74B70C70D"
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.18444
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;namespace WpfApplication1 {/// <summary>/// MainWindow/// </summary>public partial class MainWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector {#line 6 "..\..\..\MainWindow.xaml"[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]<strong><span style="color:#ff0000;">internal System.Windows.Controls.Button btnHaHa;</span></strong>#line default#line hiddenprivate bool _contentLoaded;/// <summary>/// InitializeComponent/// </summary>[System.Diagnostics.DebuggerNonUserCodeAttribute()][System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]public void <span style="color:#000066;"><strong>InitializeComponent</strong></span>() {if (_contentLoaded) {return;}_contentLoaded = true;System.Uri resourceLocater = new System.Uri("/WpfApplication1;component/mainwindow.xaml", System.UriKind.Relative);#line 1 "..\..\..\MainWindow.xaml"System.Windows.Application.LoadComponent(this, resourceLocater);#line default#line hidden}[System.Diagnostics.DebuggerNonUserCodeAttribute()][System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")][System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)][System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")][System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")][System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {switch (connectionId){case 1:<strong><span style="color:#ff0000;">this.btnHaHa = ((System.Windows.Controls.Button)(target));</span></strong>return;}this._contentLoaded = true;}}
}
我们看到了什么?是不是很熟悉了,是不是和Winform中的窗体设计文件很类似呀!
注意:添加的控件需要唯一ID,也就是Name属性,否则在这两个文件中将找不到该对象的定义与初始化
Xaml技术:浅析为什么说一个标签就是new一个对象?相关推荐
- 基础网络爬虫(Web crawler)相关技术浅析
文章目录 前言 基本概念 Robots协议 基本原理 现状概况 爬虫软件 跨语言 Selenium Python urllib requests Scrapy Pyspider Java WebMag ...
- (转)完美画质 3D游戏反锯齿技术浅析 .
完美的画面已经离我们不再遥远--反锯齿技术浅析 不管现今的游戏画面有多完美,人物和环境有多真实,但游戏画面的构成的主要方式仍然没有得到改善:一帧画面由成千上万像素构成.这意味着物体多边形的轮廓最终是锯 ...
- [html] 写一个标签云的布局
[html] 写一个标签云的布局 <ul class="tag-cloud"><li>JavaScript</li><li>技术&l ...
- 界面上下固定_【技术浅析】三通道机床自动上下料控制方法应用
摘要:当前制造业竞争日益激烈,产品性价比与产能限制为许多中小企业提供了生存空间,也是大型企业抢夺市场份额的终极利器.现介绍一种三通道机床自动上下料控制方法,即一个数控系统控制两个加工通道异步加工,并且 ...
- 谨赠20篇技术热文营造一个不一样的节日气氛!
一年一度的圣诞节又来临了.在这个越来越受到国人重视的节日中,每个人有每个人的浪漫方式,作为程序员.架构师和软件运维人员来说,也不例外.但是,我们表达节日快乐的方式与众不同,一切都在干货分享中,20篇技 ...
- 浅析计算机网络技术相关论文,计算机网络技术浅析论文 - 经典论文
<计算机网络技术浅析论文 - 经典论文>由会员分享,可在线阅读,更多相关<计算机网络技术浅析论文 - 经典论文(2页珍藏版)>请在人人文库网上搜索. 1.计算机网络技术浅析论文 ...
- PrestaShop - 技术百科 - PrestaShop是一个100%免费的外贸跨境电子商务购物车平台,中文支持非常友好且面向国际化
PrestaShop – 技术百科 – PrestaShop是一个100%免费的外贸跨境电子商务购物车平台,中文支持非常友好且面向国际化 PrestaShop PrestaShop是一个100%免费的 ...
- 特征级融合_自动驾驶多传感器融合技术浅析
文章转自公众号:计算机视觉之路 原文链接: 头条 | 自动驾驶多传感器融合技术浅析mp.weixin.qq.com 自动驾驶车上使用了多种多样的传感器,不同类型的传感器间在功用上互相补充,提高自动驾 ...
- 机器人离线编程画圆误差解决方案_机器人离线编程技术浅析及未来展望
龙源期刊网 http://www.qikan.com.cn 机器人离线编程技术浅析及未来展望 作者:刘梓航 来源:<中国校外教育 ( 下旬 ) > 2018 年第 01 期 [摘要]编程技 ...
- java 声音技术浅析
java 声音技术浅析 java 的魅力之一就是对多媒体的支持,Appley使得原来沉闷的网页变得 丰富起来,在java.applet中提供了很多功能强大的方法对多媒体的支 持.现在我们就java中的 ...
最新文章
- Ubuntu升级后apache所有的失败,以解决虚拟文件夹的设置
- mysql5.7单机多实例_Mysql 5.7.21单机多实例安装
- 3、excel数据格式设置快捷键
- Dubbo自定义日志拦截器
- [链接]开方检验原理
- Vue.js CLI4 Vue.config.js标准配置 (最全注释)
- 首次 统一调度系统规模化落地,全面支撑阿里巴巴双 11 全业务
- MySQL免安装版安装
- Nginx安装手册,反向代理,负载均衡,keepalived高可用
- 读书笔记:《知道做到》
- 2019.1.18作业 继承
- MyEclipse部署,将一个项目引入到两个项目;多项目部署
- PDMS中如何设置颜色规则
- 韩顺平html设计手册,韩顺平WEB前端网页设计视频教程
- 《创新者的窘境》读书笔记
- nexus3.x批量上传jar包
- wiki admin.php,dokuwiki 重置管理员密码
- VBA--类模块学习
- 【行车路径规划】百度地图API,行车路径规划 起始点+途经点
- JNDI全攻略(一)