Vereinsmeisterschaften  22aa7800eae54b428d40e835886cefe1fdefdfdf
This is a software that can be used to manage the internal competition of the swimming club Illertissen called "Vereinsmeisterschaften".
Loading...
Searching...
No Matches
StringFormatHelper.cs
2
4{
9 public static class StringFormatHelper
10 {
11 #region Value
12
13 public static DependencyProperty ValueProperty = DependencyProperty.RegisterAttached("Value", typeof(object), typeof(StringFormatHelper), new PropertyMetadata(null, OnValueChanged));
14
15 private static void OnValueChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
16 {
17 RefreshFormattedValue(obj);
18 }
19
20 public static object GetValue(DependencyObject obj)
21 {
22 return obj.GetValue(ValueProperty);
23 }
24
25 public static void SetValue(DependencyObject obj, object newValue)
26 {
27 obj.SetValue(ValueProperty, newValue);
28 }
29
30 #endregion
31
32 #region Format
33
34 public static DependencyProperty FormatProperty = DependencyProperty.RegisterAttached("Format", typeof(string), typeof(StringFormatHelper), new PropertyMetadata(null, OnFormatChanged));
35
36 private static void OnFormatChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
37 {
38 RefreshFormattedValue(obj);
39 }
40
41 public static string GetFormat(DependencyObject obj)
42 {
43 return (string)obj.GetValue(FormatProperty);
44 }
45
46 public static void SetFormat(DependencyObject obj, string newFormat)
47 {
48 obj.SetValue(FormatProperty, newFormat);
49 }
50
51 #endregion
52
53 #region FormattedValue
54
55 public static DependencyProperty FormattedValueProperty = DependencyProperty.RegisterAttached("FormattedValue", typeof(string), typeof(StringFormatHelper), new PropertyMetadata(null));
56
57 public static string GetFormattedValue(DependencyObject obj)
58 {
59 return (string)obj.GetValue(FormattedValueProperty);
60 }
61
62 public static void SetFormattedValue(DependencyObject obj, string newFormattedValue)
63 {
64 obj.SetValue(FormattedValueProperty, newFormattedValue);
65 }
66
67 #endregion
68
69 private static void RefreshFormattedValue(DependencyObject obj)
70 {
71 object value = GetValue(obj);
72 string format = GetFormat(obj);
73
74 if (format != null)
75 {
76 if (!format.StartsWith("{0:"))
77 {
78 format = String.Format("{{0:{0}}}", format);
79 }
80
81 SetFormattedValue(obj, String.Format(format, value));
82 }
83 else
84 {
85 SetFormattedValue(obj, value == null ? String.Empty : value.ToString());
86 }
87 }
88 }
89
90}