Skip to content

Commit 553a19a

Browse files
committed
Populate hostname text from code
1 parent 611938e commit 553a19a

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

App/TrayWindow.xaml

+3-11
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,16 @@
104104
Canvas.Top="3" />
105105
</Canvas>
106106

107-
<!-- This needs to not have any whitespace at all to avoid adding spaces between the runs -->
107+
<!-- This cannot have any whitespace at all to avoid adding spaces between the elements, so it's populated from code instead -->
108108
<!-- TODO: I couldn't get ellipsis to work without hardcoding a width here -->
109109
<TextBlock
110+
Loaded="{x:Bind AgentHostnameText_OnLoaded}"
110111
VerticalAlignment="Center"
111112
HorizontalAlignment="Stretch"
112113
HorizontalTextAlignment="Left"
113114
TextTrimming="CharacterEllipsis"
114115
TextWrapping="NoWrap"
115-
Width="180"
116-
xml:space="preserve"><!--
117-
118-
--><Run
119-
Text="{x:Bind Hostname}"
120-
Foreground="{ThemeResource DefaultTextForegroundThemeBrush}" /><!--
121-
--><Run
122-
Text="{x:Bind Suffix}"
123-
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" /><!--
124-
--></TextBlock>
116+
Width="180" />
125117
</StackPanel>
126118
</HyperlinkButton>
127119

App/TrayWindow.xaml.cs

+23-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.UI.Xaml;
1616
using Microsoft.UI.Xaml.Controls;
1717
using Microsoft.UI.Xaml.Controls.Primitives;
18+
using Microsoft.UI.Xaml.Documents;
1819
using Microsoft.UI.Xaml.Media;
1920
using WinRT.Interop;
2021
using WindowActivatedEventArgs = Microsoft.UI.Xaml.WindowActivatedEventArgs;
@@ -30,8 +31,8 @@ public enum AgentStatus
3031

3132
public partial class Agent
3233
{
33-
public string Hostname { get; set; } // without suffix
34-
public string Suffix { get; set; }
34+
public required string Hostname { get; set; } // without suffix
35+
public required string Suffix { get; set; }
3536
public AgentStatus Status { get; set; }
3637

3738
public Brush StatusColor => Status switch
@@ -82,6 +83,26 @@ private void AgentHostnameCopyButton_Click(object parameter)
8283
FlyoutBase.SetAttachedFlyout(frameworkElement, flyout);
8384
FlyoutBase.ShowAttachedFlyout(frameworkElement);
8485
}
86+
87+
public void AgentHostnameText_OnLoaded(object sender, RoutedEventArgs e)
88+
{
89+
if (sender is not TextBlock textBlock) return;
90+
textBlock.Inlines.Clear();
91+
textBlock.Inlines.Add(new Run
92+
{
93+
Text = Hostname,
94+
Foreground =
95+
(SolidColorBrush)Application.Current.Resources.ThemeDictionaries[
96+
"DefaultTextForegroundThemeBrush"],
97+
});
98+
textBlock.Inlines.Add(new Run
99+
{
100+
Text = Suffix,
101+
Foreground =
102+
(SolidColorBrush)Application.Current.Resources.ThemeDictionaries[
103+
"SystemControlForegroundBaseMediumBrush"],
104+
});
105+
}
85106
}
86107

87108
public sealed partial class TrayWindow : Window

0 commit comments

Comments
 (0)