FirstButton.RaiseEvent(new RoutedEventArgs(System.Windows.Controls.Button.ClickEvent));
WPF 手动触发按钮事件
发表评论
FirstButton.RaiseEvent(new RoutedEventArgs(System.Windows.Controls.Button.ClickEvent));
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls.Primitives;
namespace cmbc
{
static public class ButtonEx
{
public static void PerformClick(this ButtonBase button)
{
var method = button.GetType().GetMethod("OnClick",
BindingFlags.NonPublic | BindingFlags.Instance);
if (method != null)
{
method.Invoke(button, null);
}
//button.Focus();
}
}
}
例如对ImagePage元素进行淡入淡出
淡入
daV = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(1)));
this.ImagePage.BeginAnimation(UIElement.OpacityProperty, daV);
淡出
DoubleAnimation daV = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(1)));
this.ImagePage.BeginAnimation(UIElement.OpacityProperty, daV);