Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Shakhnazarov <v-seshak@microsoft.com>2018-10-18 14:44:06 +0300
committerSergey Shakhnazarov <v-seshak@microsoft.com>2018-10-18 16:47:56 +0300
commitc5364cb760c173af5960b660724fab1c15b36f3c (patch)
tree2aa050b74ce65052ae451b38647a0b5461c7ab96
parent750c88b06177548085a1f03fad09338063b33b4b (diff)
[WPF] Set focus to element via UI thread because sometimes the element would not be ready (even though IsLoaded)
-rw-r--r--Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs16
1 files changed, 12 insertions, 4 deletions
diff --git a/Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs b/Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs
index 023ef3e5..9f4c48f0 100644
--- a/Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs
+++ b/Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs
@@ -222,18 +222,26 @@ namespace Xwt.WPFBackend
get { return Widget.IsFocused; }
}
- public void SetFocus ()
+ void FocusOnUIThread ()
{
- if (Widget.IsLoaded)
+ Widget.Dispatcher.BeginInvoke ((Action) (() =>
+ {
Widget.Focus ();
- else
+ }), SW.Threading.DispatcherPriority.Render);
+ }
+
+ public void SetFocus ()
+ {
+ if (Widget.IsLoaded) {
+ FocusOnUIThread ();
+ } else
Widget.Loaded += DeferredFocus;
}
void DeferredFocus (object sender, RoutedEventArgs e)
{
Widget.Loaded -= DeferredFocus;
- Widget.Focus ();
+ FocusOnUIThread ();
}
public virtual bool Sensitive {