分类目录归档:WPF

反射实现 WPF 按钮的  PerformClick 

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();
        }
    }
}

WPF对某个元素进行淡入淡出

例如对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);