Skip to content

Commit 835ba57

Browse files
committed
Fix: ComboBox focus issue
1 parent a8c48cf commit 835ba57

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

Source/NETworkManager/Views/TigerVNCConnectChildWindow.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Windows;
3+
using System.Windows.Controls;
34
using System.Windows.Threading;
45

56
namespace NETworkManager.Views;
@@ -15,7 +16,9 @@ private void ChildWindow_OnLoaded(object sender, RoutedEventArgs e)
1516
{
1617
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
1718
{
18-
ComboBoxHost.Focus();
19+
// Workaround to focus the editable part of the ComboBox
20+
var textBox = (TextBox)ComboBoxHost.Template.FindName("PART_EditableTextBox", ComboBoxHost);
21+
textBox?.Focus();
1922
}));
2023
}
2124
}

Source/NETworkManager/Views/WebConsoleConnectChildWindow.xaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
CloseButtonCommand="{Binding Path=CancelCommand}"
1313
Style="{StaticResource DefaultChildWindow}"
1414
Loaded="ChildWindow_OnLoaded"
15-
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:WebConsoleConnectViewModel}">
15+
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:WebConsoleConnectViewModel}">
1616
<Grid Margin="10">
1717
<Grid.RowDefinitions>
1818
<RowDefinition Height="Auto" />
@@ -34,12 +34,11 @@
3434
<RowDefinition Height="Auto" />
3535
</Grid.RowDefinitions>
3636
<TextBlock Grid.Column="0" Grid.Row="0" Text="{x:Static localization:Strings.URL}" />
37-
3837
<ComboBox x:Name="ComboBoxUrl"
39-
Grid.Column="2" Grid.Row="0"
40-
ItemsSource="{Binding UrlHistoryView}"
41-
mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleWebsiteUri}"
42-
Style="{StaticResource EditableComboBox}">
38+
Grid.Column="2" Grid.Row="0"
39+
ItemsSource="{Binding UrlHistoryView}"
40+
mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleWebsiteUri}"
41+
Style="{StaticResource EditableComboBox}">
4342
<ComboBox.Text>
4443
<Binding Path="Url" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged">
4544
<Binding.ValidationRules>

Source/NETworkManager/Views/WebConsoleConnectChildWindow.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Windows;
3+
using System.Windows.Controls;
34
using System.Windows.Threading;
45

56
namespace NETworkManager.Views;
@@ -15,7 +16,9 @@ private void ChildWindow_OnLoaded(object sender, RoutedEventArgs e)
1516
{
1617
Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate
1718
{
18-
ComboBoxUrl.Focus();
19+
// Workaround to focus the editable part of the ComboBox
20+
var textBox = (TextBox)ComboBoxUrl.Template.FindName("PART_EditableTextBox", ComboBoxUrl);
21+
textBox?.Focus();
1922
}));
2023
}
2124
}

0 commit comments

Comments
 (0)