diff options
author | Sergey Shakhnazarov <v-seshak@microsoft.com> | 2018-10-18 14:44:06 +0300 |
---|---|---|
committer | Sergey Shakhnazarov <v-seshak@microsoft.com> | 2018-10-18 16:47:56 +0300 |
commit | c5364cb760c173af5960b660724fab1c15b36f3c (patch) | |
tree | 2aa050b74ce65052ae451b38647a0b5461c7ab96 | |
parent | 750c88b06177548085a1f03fad09338063b33b4b (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.cs | 16 |
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 {
|