main
 1using System;
 2using System.Windows;
 3using System.Windows.Controls;
 4using System.Windows.Controls.Primitives;
 5using System.Windows.Input;
 6using solidware.financials.windows.ui.views.controls;
 7using solidware.financials.windows.ui.views.icons;
 8
 9namespace solidware.financials.windows.ui.views
10{
11    static public class WPFExtensions
12    {
13        static public T Add<T>(this Panel panel, Action<T> action) where T : UIElement, new()
14        {
15            var element = panel.Add<T>();
16            action(element);
17            return element;
18        }
19
20        static public T Add<T>(this Panel panel) where T : UIElement, new()
21        {
22            var t = new T();
23            panel.Children.Add(t);
24            return t;
25        }
26
27        static public StackPanel Horizontal(this StackPanel panel)
28        {
29            panel.Orientation = Orientation.Horizontal;
30            return panel;
31        }
32
33        static public ButtonExpression ToIconButton(this ButtonBase button, UIIcon icon, ICommand command)
34        {
35            button.Command = command;
36            return button.ToIconButton(icon);
37        }
38
39        static public ButtonExpression ToIconButton(this ButtonBase button, UIIcon icon)
40        {
41            button.ClickMode = ClickMode.Release;
42            var image = button.Content as Image;
43            if (image == null)
44            {
45                image = new Image();
46                button.Content = image;
47                image.Width = 25;
48                image.Height = 25;
49            }
50            image.apply_icon(icon);
51            return new ButtonExpression(button);
52        }
53
54        static public RoutedEventHandler ToRoutedHandler(this Action action)
55        {
56            return (s, e) => action();
57        }
58    }
59}