zoukankan      html  css  js  c++  java
  • WPF TriggerAction弹出子窗体 TargetedTrigger、TargetedTriggerAction用法

    namespace TriggerAction
    {
        public class OpenWindowAction : TriggerAction<DependencyObject>
        {
    
    
            public Type WindowType
            {
                get { return (Type)GetValue(WindowTypeProperty); }
                set { SetValue(WindowTypeProperty, value); }
            }
    
            public static readonly DependencyProperty WindowTypeProperty =
                DependencyProperty.Register("WindowType", typeof(Type), typeof(OpenWindowAction), new PropertyMetadata(null));
    
    
    
            protected override void Invoke(object parameter)
            {
               var windowObj=  Activator.CreateInstance(WindowType) as Window;
                windowObj.ShowDialog();
            }
        }
    
        public class ButtonAction : TriggerAction<Button>
        {
            protected override void Invoke(object parameter)
            {
                this.AssociatedObject.Content = DateTime.Now.ToString();
            }
        }
    
        public class ButtonTargetAction : TargetedTriggerAction<Button>
        {
            protected override void Invoke(object parameter)
            {
                this.Target.Content = this.Target.Content + "1";
            }
        }
    }
    <Window x:Class="TriggerAction.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
            xmlns:local="clr-namespace:TriggerAction"
            
            mc:Ignorable="d"
            Title="MainWindow" Height="450" Width="800">
        <Grid>
            <Button Content="Button" HorizontalAlignment="Left" Margin="531,122,0,0" VerticalAlignment="Top" Width="164" Height="46">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <local:OpenWindowAction WindowType="{x:Type local:Window1}" />
                        <local:ButtonAction />
                        <local:ButtonTargetAction TargetName="aaa" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <Button x:Name="aaa" Content="Button" HorizontalAlignment="Left" Margin="531,238,0,0" VerticalAlignment="Top" Width="103" Height="30"/>
    
        </Grid>
    </Window>
  • 相关阅读:
    再论使用Oracle Instant Client连接Oracle
    再谈业务逻辑架构模式(事务脚本,表模块,活动记录,领域模型)
    业务逻辑架构模式(事务脚本,表模块,活动记录,领域模型)
    .net程序集组成与内存布局
    多参的实现原理
    起点
    Windows1[头文件]
    C++中构造函数、析构函数、拷贝构造函数详解
    PHP 开发工具
    写点东西顺便吐槽(很弱很弱的技术文)
  • 原文地址:https://www.cnblogs.com/czly/p/10233837.html
Copyright © 2011-2022 走看看