WPF ImageButton

最新版移步至:http://blog.csdn.net/oneonce/article/details/77001854


创建CustomControl

Generic.xaml



    

ImageButton.cs

public class ImageButton : Button
{
    static ImageButton()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageButton), new FrameworkPropertyMetadata(typeof(ImageButton)));
    }

    public ImageButton()
    {
    }

    #region Properties
 
    public static readonly DependencyProperty NormalImageProperty =
                        DependencyProperty.Register("NormalImage", typeof(ImageSource), typeof(ImageButton), new PropertyMetadata(null));
    public ImageSource NormalImage
    {
        get { return (ImageSource)GetValue(NormalImageProperty); }
        set { SetValue(NormalImageProperty, value); }
    }

    public static readonly DependencyProperty HoverImageProperty =
                        DependencyProperty.Register("HoverImage", typeof(ImageSource), typeof(ImageButton), new PropertyMetadata(null));
    public ImageSource HoverImage
    {
        get { return (ImageSource)GetValue(HoverImageProperty); }
        set { SetValue(HoverImageProperty, value); }
    }

    public static readonly DependencyProperty PressedImageProperty =
                        DependencyProperty.Register("PressedImage", typeof(ImageSource), typeof(ImageButton), new PropertyMetadata(null));
    public ImageSource PressedImage
    {
        get { return (ImageSource)GetValue(PressedImageProperty); }
        set { SetValue(PressedImageProperty, value); }
    }

    public static readonly DependencyProperty DisabledImageProperty =
                        DependencyProperty.Register("DisabledImage", typeof(ImageSource), typeof(ImageButton), new PropertyMetadata(null));
    public ImageSource DisabledImage
    {
        get { return (ImageSource)GetValue(DisabledImageProperty); }
        set { SetValue(DisabledImageProperty, value); }
    }

    #endregion
}

使用:



你可能感兴趣的:(WPF)