摘要: 1.使用路由事件 路由事件是一种可以针对元素树中的多个侦听器(而不是仅针对引发该事件的对象)调用处理程序的事件。通俗地说,路由事件会在可视树(逻辑树是其子集)上,上下routed,如果哪个节点上订阅了事件,就会被触发。 路由事件的规则有三种: (1)冒泡;由事件源向上沿视觉树传递一直到根元素。如 MouseDown (2)直接;只有事件源才有机会响应事件,某个元素引发事件后,不传递到其他元素 (3)隧道;从元素树的根部调用事件处理程序并依次向下深入直到事件源。 一般情况下,WPF提供的输入事件都是以隧道/冒泡对实现的。隧道事件常常被称为Preview事件。如 PreviewMouse... 阅读全文
posted @ 2013-09-07 13:09 小p 阅读(559) 评论(0) 推荐(0) 编辑
摘要: 1.依赖属性的效果 一旦规定视觉树上一个对象的fontsize属性,那么属于他的节点之下的所有对象都会沿袭这个属性,然而如果某个子节点明确的设定了自己的fontsize,就不会沿袭父节点的fontsize属性。fontsize这个属性是在Contorl中定义的,它具有默认值,默认的值优先级最低,从父节点上沿袭来的fontsize优先级比默认高,而直接对对象本身进行设置的优先级最高。类似fontsize属性的这类属性就是依赖属性2.依赖属性的实现using System;using System.Text;using System.Windows;using System.Windows... 阅读全文
posted @ 2013-09-01 18:47 小p 阅读(340) 评论(0) 推荐(0) 编辑
摘要: 1.Canvas面板using System;using System.Windows;using System.Windows.Controls;using System.Windows.Media;using System.Windows.Input;using System.Windows.Shapes;namespace LY.PaintTheButton{ public class PaintTheButton:Window { [STAThread] public static void Main() { ... 阅读全文
posted @ 2013-08-26 19:24 小p 阅读(408) 评论(0) 推荐(0) 编辑
摘要: 1.DockPanel面板using System;using System.Windows;using System.Windows.Controls;using System.Windows.Input;using System.Windows.Media;namespace LY.DockAroundTheBlock{ class DockAroundTheBlock:Window { [STAThread] public static void Main() { new Application().Run(ne... 阅读全文
posted @ 2013-08-25 20:52 小p 阅读(500) 评论(0) 推荐(0) 编辑
摘要: 1.StackPanel面板using System;using System.Windows;using System.Windows.Input;using System.Windows.Media;using System.Windows.Controls;namespace LY.StactTheButtons{ public class StackTheButton:Window { [STAThread] public static void Main() { new Application().Run(n... 阅读全文
posted @ 2013-08-24 22:36 小p 阅读(397) 评论(0) 推荐(0) 编辑
摘要: 1.Button类using System;using System.Windows;using System.Windows.Media;using System.Windows.Input;using System.Windows.Controls;namespace LY.ClickTheButton{ public class ClickTheButton:Window { [STAThread] public static void Main() { Application app = new Applica... 阅读全文
posted @ 2013-08-19 00:35 小p 阅读(573) 评论(1) 推荐(0) 编辑
摘要: 1.Content属性及字体相关的属性using System;using System.Windows;using System.Windows.Media;namespace LY.DisplaySomeText{ public class DisplaySomeText:Window { Brush brush = new LinearGradientBrush(Colors.Black, Colors.White, new Point(0, 0), new Point(1, 1)); [STAThread] public stati... 阅读全文
posted @ 2013-08-18 14:46 小p 阅读(320) 评论(1) 推荐(0) 编辑
摘要: 1.Color结构using System;using System.Windows;using System.Windows.Input;using System.Windows.Media;namespace LY.VaryTheBackGround{ public class VaryTheBackGround : Window { SolidColorBrush brush = new SolidColorBrush(Colors.Beige); [STAThread] public static void Main() ... 阅读全文
posted @ 2013-08-17 00:06 小p 阅读(488) 评论(1) 推荐(0) 编辑
摘要: 1.空白WPF项目的创建: 1)新建项目:在VS2010中,文件-新建-项目-visual c#-windows-空项目; 2)添加引用:PresentationFramework,PresentationCore,WindowsBase,System,System.Xaml,共5个。书中是4个,这是因为早期WindowsBase中的一些类后来放到了System.Xaml里。 3)添加文件:在项目中添加“新建项”,选择“代码文件"。2.SayHello程序 using System;using System.Windows;namespace LY.SayHello{ class . 阅读全文
posted @ 2013-08-13 00:28 小p 阅读(738) 评论(0) 推荐(0) 编辑