【问题标题】:WPF - Button click on selection within a limited time interval?WPF - 在有限的时间间隔内单击选择按钮?
【发布时间】:2011-06-19 18:52:53
【问题描述】:

我有按钮网格。我想在没有任何按键或鼠标事件的情况下单击一个按钮(调用单击事件)。只希望在有限的时间间隔(3 秒)内自动单击它。

【问题讨论】:

    标签: c# wpf events button wpf-controls


    【解决方案1】:

    您可以使用 WPF 中的自动化界面以编程方式单击按钮。当然,如果您使用命令而不是处理点击事件(强烈推荐),那么您可以调用命令。

    这是使用来自Josh Smith's blog 的自动化单击按钮的代码。

    var peer = new ButtonAutomationPeer(someButton);
    var invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
    
    invokeProv.Invoke();
    

    【讨论】:

    • 成功了:)。如何设置选择时间限制?有什么on selection活动吗?
    【解决方案2】:

    您可以使用 Timer 并在 Elapsed 事件中调用您喜欢的任何内容?

    // Create a timer with a three second interval.
    myTimer = new System.Timers.Timer(3000);
    myTimer.Elapsed += new ElapsedEventHandler(YourEventHere);
    myTimer.Enabled = true;
    

    【讨论】:

      猜你喜欢
      • 2014-09-02
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 2015-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多