网站设计字体大小,搜狗整站优化,微信小程序在哪里找?,开发一个软件需要多久触发器
触发器可以理解为#xff0c;当达到了触发的条件#xff0c;那么就执行预期内的响应#xff0c;可以是样式、数据变化、动画等。触发器通过Style.Triggers集合连接到样式中#xff0c;每个样式都可以有任意多个触发器#xff0c;并且每个触发器都是System.Windows…触发器
触发器可以理解为当达到了触发的条件那么就执行预期内的响应可以是样式、数据变化、动画等。触发器通过Style.Triggers集合连接到样式中每个样式都可以有任意多个触发器并且每个触发器都是System.Windows.TriggerBase的派生类实例以下是触发器的类型
Trigger监测依赖属性的变化、触发器生效MultiTrigger通过多个条件的设置、达到满足条件、触发器生效DataTrigger通过数据的变化、触发器生效MultiDataTrigger多个数据条件的触发器EventTrigger事件触发器触发了某类事件时触发器生效
属性触发器
Trigger监测依赖属性的变化、触发器生效
Window x:ClassEventLearn.UseStylexmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:EventLearnmc:IgnorabledTitleUseStyle Height450 Width800Window.ResourcesStyle x:KeyBaseStyle TargetTypeButtonSetter PropertyWidth Value100/Setter PropertyHeight Value40/Setter PropertyForeground ValueRed/Style.TriggersTrigger PropertyIsMouseOver ValueTrueSetter PropertyForeground ValueBlue/Setter PropertyFontSize Value20//TriggerTrigger PropertyIsMouseOver ValueFalseSetter PropertyForeground ValueRed/Setter PropertyFontSize Value15//Trigger /Style.Triggers/StyleStyle x:Keystyle1 TargetTypeButton BasedOn{StaticResource BaseStyle}Setter PropertyContent ValueHello//Style/Window.ResourcesGridStackPanelButton Style{StaticResource style1} /Button Style{StaticResource style1}/Button Style{StaticResource style1}//StackPanel/Grid
/Window
Trigger类定义的属性
Tirgger属性说明Property Value使用属性触发器Property和Value属性用于指定触发器的激活时间。例如Property “IsMouseOver” ,Value “True”Setters一旦激活触发器就可以使用Setters定义一个Setter元素集合来改变属性值。Setter类定义Property、TargetName和Value属性已修改对象属性。EnterActions ExitActions除了定义 settm之 外,还可以定义 EnterActions 和 ExitActions。使用这两个属性,可以定义一个TriggerAction元素集合。EnterActions在启动触发器时激活(此时通过属性触发器应用Property/Value组合。ExitActions在触发器结束之前激活此时不再应用Property/Value组合
多触发器
MultiTrigger通过多个条件的设置、达到满足条件、触发器生效
MultiTrigger有一个Conditions属性可以在其中设置属性的有效值。还有一个Setters属性可以在其中指定需要设置的属性
Windowx:ClassEventLearn.UseStylexmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:localclr-namespace:EventLearnxmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006TitleUseStyleWidth800Height450mc:IgnorabledWindow.ResourcesStyle x:KeyBaseStyle TargetTypeTextBoxSetter PropertyWidth Value100 /Setter PropertyHeight Value40 /Setter PropertyForeground ValueRed /Style.TriggersTrigger PropertyIsMouseOver ValueTrueSetter PropertyForeground ValueBlue /Setter PropertyFontSize Value20 //TriggerTrigger PropertyIsMouseOver ValueFalseSetter PropertyForeground ValueRed /Setter PropertyFontSize Value15 //TriggerMultiTriggerMultiTrigger.ConditionsCondition PropertyIsMouseOver Valuetrue/Condition PropertyIsFocused Valuetrue//MultiTrigger.ConditionsMultiTrigger.SettersSetter PropertyBackground ValuePink//MultiTrigger.Setters/MultiTrigger/Style.Triggers/StyleStyle x:Keystyle1 TargetType{x:Type TextBox} BasedOn{StaticResource BaseStyle}/Style/Window.ResourcesGridStackPanelTextBox Style{StaticResource style1} /TextBox Style{StaticResource style1} /TextBox Style{StaticResource style1} //StackPanel/Grid
/Window
数据触发器
DataTrigger通过数据的变化、触发器生效
Windowx:ClassEventLearn.UseStylexmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:localclr-namespace:EventLearnxmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006TitleUseStyleWidth800Height450mc:IgnorabledWindow.ResourcesStyle x:KeyBaseStyle TargetTypeTextBoxSetter PropertyWidth Value100 /Setter PropertyHeight Value40 /Setter PropertyForeground ValueRed /Style.TriggersTrigger PropertyIsMouseOver ValueTrueSetter PropertyForeground ValueBlue /Setter PropertyFontSize Value20 //TriggerTrigger PropertyIsMouseOver ValueFalseSetter PropertyForeground ValueRed /Setter PropertyFontSize Value15 //Trigger!-- 当在TextBox中写入123时背景颜色变绿 --DataTrigger Binding{Binding RelativeSource{RelativeSource ModeSelf}, PathText} Value123Setter PropertyBackground ValueSeaGreen //DataTrigger/Style.Triggers/StyleStylex:Keystyle1BasedOn{StaticResource BaseStyle}TargetType{x:Type TextBox} //Window.ResourcesGridStackPanelTextBox Style{StaticResource style1} /TextBox Style{StaticResource style1} /TextBox Style{StaticResource style1} //StackPanel/Grid
/Window
模板
控件的外观及其功能在WPF中是完全分离的。虽然按钮有默认的外观但可以用模板完全定制其外观。
WPF提供了几个模板类型它们派生自基类FrameworkTemplate。
模板类型说明ControlTemplate使用ControlTemplate可以指定控件的可视化结构重新设计其外观ItemsPanelTemplate对于ItemsControl可以赋予一个ItemsPanelTemplate以指定其项的布局。每个ItemsControl都有一个默认的ItemsPanelTemplate。MenuItem使用WrapPanelStatusBar使用DockPanelListBox使用VirtualizingStackPanel。DataTemplateDataTemplates非常适用于对象的图形表示。给列表框指定样式默认情况下列表框中的项根据ToString()方法的输出来显示。应用DataTemplate可以重写其操作定义项的自定义表示HierarchicalDataTemplateHierarchicalDataTemplate用于排列对象的树形结构。这个控件支持HierarchicalControls如TreeViewItem和MenuItem
ControlTemplate
控件模板用来定义控件的外观、样式还可通过控件模板的触发器ControlTemplate.Triggers修改控件的行为、响应动画等。
对于WPF当中每个控件都是无外观的这意味着我们可以完全自定义其可视化的外观但是不能修改其内部的行为因为空间的行为已经被固定在控件的具体类中。在Winform当中控件的外观与行为都被固定在空间的具体类中当我们想要修改按钮的边框弧度或者修改控件身一些细节的时候我们需要修改外观的同时把原来具备的所有行为重写一遍我们大多数称之为自定义控件。
ContentPresenter是控件内容的占位符并定义了放置这些内容的位置。ContentPresenter的Content属性定义了内容的外观。
DataTemplate
Windowx:ClassWpfApp1.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:localclr-namespace:WpfApp1xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006TitleMainWindowWidth800Height450mc:IgnorabledGridListBox ItemsSource{Binding ElementNamecom, PathItemsSource}ListBox.ItemTemplateDataTemplateStackPanel OrientationHorizontalTextBlock Text{Binding Name} /TextBlock Text--- /TextBlock Text{Binding Sex} //StackPanel/DataTemplate/ListBox.ItemTemplate/ListBoxComboBoxx:NamecomWidth100Height20ComboBox.ItemTemplateDataTemplateStackPanel OrientationHorizontalTextBlock Text{Binding Name} /TextBlock Text--- /TextBlock Text{Binding Sex} //StackPanel/DataTemplate/ComboBox.ItemTemplate/ComboBox/Grid
/Window