12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System.ComponentModel;
- using System.Windows;
- using System.Windows.Media;
- namespace CustomControls
- {
- [DesignTimeVisible(false)]
- public class ToggleButtonBase : System.Windows.Controls.Primitives.ToggleButton
- {
- public string Text
- {
- get { return (string)GetValue(TextProperty); }
- set { SetValue(TextProperty, value); }
- }
- public static readonly DependencyProperty TextProperty =
- DependencyProperty.Register("Text", typeof(string), typeof(ToggleButtonBase), new PropertyMetadata(""));
- public ImageSource Image
- {
- get { return (ImageSource)GetValue(ImageProperty); }
- set { SetValue(ImageProperty, value); }
- }
- public static readonly DependencyProperty ImageProperty =
- DependencyProperty.Register("Image", typeof(ImageSource), typeof(ToggleButtonBase), new PropertyMetadata(null));
- public double ImageWidth
- {
- get { return (double)GetValue(ImageWidthProperty); }
- set { SetValue(ImageWidthProperty, value); }
- }
- public static readonly DependencyProperty ImageWidthProperty =
- DependencyProperty.Register("ImageWidth", typeof(double), typeof(ToggleButtonBase), new PropertyMetadata(16.0));
- public double ImageHeight
- {
- get { return (double)GetValue(ImageHeightProperty); }
- set { SetValue(ImageHeightProperty, value); }
- }
- public static readonly DependencyProperty ImageHeightProperty =
- DependencyProperty.Register("ImageHeight", typeof(double), typeof(ToggleButtonBase), new PropertyMetadata(16.0));
- public bool IsVertical
- {
- get { return (bool)GetValue(IsVerticalProperty); }
- set { SetValue(IsVerticalProperty, value); }
- }
- public static readonly DependencyProperty IsVerticalProperty =
- DependencyProperty.Register("IsVertical", typeof(bool), typeof(ToggleButtonBase), new PropertyMetadata(false));
- public bool CheckOnClick { get; set; }
- protected override void OnClick()
- {
- // base OnClick implementation makes toggle then raises the event. Skip toggle and raise the event only.
- if (!CheckOnClick)
- {
- RoutedEventArgs e = new RoutedEventArgs(ClickEvent, this);
- RaiseEvent(e);
- return;
- }
- base.OnClick();
- }
- }
- }
|