main
 1using System.Windows;
 2using System.Windows.Controls;
 3using System.Windows.Data;
 4using System.Windows.Media;
 5
 6namespace solidware.financials.windows.ui.views
 7{
 8    public class ImageButton : System.Windows.Controls.Button
 9    {
10        public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(ImageButton));
11
12        public static readonly DependencyProperty LabelProperty = DependencyProperty.Register("Label", typeof(string),typeof (ImageButton));
13
14        public ImageSource ImageSource
15        {
16            get { return (ImageSource)GetValue(ImageSourceProperty); }
17            set{SetValue(ImageSourceProperty, value);}
18        }
19
20        public string Label
21        {
22            get { return (string) GetValue(LabelProperty); }
23            set{ SetValue(LabelProperty, value);}
24        }
25
26        private void Configure()
27        {
28            var binding = new Binding
29            {
30                RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ImageButton), 1),
31                Path = new PropertyPath("IsEnabled")
32            };
33            var dataTrigger = new DataTrigger { Binding = binding, Value = false, Setters = { new Setter(OpacityProperty, 0.25) } };
34            var stackPanel = new StackPanel();
35            
36            stackPanel.Children.Add(new Image {Source = ImageSource, Style = new Style { Triggers = { dataTrigger } }, Height = 25, Margin = new Thickness(0)});
37            var label = new Label
38                              {
39                                  HorizontalAlignment = HorizontalAlignment.Center,
40                                  HorizontalContentAlignment = HorizontalAlignment.Left,
41                                  Margin = new Thickness(0),
42                                  Padding = new Thickness(0),
43                              };
44            if (!string.IsNullOrEmpty(Label))
45                label.Content = new AccessText{Text = Label, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0)};
46
47            stackPanel.Children.Add(label);
48            Content = stackPanel;
49        }
50
51        protected override void OnInitialized(System.EventArgs e)
52        {
53            base.OnInitialized(e);
54            Configure();
55            SetValue(ToolTipService.ShowOnDisabledProperty, true);
56        }
57    }
58}