博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2011年5月6日

摘要: 控件模版ControlTemplate就是设置控件的外观,比如我们常见到的按钮是下面这样的,但是我们如何改变成圆形的呢?view sourceprint?01<Window x:Class="DeepXAML.MainWindow"02xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"03xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"04xmlns:local="clr-name 阅读全文

posted @ 2011-05-06 23:24 linFen 阅读(621) 评论(0) 推荐(1) 编辑

摘要: WPF模版主要分为俩大类:ControlTemplate: 控件的外观,也就是控件是什么样子DataTemplate: 是数据内容的表现,一条数据显示成什么样子1. 数据模版常用的地方有以下几处:ContentControl的ContentTemplate属性。ItemsControl的ItemTemplate属性。GridViewColumn的CellTemplate属性。 2. 示例ItemsControlContentControl3. DataTemplate除了可以作用在控件上,也可以作用再数据类型上view sourceprint?01<Window x:Class=&quo 阅读全文

posted @ 2011-05-06 23:22 linFen 阅读(5555) 评论(0) 推荐(1) 编辑

摘要: 在WPF中资源通常用作“样式”(Style)、样式模板、数据模板等。一、资源的定义及使用1. 应用程序级资源:定义在App.xaml文件中,作为整个应用程序共享的资源view sourceprint?1<Application x:Class="DeepXAML.App"2xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"3xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"4StartupUr 阅读全文

posted @ 2011-05-06 23:18 linFen 阅读(1845) 评论(1) 推荐(0) 编辑

摘要: 1. 样式中的Setter使用示例:view sourceprint?01<Window x:Class="DeepXAML.MainWindow"02xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"03xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"04xmlns:local="clr-namespace:DeepXAML"05xmlns:sys="clr- 阅读全文

posted @ 2011-05-06 23:15 linFen 阅读(1975) 评论(0) 推荐(1) 编辑

摘要: 一、WPF为何需要命令我们已经知道WPF里已经有了路由事件,可以发布及传播一些消息,那为什么还需要命令呢?这是因为事件指负责发送消息,对消息如何处理则不管,而命令是有约束力,每个接收者对命令执行统一的行为,比如菜单上的保存,工具栏上的保存都必须是执行同样的保存。二、命令系统的基本元素命令(Command):实现了ICommand接口的类,经常使用的有RoutedCommand类命令源: 是命令的发送者,是实现了ICommandSource接口的类,大部分界面的控件都实现了这个接口,Button, MenuItem 等等。命令目标:命令的接收者,命令目标是视线了IInputElement接口的类 阅读全文

posted @ 2011-05-06 23:13 linFen 阅读(7779) 评论(4) 推荐(1) 编辑

摘要: 逻辑树<Window> <Grid> <Button> <StackPanel> <Image/> <TextBlock/> </StackPanel> </Button> </Grid></Window>但是实际上这些元素在运行时会扩展为可是树事件路由 对逻辑树和可视树有所了解很有必要,因为路由事件主要是根据可视树进行路由。路由事件支持三种路由策略:气泡、隧道和直接。 气泡事件最为常见,它表示事件从源元素扩散(传播)到可视树,直到它被处理或到达根元素。这样您就可以针对源元素 阅读全文

posted @ 2011-05-06 23:09 linFen 阅读(2395) 评论(0) 推荐(0) 编辑

摘要: 一、依赖属性依赖属性就是自己自己没有值,通过Binding从数据源获得值,就是依赖在别人身上,拥有依赖属性的对象称为依赖对象。几种应用依赖属性的场景: 1. 希望可在样式中设置属性。 2. 希望属性支持数据绑定。 3. 希望可使用动态资源引用设置属性。 4. 希望从元素树中的父元素自动继承属性值。 5. 希望属性可进行动画处理。 6. 希望属性系统在属性系统、环境或用户执行的操作或者读取并使用样式更改了属性以前的值时报告。 7. 希望使用已建立的、WPF 进程也使用的元数据约定,例如报告更改属性值时是否要求布局系统重新编写元素的可视化对象。 依赖对象创建时并不包含存储数据空间。WPF中必须使用 阅读全文

posted @ 2011-05-06 23:05 linFen 阅读(13997) 评论(5) 推荐(1) 编辑

摘要: 有时我们展现的数据,需要进行转换,比如如果一个学生的成绩过了60,我们显示一个Pass的图片。XAML:view sourceprint?01<Window x:Class="DeepXAML.MainWindow"02xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"03xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"04xmlns:local="clr-namespace:De 阅读全文

posted @ 2011-05-06 23:02 linFen 阅读(1221) 评论(0) 推荐(0) 编辑

摘要: 设置Binding的ValidationRules属性对Binding进行检验view sourceprint?1<StackPanel> 2<TextBox x:Name="txtAge" FontSize="30" Foreground="Red"></TextBox> 3<TextBlock x:Name="errorSummary" FontSize="30" Foreground="Red"></TextBloc 阅读全文

posted @ 2011-05-06 23:00 linFen 阅读(1234) 评论(0) 推荐(1) 编辑

摘要: 1. 绑定到其它元素view sourceprint?1<Grid> 2<StackPanel> 3<TextBox x:Name="textbox1" /> 4<Label Content="{Binding ElementName=textbox1, Path=Text}" /> 5</StackPanel> 6</Grid>2. 绑定到静态资源view sourceprint?1<Window.Resources> 2<ContentControl x:Key 阅读全文

posted @ 2011-05-06 22:57 linFen 阅读(3818) 评论(0) 推荐(1) 编辑

摘要: 绑定,就是把一个对象属性的值绑定在别的对象的属性上1. 默认绑定public class Company { public string Name { get; set; } } XAML代码view sourceprint?1<StackPanel x:Name="stackPanel"> 2<TextBox x:Name="txtName" Text="{Binding Path=Name}"></TextBox> 3<TextBox x:Name="txtName2" 阅读全文

posted @ 2011-05-06 22:53 linFen 阅读(38448) 评论(3) 推荐(4) 编辑

摘要: 一、 Grida. 单元格的宽度可以设置三类值绝对值:double数值加单位后缀比例值:double数值加一个星号*自动值: auto,高度将有内部的控件的高度和宽度决定。b. Grid可接受的宽度和高度的单位1in=96px1cm=(96/2.54)px1pt=(96/72) pxc. 示例view sourceprint?01<Window x:Class="DeepXAML.MainWindow"02xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"03xmlns 阅读全文

posted @ 2011-05-06 22:45 linFen 阅读(3871) 评论(0) 推荐(1) 编辑

摘要: 1. ContentControl族 他们都继承ContentControl,都是控件,内容属性的名称为Content,只能由单一元素充当起内容包含的控件有:ButtonBaseRepeatButtonCheckBoxComboBoxItemButtonContentControlLableFrameToggeButtonGridViewColumnHeaderGroupItemListBoxItemRadioButtonListViewItemNavigationWindowScrollViewerStatusBarItemToolTipUserControlWindowview sourc 阅读全文

posted @ 2011-05-06 22:43 linFen 阅读(5531) 评论(0) 推荐(2) 编辑

摘要: 1. WPF类控件的派生关系图,紫色的部分开始才算是进入WPF的框架里。2. WPF控件图WPF的UI控件主要有以下类型,ContentControl, HeaderedContentControl, ItemsControl, HeaderedItemsControl, Panel, Adorner(文字点缀元素), Flow Text(流式文本元素), TextBox, TextBlock, Shape. 阅读全文

posted @ 2011-05-06 22:40 linFen 阅读(958) 评论(0) 推荐(1) 编辑

摘要: 1. 使用标签的Attribute为对象属性赋值我们可以按上面的方式用字符串来赋值,但是比如上面的Fill其实Shape.Fill类型,那为什么我么可以赋Red呢?因为WPF使用TypeConverter进行了转换.2. 使用TypeConverter类将XAML的Attribute与对象的Property进行转换view sourceprint?1namespace DeepXAML 2{ 3[TypeConverter(typeof(StringToPersonConverter))] 4public class Person 5{ 6public string Name { get; s 阅读全文

posted @ 2011-05-06 22:39 linFen 阅读(1180) 评论(0) 推荐(1) 编辑

摘要: 这个命名空间存放的就是XAML和XAML编译器沟通的东西,比如编译时与那个C#代码合并等一、 在XAML中出现的方式有三种1.标签扩展: x:Array, x:Null, x:Static, x:Type2. XAML指令元素: x:Code, x:XData3. Attribute: x:Class, x:ClassModifier, x:FieldModifier, x:Key, x:Name, x: Shared, X:Subclass, x:TypeArguments, x:Uid.二、详解x:Class:告诉XAML编译器将XAML标签的编译结果与后台制定的类合并,这个类必须使用pa 阅读全文

posted @ 2011-05-06 22:35 linFen 阅读(4381) 评论(1) 推荐(3) 编辑