main
1using System;
2using System.Windows;
3using System.Windows.Controls;
4
5namespace solidware.financials.windows.ui.views.controls
6{
7 public class ExtendedTextColumn : DataGridTextColumn
8 {
9 public HorizontalAlignment HorizontalAlignment
10 {
11 get { return (HorizontalAlignment)GetValue(HorizontalAlignmentProperty); }
12 set { SetValue(HorizontalAlignmentProperty, value); }
13 }
14
15 public static readonly DependencyProperty HorizontalAlignmentProperty =
16 DependencyProperty.Register(
17 "HorizontalAlignment",
18 typeof(HorizontalAlignment),
19 typeof(ExtendedTextColumn),
20 new UIPropertyMetadata(HorizontalAlignment.Stretch));
21
22 public VerticalAlignment VerticalAlignment
23 {
24 get { return (VerticalAlignment)GetValue(VerticalAlignmentProperty); }
25 set { SetValue(VerticalAlignmentProperty, value); }
26 }
27
28 public static readonly DependencyProperty VerticalAlignmentProperty =
29 DependencyProperty.Register(
30 "VerticalAlignment",
31 typeof(VerticalAlignment),
32 typeof(ExtendedTextColumn),
33 new UIPropertyMetadata(VerticalAlignment.Stretch));
34
35 private TextAlignment GetTextAlignment()
36 {
37 switch (HorizontalAlignment)
38 {
39 case HorizontalAlignment.Center:
40 return TextAlignment.Center;
41 case HorizontalAlignment.Left:
42 return TextAlignment.Left;
43 case HorizontalAlignment.Right:
44 return TextAlignment.Right;
45 case HorizontalAlignment.Stretch:
46 return TextAlignment.Justify;
47 default:
48 throw new ArgumentOutOfRangeException("HorizontalAlignment", "Unsupported alignment type!");
49 }
50 }
51
52 protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
53 {
54 var element = base.GenerateElement(cell, dataItem);
55
56 element.HorizontalAlignment = HorizontalAlignment;
57 element.VerticalAlignment = VerticalAlignment;
58
59 return element;
60 }
61
62 protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
63 {
64 var textBox = (TextBox)base.GenerateEditingElement(cell, dataItem);
65
66 textBox.TextAlignment = GetTextAlignment();
67 textBox.VerticalContentAlignment = VerticalAlignment;
68
69 return textBox;
70 }
71 }
72}