随笔分类 -  WPF

摘要:如果不用VS的WPF项目模板,如何手工创建一个WPF程序呢?我们来模仿WPF模板,创建一个最简单的WPF程序。第一步:文件——新建——项目——空项目,创建一个空项目。第二步:添加引用,PresentationFramework,PresentationCore,WindowsBase,System,System.Xaml,这几个是WPF的核心dll。第三步:在项目上右键添加新建项,添加两个“xml文件”,分别命名为App.xaml和MainWindow.xaml。可以看出,xaml文件其实就是xml文件。 第四步:同第二步,添加两个代码文件,即空白c#代码文件,分别命名为App.xaml.c. 阅读全文
posted @ 2014-03-11 10:23 小p 阅读(4570) 评论(0) 推荐(0)
摘要:1.使用路由事件 路由事件是一种可以针对元素树中的多个侦听器(而不是仅针对引发该事件的对象)调用处理程序的事件。通俗地说,路由事件会在可视树(逻辑树是其子集)上,上下routed,如果哪个节点上订阅了事件,就会被触发。 路由事件的规则有三种: (1)冒泡;由事件源向上沿视觉树传递一直到根元素。如 MouseDown (2)直接;只有事件源才有机会响应事件,某个元素引发事件后,不传递到其他元素 (3)隧道;从元素树的根部调用事件处理程序并依次向下深入直到事件源。 一般情况下,WPF提供的输入事件都是以隧道/冒泡对实现的。隧道事件常常被称为Preview事件。如 PreviewMouse... 阅读全文
posted @ 2013-09-07 13:09 小p 阅读(568) 评论(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 阅读(353) 评论(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 阅读(418) 评论(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 阅读(538) 评论(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 阅读(415) 评论(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 阅读(585) 评论(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 阅读(331) 评论(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 阅读(496) 评论(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 阅读(760) 评论(0) 推荐(0)