forked from Devolutions/UniGetUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslatedTextBlock.xaml.cs
More file actions
75 lines (68 loc) · 2.14 KB
/
TranslatedTextBlock.xaml.cs
File metadata and controls
75 lines (68 loc) · 2.14 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
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using UniGetUI.Core.Logging;
using UniGetUI.Core.Tools;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace UniGetUI.Interface.Widgets
{
public sealed partial class TranslatedTextBlock : UserControl
{
public string __text = "";
public string Text
{
set => ApplyText(value);
}
public string __suffix = "";
public string Suffix
{
set
{
__suffix = value;
ApplyText(null);
}
}
public string __prefix = "";
public string Prefix
{
set
{
__prefix = value;
ApplyText(null);
}
}
public TextWrapping WrappingMode
{
set => _textBlock.TextWrapping = value;
}
public TranslatedTextBlock()
{
InitializeComponent();
Loaded += (s, e) =>
{
if (Parent is Microsoft.UI.Xaml.Controls.Primitives.ButtonBase parentBtn && string.IsNullOrEmpty(Microsoft.UI.Xaml.Automation.AutomationProperties.GetName(parentBtn)))
{
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(parentBtn, _textBlock.Text);
}
};
}
public void ApplyText(string? text)
{
try
{
if (text is not null)
__text = CoreTools.Translate(text);
_textBlock.Text = __prefix + __text + __suffix;
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(this, _textBlock.Text);
if (IsLoaded && Parent is Microsoft.UI.Xaml.Controls.Primitives.ButtonBase parentBtn)
{
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(parentBtn, _textBlock.Text);
}
}
catch (Exception ex)
{
Logger.Error(ex);
}
}
}
}