-
-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathLocProxy.cs
More file actions
145 lines (129 loc) · 5.08 KB
/
Copy pathLocProxy.cs
File metadata and controls
145 lines (129 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#region Copyright information
// <copyright file="LocBinding.cs">
// Licensed under Microsoft Public License (Ms-PL)
// https://github.com/XAMLMarkupExtensions/WPFLocalizationExtension/blob/master/LICENSE
// </copyright>
// <author>Uwe Mayer</author>
#endregion
namespace WPFLocalizeExtension.Deprecated.Engine
{
#region Usings
using System;
using System.ComponentModel;
using System.Windows;
using WPFLocalizeExtension.Extensions;
#endregion
/// <summary>
/// A proxy class to localize object strings.
/// </summary>
[Obsolete("LocProxy is deprecated and will be removed in version 4.0, because lex:Loc supports now direct Binding, see documentation", false)]
public class LocProxy : FrameworkElement
{
/// <summary>
/// Our own <see cref="LocBaseExtension"/> instance.
/// </summary>
private LocBaseExtension _ext;
#region Source property
/// <summary>
/// The source.
/// </summary>
public static DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(object), typeof(LocProxy), new PropertyMetadata(PropertiesChanged));
/// <summary>
/// The backing property for <see cref="LocProxy.SourceProperty"/>
/// </summary>
[Category("Common")]
public object Source
{
get => GetValue(SourceProperty);
set => SetValue(SourceProperty, value);
}
#endregion
#region PrependType property
/// <summary>
/// This flag determines, if the type should be added using the given separator.
/// </summary>
public static DependencyProperty PrependTypeProperty = DependencyProperty.Register("PrependType", typeof(bool), typeof(LocProxy), new PropertyMetadata(false, PropertiesChanged));
/// <summary>
/// The backing property for <see cref="PrependTypeProperty"/>
/// </summary>
[Category("Common")]
public bool PrependType
{
get => (bool)GetValue(PrependTypeProperty);
set => SetValue(PrependTypeProperty, value);
}
#endregion
#region Separator property
/// <summary>
/// The Separator.
/// </summary>
public static DependencyProperty SeparatorProperty = DependencyProperty.Register("Separator", typeof(string), typeof(LocProxy), new PropertyMetadata("_", PropertiesChanged));
/// <summary>
/// The backing property for <see cref="SeparatorProperty"/>
/// </summary>
[Category("Common")]
public string Separator
{
get => (string)GetValue(SeparatorProperty);
set => SetValue(SeparatorProperty, value);
}
#endregion
#region Prefix property
/// <summary>
/// The Prefix.
/// </summary>
public static DependencyProperty PrefixProperty = DependencyProperty.Register("Prefix", typeof(string), typeof(LocProxy), new PropertyMetadata(null, PropertiesChanged));
/// <summary>
/// The backing property for <see cref="PrefixProperty"/>
/// </summary>
[Category("Common")]
public string Prefix
{
get => (string)GetValue(PrefixProperty);
set => SetValue(PrefixProperty, value);
}
#endregion
#region Readonly result property
/// <summary>
/// The result.
/// </summary>
public static DependencyPropertyKey ResultProperty = DependencyProperty.RegisterReadOnly("Result", typeof(string), typeof(LocProxy), new PropertyMetadata(""));
/// <summary>
/// The backing property for <see cref="ResultProperty"/>
/// </summary>
[Category("Common")]
public string Result
{
get => (string)GetValue(ResultProperty.DependencyProperty) ?? this.Source.ToString();
set => SetValue(ResultProperty, value);
}
#endregion
/// <summary>
/// A notification handler for the <see cref="SourceProperty"/>.
/// </summary>
/// <param name="d">The object.</param>
/// <param name="e">The event arguments.</param>
private static void PropertiesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is LocProxy proxy)
{
var source = proxy.Source;
if (source != null)
{
var key = source.ToString();
if (proxy.PrependType)
key = source.GetType().Name + proxy.Separator + key;
if (!string.IsNullOrEmpty(proxy.Prefix))
key = proxy.Prefix + proxy.Separator + key;
if (proxy._ext == null)
{
proxy._ext = new LocBaseExtension { Key = key };
proxy._ext.SetBinding(proxy, proxy.GetType().GetProperty("Result"));
}
else
proxy._ext.Key = key;
}
}
}
}
}