网站推广优化教程,网站备案怎么查,邢台是不是又封了,如何生成一个网站触发器是指当满足预设的条件时去执行一些事务的工具#xff0c;比如我们希望鼠标移到某个按钮上方时#xff0c;这个按钮的颜色、大小发生一些改变。这个时候#xff0c;条件是鼠标移到按钮上#xff0c;执行的事务是改变按钮的颜色和大小。
触发器种类 触发器主要运用的场…触发器是指当满足预设的条件时去执行一些事务的工具比如我们希望鼠标移到某个按钮上方时这个按钮的颜色、大小发生一些改变。这个时候条件是鼠标移到按钮上执行的事务是改变按钮的颜色和大小。
触发器种类 触发器主要运用的场景在Style、ControlTemplate、DataTemplate三个地方。
style中
Window.ResourcesStyle x:KeyGreenButtonStyle TargetTypeButtonSetter PropertyWidth Value100/Setter PropertyHeight Value30/Setter PropertyBackground ValueGreen/Setter PropertyForeground ValueWhite/Setter PropertyMargin Value3/Style.TriggersTrigger PropertyIsMouseOver ValueTrueSetter PropertyForeground ValueRed/Setter PropertyWidth Value150/Setter PropertyHeight Value50/Setter PropertyContent Value鼠标移入//Trigger /Style.Triggers/Style/Window.ResourcesStackPanel VerticalAlignmentCenterButton Content按钮 Style{StaticResource GreenButtonStyle}//StackPanel
这种情况下改变不了background的值的。要想改变background需要利用模版重写
ControlTemplate中
实例如下
步骤1创建用户字典ButtonStyle.xaml,放在Style文件夹下
ResourceDictionary xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlStyle TargetTypeButton x:KeyButtonTemplate Setter PropertyWidth Value100/SetterSetter PropertyHeight Value30/SetterSetter PropertyBackground ValueBlue/SetterSetter PropertyForeground ValueWhite/SetterSetter PropertyTemplateSetter.ValueControlTemplate TargetTypeButtonBorder Background{TemplateBinding Background}ContentPresenter HorizontalAlignmentCenterVerticalAlignmentCenter/ContentPresenter/BorderControlTemplate.TriggersTrigger PropertyIsMouseOver ValueTrueSetter PropertyBackground Value#409eff//Trigger/ControlTemplate.Triggers/ControlTemplate/Setter.Value/Setter/Style/ResourceDictionary
步骤2在app.xaml中引入全局可用 Application.ResourcesResourceDictionaryResourceDictionary.MergedDictionariesResourceDictionary SourceStyle/ButtonStyle.xaml/ResourceDictionary/ResourceDictionary.MergedDictionaries/ResourceDictionary/Application.Resources
步骤3在任意view中使用 Button Content模版按钮 Style{StaticResource ButtonTemplate }/Button 结果如下 Background{TemplateBinding Background}实现了将Background绑定ControlTemplate 重写了Button。