WPF知识总结

XAML:声明型语言,UI与逻辑的剥离,Code-Behind。WPF的核心理念是数据驱动UI。

x:Class x:ClassModifier x:Name x:FieldModifier x:Key x:Shared x:Type x:Null x:Array x:Static x:Code x:XData

(1)布局控件 Grid StackPanel DockPanel Canvas WrapPanel

(2)内容控件 Window Button

(3)带标题内容控件 Groupbox,TabItem

(4)条目控件 ListBox

(5)带标题条目控件 TreeViewItem MenuItem

(6)特殊内容控件 TextBox TextBlock Image

INotifyPropertyChanged UpdateSourceTrigger ValidationRule ValidatesOnTargetUpdated NotifyOnValidationError IValueConverter MultiBinding

BindingMode:TwoWay,OneWay,OneWayToSource,Default

为Binding指定Source的几种方法

(1) 把普通CLR类型单个对象指定为Source

(2)把普通CLR基类类型对象指定为Source

(3)把ADO.NET数据对象指定为Source

(4)使用XMLDataProvider把XML数据指定为Source

(5)把依赖对象(Dependency Object)指定为Source

(6)把容器的DataContext指定为Source

(7)通过ElementName指定Source

(8)通过Binding的RelativeSource属性相对地指定Source

(9)把ObjectDataProvider对象指定为Source

(10)把使用LINQ检索得到的数据对象作为Binding的源

DependencyObject:实时分配空间 这种能力依靠DependencyProperty实现

加载路由事件:AddHandler 查看事件VisualTree源头:e.OriginalSource 查看事件LogicalTree上的消息源头:e.Source 发送路由事件 button1.RaiseEvent(arg) 删除路由事件:RemoveHandler 自定义路由事件需要定义在自定义控件上

命令的几个基本要素:

(1)命令(Command) 实现了ICommand的类,平常用的最多的是RoutedCommand类。

(2)命令源(Command Source) 实现了ICommandSource接口的类,很多UI界面元素都实现了这个接口

(3)命令目标(Command Target) 即命令将发送给谁。命令目标必须是实现了IInputElement接口的类。

(4)命令关联(Command Binding)负责把一些外围逻辑与命令关联起来。 加载命令相关事件

命令的使用步骤:

(1)创建命令类:即获得一个实现ICommand接口的类

(2)声明命令实例:使用命令时需要创建命令类的实例。

(3)指定命令的源:this.button1.Command=cmdInstance;

(4)指定命令目标:this.button1.CommandTarget=this.textBoxA

(5)设置命令关联:this.stackPanel.CommandBindings.Add(cb)

CommandParameter:如果把命令看作是飞向目标的炮弹,那么CommandParameter相当于装载在炮弹肚子里的”消息“。 获取CommandParameter:e.Parameter

StaticResource:程序载入内存时对资源的一次性使用,之后就不再去访问这个资源了。

DynamicResource:指的是在程序运行过程中仍然会去访问资源。

WPF中的Template分为两大类:

(1)ControlTemplate:决定了控件长什么样子,并让程序员有机会在控制原有的内部逻辑基础上扩展自己的逻辑。

(2)DataTemplate:数据内容的表现形式,一条数据显示成什么样子,是简单的文本还是直观的图形动画就由它来决定。

DataTemplate常用的地方有3处,分别是:

(1)ContentControl的ContentTemplate属性。

(2)ItemsControl的ItemTemplate属性

(3)GridViewColumn的CellTemplate属性

ItemsControl具有一个名为ItemsPanel的属性,数据类型为ItemsPanelTemplate也是一种控件Template。

决定控件外观的是ControlTemplate,决定数据外观的是DataTemplate,他们正是Control类的Template和ContentTemplate两个属性的值。

<Style TargetType=""> <DataTemplate DataType="">

能够帮助层级控件显示层级数据的模板是HierarchicalDataTemplate。

 

 

转自:http://blog.csdn.net/xufei96/article/details/8480775

 

好多东西只是用过,还不明所以。。。。慢慢来吧~~唉,基础不好,没办法~~

ControlTemplate和DataTemplate两个类均派生自FrameworkTemplate类,这个类有个名为FindName的方法供我们检索其内部控件。

Style Setter Trigger MultiTrigger DataTrigger MultiDataTrigger

原文地址:https://www.cnblogs.com/gdx4430090/p/3259009.html