zoukankan      html  css  js  c++  java
  • wpf中的触发器

    StyleControlTemplateDataTemplate 都具有 Triggers 属性,该属性可以包含一组触发器。某个属性值更改时,或某个事件引发时,触发器会相应地设置属性或启动操作(如动画操作)。

    这里说一个简单属性触发器

    在window中添加一个listbox
     <ListBox Name="l1" >
                <ListBoxItem>1111</ListBoxItem>
                <ListBoxItem>2222</ListBoxItem>
                <ListBoxItem>3333</ListBoxItem>
                <ListBoxItem>4444</ListBoxItem>
            </ListBox>

    然后在Window.Resources中添加一个触发器。触发器也是在样式中定义的
    刚开始listbox中各个项目透明度为01.选择用户透明度为1.0
    <Style TargetType="ListBoxItem">
                <Setter Property="Opacity" Value="0.1" />
                <Setter Property="MaxHeight" Value="75" />
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Opacity" Value="1.0" />
                    </Trigger>
                </Style.Triggers>
            </Style>
    下面说说事件触发器
    EventTrigger 和 Storyboard

    它根据事件的引发来启动一组操作。下面的 EventTrigger 对象指定当鼠标指针进入 ListBoxItem 时,MaxHeight 属性在 0.2 秒时间内以动画方式增大为值 90。当鼠标离开该项时,该属性在 1 秒时间内还原为原始值

    <EventTrigger RoutedEvent="Mouse.MouseEnter"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="MaxHeight" To="90" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseLeave"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <DoubleAnimation Duration="0:0:1" Storyboard.TargetProperty="MaxHeight" /> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger>

    本文使用Blog_Backup未注册版本导出,请到soft.pt42.com注册。

  • 相关阅读:
    (原创)神舟笔记本bios设置——神船战神ZX7-CP7S2 <一>
    Kali笔记<三> 安装中文输入法
    (原创)Kali笔记<二>root权限的使用和启用
    (原创)Kali笔记<一>虚拟机安装Kali
    加快vmware虚拟机运行速度的方法(大牛勿笑)
    PR/AE/PS 素材模板网站
    批量查杀该死的VBscript “svchost.exe” 脚本挂马
    echarts统计图Y轴(或X轴)文字过长问题解决
    正则实例
    Angular.js的自定义功能
  • 原文地址:https://www.cnblogs.com/zjypp/p/2319385.html
Copyright © 2011-2022 走看看