Skip to content

Commit 396c2a8

Browse files
committed
Improvements to TranslatedTextBlock (fix potential crash)
1 parent 9dfd8ee commit 396c2a8

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/UniGetUI/Controls/TranslatedTextBlock.xaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
x:Class="UniGetUI.Interface.Widgets.TranslatedTextBlock"
44
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
55
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6-
xmlns:local="using:UniGetUI.Interface.Widgets"
76
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
87
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
98
mc:Ignorable="d"
109
x:Name ="_parent">
1110

1211
<TextBlock
13-
x:Name="__textblock"
12+
x:Name="_textBlock"
1413
TextWrapping="Wrap"
1514
FontSize="{x:Bind _parent.FontSize}"
1615
FontFamily="{x:Bind _parent.FontFamily}"
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Microsoft.UI.Xaml;
22
using Microsoft.UI.Xaml.Controls;
3+
using Microsoft.UI.Xaml.Media;
4+
using UniGetUI.Core.Logging;
35
using UniGetUI.Core.Tools;
46

57
// To learn more about WinUI, the WinUI project structure,
@@ -12,34 +14,44 @@ public sealed partial class TranslatedTextBlock : UserControl
1214
public string __text = "";
1315
public string Text
1416
{
15-
set { __text = CoreTools.Translate(value); ApplyText(); }
17+
set => ApplyText(value);
1618
}
1719

1820
public string __suffix = "";
1921
public string Suffix
2022
{
21-
set { __suffix = value; ApplyText(); }
23+
set { __suffix = value; ApplyText(null); }
2224
}
2325
public string __prefix = "";
2426
public string Prefix
2527
{
26-
set { __prefix = value; ApplyText(); }
28+
set { __prefix = value; ApplyText(null); }
2729
}
2830

2931
public TextWrapping WrappingMode
3032
{
31-
set => __textblock.TextWrapping = value;
33+
set => _textBlock.TextWrapping = value;
3234
}
3335

3436
public TranslatedTextBlock()
3537
{
3638
InitializeComponent();
3739
}
3840

39-
public void ApplyText()
41+
public void ApplyText(string? text)
4042
{
41-
if (__textblock is not null)
42-
__textblock.Text = __prefix + __text + __suffix;
43+
try
44+
{
45+
if (text is not null) __text = CoreTools.Translate(text);
46+
if (_textBlock is not null)
47+
{
48+
_textBlock.Text = __prefix + __text + __suffix;
49+
}
50+
}
51+
catch (Exception ex)
52+
{
53+
Logger.Error(ex);
54+
}
4355
}
4456
}
4557
}

0 commit comments

Comments
 (0)