/// <summary> /// 改变按钮的类型 /// </summary> /// <param name="d"></param> /// <param name="e"></param> private static void OnButtonTypeChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e) { WenlButton wBtn = d as WenlButton; if (e.NewValue != e.OldValue && wBtn != null) { ButtonType type = (ButtonType)e.NewValue; SetWenlButtonColorPattern(wBtn, wBtn.Pattern, type); } }
/// <summary> /// 改变按钮的样式 /// </summary> /// <param name="d"></param> /// <param name="e"></param> public static void OnButtonPatternChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { WenlButton wBtn = d as WenlButton; if (e.NewValue != e.OldValue && wBtn != null) { ButtonPattern pattern = (ButtonPattern)e.NewValue; SetWenlButtonColorPattern(wBtn, pattern, wBtn.Type); } }
/// <summary> /// /// </summary> /// <param name="wBtn"></param> /// <param name="type"></param> /// <param name="pattern"></param> private static void SetWenlButtonColorPattern(WenlButton wBtn, ButtonPattern pattern, ButtonType type) { if (type == ButtonType.Customised) { wBtn.mStaticBackground = wBtn.StaticBackground; wBtn.mStaticBorderBrush = wBtn.StaticBorderBrush; wBtn.mMouseOverBackground = wBtn.MouseOverBackground; wBtn.mMouseOverBorderBrush = wBtn.MouseOverBorderBrush; wBtn.mPressedBackground = wBtn.PressedBackground; wBtn.mPressedBorderBrush = wBtn.PressedBorderBrush; } else if (type == ButtonType.Normal || type == ButtonType.Label) { switch (pattern) { case ButtonPattern.Primary: wBtn.mStaticBackground = new SolidColorBrush(Color.FromRgb(0x42, 0x8B, 0xCA)); wBtn.mStaticBorderBrush = new SolidColorBrush(Color.FromRgb(0x35, 0x7E, 0xBD)); wBtn.mMouseOverBackground = new SolidColorBrush(Color.FromRgb(0x32, 0x76, 0xB1)); wBtn.mMouseOverBorderBrush = new SolidColorBrush(Color.FromRgb(0x28, 0x5E, 0x8F)); wBtn.mPressedBackground = new SolidColorBrush(Color.FromRgb(0x28, 0x5E, 0x8F)); wBtn.mPressedBorderBrush = new SolidColorBrush(Color.FromRgb(0x2C, 0x6A, 0xA1)); break; case ButtonPattern.Success: wBtn.mStaticBackground = new SolidColorBrush(Color.FromRgb(0x5C, 0xB8, 0x5C)); wBtn.mStaticBorderBrush = new SolidColorBrush(Color.FromRgb(0x4C, 0xAE, 0x4C)); wBtn.mMouseOverBackground = new SolidColorBrush(Color.FromRgb(0x46, 0xA5, 0x46)); wBtn.mMouseOverBorderBrush = new SolidColorBrush(Color.FromRgb(0x38, 0x85, 0x38)); wBtn.mPressedBackground = new SolidColorBrush(Color.FromRgb(0x40, 0x95, 0x40)); wBtn.mPressedBorderBrush = new SolidColorBrush(Color.FromRgb(0x38, 0x83, 0x38)); break; case ButtonPattern.Info: wBtn.mStaticBackground = new SolidColorBrush(Color.FromRgb(0x5B, 0xC0, 0xDE)); wBtn.mStaticBorderBrush = new SolidColorBrush(Color.FromRgb(0x46, 0xB8, 0xDA)); wBtn.mMouseOverBackground = new SolidColorBrush(Color.FromRgb(0x38, 0xB3, 0xD7)); wBtn.mMouseOverBorderBrush = new SolidColorBrush(Color.FromRgb(0x26, 0x9B, 0xBD)); wBtn.mPressedBackground = new SolidColorBrush(Color.FromRgb(0x33, 0xA7, 0xC7)); wBtn.mPressedBorderBrush = new SolidColorBrush(Color.FromRgb(0x26, 0x9B, 0xBD)); break; case ButtonPattern.Warning: wBtn.mStaticBackground = new SolidColorBrush(Color.FromRgb(0xF0, 0xAD, 0x4E)); wBtn.mStaticBorderBrush = new SolidColorBrush(Color.FromRgb(0xE5, 0x9D, 0x36)); wBtn.mMouseOverBackground = new SolidColorBrush(Color.FromRgb(0xED, 0x9D, 0x28)); wBtn.mMouseOverBorderBrush = new SolidColorBrush(Color.FromRgb(0xD5, 0x85, 0x12)); wBtn.mPressedBackground = new SolidColorBrush(Color.FromRgb(0xDD, 0x91, 0x23)); wBtn.mPressedBorderBrush = new SolidColorBrush(Color.FromRgb(0xD5, 0x85, 0x12)); break; case ButtonPattern.Danger: wBtn.mStaticBackground = new SolidColorBrush(Color.FromRgb(0xD9, 0x53, 0x4F)); wBtn.mStaticBorderBrush = new SolidColorBrush(Color.FromRgb(0xC6, 0x39, 0x36)); wBtn.mMouseOverBackground = new SolidColorBrush(Color.FromRgb(0xD3, 0x32, 0x2C)); wBtn.mMouseOverBorderBrush = new SolidColorBrush(Color.FromRgb(0xAD, 0x28, 0x24)); wBtn.mPressedBackground = new SolidColorBrush(Color.FromRgb(0xC3, 0x2E, 0x28)); wBtn.mPressedBorderBrush = new SolidColorBrush(Color.FromRgb(0xAD, 0x28, 0x24)); break; default: break; } if (type == ButtonType.Label) { wBtn.mStaticBackground = Brushes.Transparent; wBtn.mStaticBorderBrush = Brushes.Transparent; } } else { wBtn.mStaticBackground = Brushes.Transparent; wBtn.mStaticBorderBrush = Brushes.Transparent; wBtn.mMouseOverBackground = Brushes.Transparent; wBtn.mMouseOverBorderBrush = Brushes.Transparent; wBtn.mPressedBackground = Brushes.Transparent; wBtn.mPressedBorderBrush = Brushes.Transparent; } }