Skip to content

Commit 100b70f

Browse files
authored
Fixed focus on view show logic being done on non-UI thread (SubnauticaNitrox#2519)
1 parent 6b8759c commit 100b70f

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Nitrox.Launcher/Models/Behaviors/FocusOnViewShowBehavior.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Avalonia.Controls;
2+
using Avalonia.Threading;
23
using Avalonia.Xaml.Interactivity;
34
using CommunityToolkit.Mvvm.Messaging;
45

@@ -11,7 +12,11 @@ public class FocusOnViewShowBehavior : Behavior<Control>
1112
{
1213
protected override void OnAttached()
1314
{
14-
WeakReferenceMessenger.Default.Register<ShowViewMessage>(this, static (obj, _) => (obj as FocusOnViewShowBehavior)?.Focus());
15+
WeakReferenceMessenger.Default.Register<ShowViewMessage>(this, static (obj, _) =>
16+
{
17+
// Need to queue this work on UI thread as calls via message originate from a different thread.
18+
Dispatcher.UIThread.Invoke(() => (obj as FocusOnViewShowBehavior)?.Focus());
19+
});
1520
base.OnAttached();
1621
}
1722

0 commit comments

Comments
 (0)