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-11-09 21:30:56 +0300
committerVsevolod Kukol <sevoku@microsoft.com>2018-11-09 21:30:56 +0300
commit51abe73670f8402122c5f970d69f3411d6b48e3a (patch)
tree08c5729b592c60cf66e8531fd4cb177f37127c13
parentda9578b8a72ec00c521fb64ee7138d2b0a0dfee1 (diff)
[WPF] Proxy Label SetFocus call to the underlying TextBlock so that i… (#868)d16-0-p2
* [WPF] Proxy Label SetFocus call to the underlying TextBlock so that it works
-rw-r--r--Xwt.WPF/Xwt.WPFBackend/LabelBackend.cs24
-rw-r--r--Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs9
2 files changed, 29 insertions, 4 deletions
diff --git a/Xwt.WPF/Xwt.WPFBackend/LabelBackend.cs b/Xwt.WPF/Xwt.WPFBackend/LabelBackend.cs
index 4b1dfb54..94d61b5c 100644
--- a/Xwt.WPF/Xwt.WPFBackend/LabelBackend.cs
+++ b/Xwt.WPF/Xwt.WPFBackend/LabelBackend.cs
@@ -35,6 +35,7 @@ using SWD = System.Windows.Documents;
using Xwt.Backends;
using System.Windows.Automation.Peers;
+using System.Windows.Threading;
namespace Xwt.WPFBackend
{
@@ -82,6 +83,29 @@ namespace Xwt.WPFBackend
}
}
+ void FocusOnUIThread ()
+ {
+ // Using Render (7) priority here instead of default Normal (9) so that
+ // the component has some time to initialize and get ready to receive the focus
+ Widget.Dispatcher.BeginInvoke ((Action) (() => {
+ ((WpfLabel) Widget).TextBlock.Focus ();
+ }), DispatcherPriority.Render);
+ }
+
+ public new void SetFocus ()
+ {
+ if (Widget.IsLoaded)
+ FocusOnUIThread ();
+ else
+ Widget.Loaded += DeferredFocus;
+ }
+
+ void DeferredFocus (object sender, RoutedEventArgs e)
+ {
+ Widget.Loaded -= DeferredFocus;
+ FocusOnUIThread ();
+ }
+
public bool Selectable { get; set; } // TODO: this is only supported on Win10 with UWP?
public void SetFormattedText (FormattedText text)
diff --git a/Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs b/Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs
index eefce69a..ba711304 100644
--- a/Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs
+++ b/Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs
@@ -270,17 +270,18 @@ namespace Xwt.WPFBackend
void FocusOnUIThread ()
{
- Widget.Dispatcher.BeginInvoke ((Action) (() =>
- {
+ // Using Render (7) priority here instead of default Normal (9) so that
+ // the component has some time to initialize and get ready to receive the focus
+ Widget.Dispatcher.BeginInvoke ((Action) (() => {
Widget.Focus ();
}), SW.Threading.DispatcherPriority.Render);
}
public void SetFocus ()
{
- if (Widget.IsLoaded) {
+ if (Widget.IsLoaded)
FocusOnUIThread ();
- } else
+ else
Widget.Loaded += DeferredFocus;
}