1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| public class ImageButton:Button { static ImageButton() { DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageButton), new FrameworkPropertyMetadata(typeof(ImageButton))); } ///ImageSize NormalImage HowerImage PressedImage BorderVisiblity ///
public double ImageSize { get { return (double)GetValue(ImageSizeProperty); } set { SetValue(ImageSizeProperty, value); } }
// Using a DependencyProperty as the backing store for ImageSize. This enables animation, styling, binding, etc... public static readonly DependencyProperty ImageSizeProperty = DependencyProperty.Register("ImageSize", typeof(double), typeof(ImageButton), new FrameworkPropertyMetadata(30.0,FrameworkPropertyMetadataOptions.AffectsRender));
public string NormalImage { get { return (string)GetValue(NormalImageProperty); } set { SetValue(NormalImageProperty, value); } }
// Using a DependencyProperty as the backing store for NormalImage. This enables animation, styling, binding, etc... public static readonly DependencyProperty NormalImageProperty = DependencyProperty.Register("NormalImage", typeof(string), typeof(ImageButton), new FrameworkPropertyMetadata("",FrameworkPropertyMetadataOptions.AffectsRender,ImageSourceChanged));
public string HoverImage { get { return (string)GetValue(HoverImageProperty); } set { SetValue(HoverImageProperty, value); } }
public static readonly DependencyProperty HoverImageProperty = DependencyProperty.Register("HoverImage", typeof(string), typeof(ImageButton), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender, ImageSourceChanged));
public string PressedImage { get { return (string)GetValue(PressedImageProperty); } set { SetValue(PressedImageProperty, value); } }
// Using a DependencyProperty as the backing store for PressedImage. This enables animation, styling, binding, etc... public static readonly DependencyProperty PressedImageProperty = DependencyProperty.Register("PressedImage", typeof(string), typeof(ImageButton), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender, ImageSourceChanged));
public string DisabledImage { get { return (string)GetValue(DisabledImageProperty); } set { SetValue(DisabledImageProperty, value); } }
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... public static readonly DependencyProperty DisabledImageProperty = DependencyProperty.Register("DisabledImage", typeof(string), typeof(ImageButton), new FrameworkPropertyMetadata("",FrameworkPropertyMetadataOptions.AffectsRender,ImageSourceChanged));
public Visibility BorderVisibility { get { return (Visibility)GetValue(BorderVisibilityProperty); } set { SetValue(BorderVisibilityProperty, value); } }
// Using a DependencyProperty as the backing store for BorderVisibility. This enables animation, styling, binding, etc... public static readonly DependencyProperty BorderVisibilityProperty = DependencyProperty.Register("BorderVisibility", typeof(Visibility), typeof(ImageButton), new FrameworkPropertyMetadata(Visibility.Hidden,FrameworkPropertyMetadataOptions.AffectsRender));
private static void ImageSourceChanged(DependencyObject Object, DependencyPropertyChangedEventArgs e) { Application.GetResourceStream(new Uri("pack://application:,,,"+(string)e.NewValue)); } }
|