Skip to content

Commit af7030d

Browse files
authored
[Fix] Correctly scales the rest of the utility when the user changes the font size (#3564)
1 parent 40b2894 commit af7030d

File tree

3 files changed

+182
-137
lines changed

3 files changed

+182
-137
lines changed

functions/private/Initialize-InstallCategoryAppList.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ function Initialize-InstallCategoryAppList {
2424
$toggleButton = New-Object Windows.Controls.Label
2525
$toggleButton.Content = "$Category"
2626
$toggleButton.Tag = "CategoryToggleButton"
27-
$sync.$Category = $Category
27+
$toggleButton.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "HeaderFontSize")
28+
$toggleButton.SetResourceReference([Windows.Controls.Control]::FontFamilyProperty, "HeaderFontFamily")
29+
$sync.$Category = $toggleButton
2830

2931
$null = $TargetElement.Items.Add($toggleButton)
3032
}

functions/public/Invoke-WPFUIElements.ps1

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ function Invoke-WPFUIElements {
140140
$label.Content = $category -replace ".*__", ""
141141
$label.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "HeaderFontSize")
142142
$label.SetResourceReference([Windows.Controls.Control]::FontFamilyProperty, "HeaderFontFamily")
143+
$label.UseLayoutRounding = $true
143144
$itemsControl.Items.Add($label) | Out-Null
144145
$sync[$category] = $label
145146

@@ -154,6 +155,7 @@ function Invoke-WPFUIElements {
154155
$checkBox = New-Object Windows.Controls.CheckBox
155156
$checkBox.Name = $entryInfo.Name
156157
$checkBox.HorizontalAlignment = "Right"
158+
$checkBox.UseLayoutRounding = $true
157159
$dockPanel.Children.Add($checkBox) | Out-Null
158160
$checkBox.Style = $ColorfulToggleSwitchStyle
159161

@@ -163,6 +165,7 @@ function Invoke-WPFUIElements {
163165
$label.HorizontalAlignment = "Left"
164166
$label.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "FontSize")
165167
$label.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "MainForegroundColor")
168+
$label.UseLayoutRounding = $true
166169
$dockPanel.Children.Add($label) | Out-Null
167170
$itemsControl.Items.Add($dockPanel) | Out-Null
168171

@@ -217,6 +220,7 @@ function Invoke-WPFUIElements {
217220
$label.HorizontalAlignment = "Left"
218221
$label.VerticalAlignment = "Center"
219222
$label.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "ButtonFontSize")
223+
$label.UseLayoutRounding = $true
220224
$horizontalStackPanel.Children.Add($label) | Out-Null
221225

222226
$comboBox = New-Object Windows.Controls.ComboBox
@@ -226,11 +230,14 @@ function Invoke-WPFUIElements {
226230
$comboBox.HorizontalAlignment = "Left"
227231
$comboBox.VerticalAlignment = "Center"
228232
$comboBox.SetResourceReference([Windows.Controls.Control]::MarginProperty, "ButtonMargin")
233+
$comboBox.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "ButtonFontSize")
234+
$comboBox.UseLayoutRounding = $true
229235

230236
foreach ($comboitem in ($entryInfo.ComboItems -split " ")) {
231237
$comboBoxItem = New-Object Windows.Controls.ComboBoxItem
232238
$comboBoxItem.Content = $comboitem
233239
$comboBoxItem.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "ButtonFontSize")
240+
$comboBoxItem.UseLayoutRounding = $true
234241
$comboBox.Items.Add($comboBoxItem) | Out-Null
235242
}
236243

@@ -239,6 +246,19 @@ function Invoke-WPFUIElements {
239246

240247
$comboBox.SelectedIndex = 0
241248

249+
# Set initial text
250+
if ($comboBox.Items.Count -gt 0) {
251+
$comboBox.Text = $comboBox.Items[0].Content
252+
}
253+
254+
# Add SelectionChanged event handler to update the text property
255+
$comboBox.Add_SelectionChanged({
256+
$selectedItem = $this.SelectedItem
257+
if ($selectedItem) {
258+
$this.Text = $selectedItem.Content
259+
}
260+
})
261+
242262
$sync[$entryInfo.Name] = $comboBox
243263
}
244264

@@ -250,7 +270,8 @@ function Invoke-WPFUIElements {
250270
$button.SetResourceReference([Windows.Controls.Control]::MarginProperty, "ButtonMargin")
251271
$button.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "ButtonFontSize")
252272
if ($entryInfo.ButtonWidth) {
253-
$button.Width = $entryInfo.ButtonWidth
273+
$baseWidth = [int]$entryInfo.ButtonWidth
274+
$button.Width = [math]::Max($baseWidth, 350)
254275
}
255276
$itemsControl.Items.Add($button) | Out-Null
256277

@@ -281,6 +302,7 @@ function Invoke-WPFUIElements {
281302
$radioButton.SetResourceReference([Windows.Controls.Control]::MarginProperty, "CheckBoxMargin")
282303
$radioButton.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "ButtonFontSize")
283304
$radioButton.ToolTip = $entryInfo.Description
305+
$radioButton.UseLayoutRounding = $true
284306

285307
if ($entryInfo.Checked -eq $true) {
286308
$radioButton.IsChecked = $true
@@ -301,6 +323,7 @@ function Invoke-WPFUIElements {
301323
$checkBox.SetResourceReference([Windows.Controls.Control]::FontSizeProperty, "FontSize")
302324
$checkBox.ToolTip = $entryInfo.Description
303325
$checkBox.SetResourceReference([Windows.Controls.Control]::MarginProperty, "CheckBoxMargin")
326+
$checkBox.UseLayoutRounding = $true
304327
if ($entryInfo.Checked -eq $true) {
305328
$checkBox.IsChecked = $entryInfo.Checked
306329
}
@@ -312,6 +335,7 @@ function Invoke-WPFUIElements {
312335
$textBlock.Text = "(?)"
313336
$textBlock.ToolTip = $entryInfo.Link
314337
$textBlock.Style = $HoverTextBlockStyle
338+
$textBlock.UseLayoutRounding = $true
315339

316340
$horizontalStackPanel.Children.Add($textBlock) | Out-Null
317341

0 commit comments

Comments
 (0)