2.4属性元素

以下c#和xaml是一致的

Rectangle r = new Rectangle();
r.Width = 40;
r.Height = 40;
r.Fill = Brushes.Black;
button.Content = r;

<Button x:Name="button" HorizontalAlignment="Left" Height="120" Margin="81,61,0,0" VerticalAlignment="Top" Width="346" Click="button_Click">
<Button.Content>
<Rectangle Height="40" Width="40" Fill="red">
</Rectangle>
</Button.Content>
</Button>

2.6属性扩展

以下xaml

<Button x:Name="button" Click="button_Click" Background="{x:Null}" Height="{x:Static SystemParameters.IconHeight}" Content="{Binding Path=Height, RelativeSource={RelativeSource Self}}">

和c#等价

button.Background = null;
button.Height = SystemParameters.IconHeight;
System.Windows.Data.Binding binding = new Binding();
binding.Path = new PropertyPath("Height");
binding.RelativeSource = RelativeSource.Self;
button.SetBinding(Button.ContentProperty, binding);

content binding含义:显示在button上的字符串

2.7.2 集合项

<ListBox x:Name="listBox" >
<ListBox.Items>
<ListBoxItem Content="Item 1"></ListBoxItem>
<ListBoxItem Content="Item 2"></ListBoxItem>
</ListBox.Items>
</ListBox>

等价于

System.Windows.Controls.ListBoxItem li1 = new System.Windows.Controls.ListBoxItem();
li1.Content = "Item 1";
listBox.Items.Add(li1);

System.Windows.Controls.ListBoxItem li2 = new System.Windows.Controls.ListBoxItem();
li2.Content = "Item 2";
listBox.Items.Add(li2);

3.2逻辑树与可视树

代码

   public MainWindow()
{
InitializeComponent();
printLogicalTree(0, this); } private void button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("A");
} protected override void OnContentRendered(EventArgs e)
{
base.OnContentRendered(e);
printVisualTree(0, this);
}
void printLogicalTree(int depth, object obj)
{
Debug.WriteLine(new string(' ', depth) + obj);
if (!(obj is DependencyObject)) return;
foreach(object child in LogicalTreeHelper.GetChildren(obj as DependencyObject))
{
printLogicalTree(depth + 1, child);
}
} void printVisualTree(int depth, DependencyObject obj)
{
Debug.WriteLine(new string(' ', depth) + obj);
if (!(obj is DependencyObject)) return;
for(int i=0; i< VisualTreeHelper.GetChildrenCount(obj);i++)
{
printVisualTree(depth + 1, VisualTreeHelper.GetChild(obj,i));
}
}

  

输出

WpfApplication1.MainWindow
System.Windows.Controls.StackPanel
System.Windows.Controls.Label: eeeeeee
eeeeeee
System.Windows.Controls.Label: Label
Label
System.Windows.Controls.Label: Label
Label
System.Windows.Controls.ListBox Items.Count:0
System.Windows.Controls.StackPanel
System.Windows.Controls.Button: Button
Button
System.Windows.Controls.Button: Button
Button
System.Windows.Controls.Primitives.StatusBar Items.Count:1
xxx
“WpfApplication1.vshost.exe”(CLR v4.0.30319: WpfApplication1.vshost.exe): 已加载“C:\windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXmlLinq\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXmlLinq.dll”。已跳过加载符号。模块进行了优化,并且调试器选项“仅我的代码”已启用。
“WpfApplication1.vshost.exe”(CLR v4.0.30319: WpfApplication1.vshost.exe): 已加载“C:\windows\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXml\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXml.dll”。已跳过加载符号。模块进行了优化,并且调试器选项“仅我的代码”已启用。
“WpfApplication1.vshost.exe”(CLR v4.0.30319: WpfApplication1.vshost.exe): 已加载“C:\windows\Microsoft.Net\assembly\GAC_MSIL\PresentationCore.resources\v4.0_4.0.0.0_zh-Hans_31bf3856ad364e35\PresentationCore.resources.dll”。模块已生成,不包含符号。
“WpfApplication1.vshost.exe”(CLR v4.0.30319: WpfApplication1.vshost.exe): 已加载“C:\Users\cutepig\AppData\Local\Temp\VisualStudio.XamlDiagnostics.8476\WpfXamlDiagnosticsTap.dll”。已跳过加载符号。模块进行了优化,并且调试器选项“仅我的代码”已启用。
“WpfApplication1.vshost.exe”(CLR v4.0.30319: WpfApplication1.vshost.exe): 已加载“C:\windows\assembly\GAC\Microsoft.VisualStudio.OLE.Interop\7.1.40304.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.OLE.Interop.dll”。模块已生成,不包含符号。
“WpfApplication1.vshost.exe”(CLR v4.0.30319: WpfApplication1.vshost.exe): 已加载“C:\windows\Microsoft.Net\assembly\GAC_MSIL\UIAutomationTypes\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationTypes.dll”。已跳过加载符号。模块进行了优化,并且调试器选项“仅我的代码”已启用。
“WpfApplication1.vshost.exe”(CLR v4.0.30319: WpfApplication1.vshost.exe): 已加载“C:\windows\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll”。无法查找或打开 PDB 文件。
“WpfApplication1.vshost.exe”(CLR v4.0.30319: WpfApplication1.vshost.exe): 已加载“C:\windows\Microsoft.Net\assembly\GAC_MSIL\UIAutomationProvider\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationProvider.dll”。已跳过加载符号。模块进行了优化,并且调试器选项“仅我的代码”已启用。
WpfApplication1.MainWindow
System.Windows.Controls.Border
System.Windows.Documents.AdornerDecorator
System.Windows.Controls.ContentPresenter
System.Windows.Controls.StackPanel
System.Windows.Controls.Label: eeeeeee
System.Windows.Controls.Border
System.Windows.Controls.ContentPresenter
System.Windows.Controls.TextBlock
System.Windows.Controls.Label: Label
System.Windows.Controls.Border
System.Windows.Controls.ContentPresenter
System.Windows.Controls.TextBlock
System.Windows.Controls.Label: Label
System.Windows.Controls.Border
System.Windows.Controls.ContentPresenter
System.Windows.Controls.TextBlock
System.Windows.Controls.ListBox Items.Count:0
System.Windows.Controls.Border
System.Windows.Controls.ScrollViewer
System.Windows.Controls.Grid
System.Windows.Shapes.Rectangle
System.Windows.Controls.ScrollContentPresenter
System.Windows.Controls.ItemsPresenter
System.Windows.Controls.VirtualizingStackPanel
System.Windows.Documents.AdornerLayer
System.Windows.Controls.Primitives.ScrollBar 最小值:0 最大值:0 值:0
System.Windows.Controls.Primitives.ScrollBar 最小值:0 最大值:0 值:0
System.Windows.Controls.StackPanel
System.Windows.Controls.Button: Button
Microsoft.Windows.Themes.ButtonChrome
System.Windows.Controls.ContentPresenter
System.Windows.Controls.TextBlock
System.Windows.Controls.Button: Button
Microsoft.Windows.Themes.ButtonChrome
System.Windows.Controls.ContentPresenter
System.Windows.Controls.TextBlock
System.Windows.Controls.Primitives.StatusBar Items.Count:1
System.Windows.Controls.Border
System.Windows.Controls.ItemsPresenter
System.Windows.Controls.DockPanel
System.Windows.Controls.Primitives.StatusBarItem: xxx
System.Windows.Controls.Border
System.Windows.Controls.ContentPresenter
System.Windows.Controls.TextBlock
System.Windows.Documents.AdornerLayer
线程 0xb10 已退出,返回值为 0 (0x0)。

  

wpf揭秘的更多相关文章

  1. WPF,Silverlight与XAML读书笔记第四十八 - Silverlight网络与通讯

    说明:本系列基本上是<WPF揭秘>的读书笔记.在结构安排与文章内容上参照<WPF揭秘>的编排,对内容进行了总结并加入一些个人理解. 这一部分我们重点讨论下Silverlight ...

  2. WPF,Silverlight与XAML读书笔记第四十七 - Silverlight与浏览器

    说明:本系列基本上是<WPF揭秘>的读书笔记.在结构安排与文章内容上参照<WPF揭秘>的编排,对内容进行了总结并加入一些个人理解. 这部分内容主要介绍Silverlight与浏 ...

  3. WPF,Silverlight与XAML读书笔记第四十六 - 外观效果之三皮肤与主题

    说明:本系列基本上是<WPF揭秘>的读书笔记.在结构安排与文章内容上参照<WPF揭秘>的编排,对内容进行了总结并加入一些个人理解. 皮肤 皮肤是应用程序中样式与模板的集合,可以 ...

  4. WPF,Silverlight与XAML读书笔记第四十五 - 外观效果之模板

    说明:本系列基本上是<WPF揭秘>的读书笔记.在结构安排与文章内容上参照<WPF揭秘>的编排,对内容进行了总结并加入一些个人理解. 模板允许用任何东西完全替换一个元素的可视树, ...

  5. WPF,Silverlight与XAML读书笔记第四十四 - 外观效果之样式

    说明:本系列基本上是<WPF揭秘>的读书笔记.在结构安排与文章内容上参照<WPF揭秘>的编排,对内容进行了总结并加入一些个人理解. 如果你有Web编程的经验,你会知道使用Sty ...

  6. WPF,Silverlight与XAML读书笔记第四十三 - 多媒体支持之文本与文档

    说明:本系列基本上是<WPF揭秘>的读书笔记.在结构安排与文章内容上参照<WPF揭秘>的编排,对内容进行了总结并加入一些个人理解. Glyphs对象(WPF,Silverlig ...

  7. WPF Media 简单的播放器

    <Window x:Class="PlayTest.MediaControl" xmlns="http://schemas.microsoft.com/winfx/ ...

  8. WPF 各种基础动画实现

    C# using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syste ...

  9. WPF进阶之接口(2):IDisposable,ICollectionView

    废话不多说,进入正题,先来说说IDisposable,看例子(来自MSDN): using System; using System.ComponentModel; // 下面的例子将展示一个实施了I ...

随机推荐

  1. jquery转换json对象为字符串

    jquery转换json对象为字符串 JSON.stringify(jsonObject),可用于单个JSON对象,也可用于JSON数组 alert(JSON.stringify(jsonObject ...

  2. 1) 上传多张图片时 ,对 $_FILES 的处理. upload ; 2)fileinput 上传多张图片. 3) 修改,删除的时候删除原来的资源,图片 update, delete , 删除 4)生成器中两个字段上传图片的时候,要修改生成器生成的代码

    1上传多张图片, 要对 $_FILES进行 重新处理. //添加 public function addCourseAlbumAction() { $CourseAlbumModel = new Co ...

  3. Python基础1--Python的安装

    一.python的安装 Windows: 1) https://www.python.org/下载 2) 傻瓜式安装 3) 设置python环境变量 计算机-属性-高级系统设置-环境变量,将C:\Py ...

  4. xshell 评估过期

    手头拮据的朋友可以通过下面方法绕过: https://www.netsarang.com/download/down_form.html?code=522 删除XShell. 到英文官网下载页找到XS ...

  5. 3--Selenium环境准备--Eclipse 引入 selenium-server包

    1.下载selenium-server包   selenium-server-standalone包是Seleniumd的核心jar包,其中包含了各种元素定位和调用浏览器的方法.下载jar包后,在ID ...

  6. Maven安装Oracle驱动包到本地仓库

    驱动下载地址:https://download.csdn.net/download/yang_lover/9455401 mvn install:install-file -DgroupId=com. ...

  7. 微软Power BI报表服务器学习总览

    今天,微软宣布了8月更新Power BI Report Server!此版本包含一些新功能,包括一些备受期待的项目,如报表主题,条件格式改进和报表页面工具提示. 报告 报告主题 用于触发操作的按钮 组 ...

  8. 【转载】 看996ICU

    原文地址: https://www.jianshu.com/p/15d8726fa8a8 作者:Demisstif 来源:简书 ------------------------------------ ...

  9. ss-libev控制脚本

    适用于:shadowsocks-libev-3.0.3 操作系统:CentOS6.8 #!/bin/sh SHADOWSOCKS_SERVER="/usr/local/shadowsocks ...

  10. todolist待办事项

    使用html/css原生js实现待办事项列表: 支持添加待办事项,删除待办事项,切换待办事项的状态(正在进行,已经完成) 支持对正在进行以及已经完成事项编辑(单击内容即可编辑) 源代码:链接:http ...