[WPF] Proxy Label SetFocus call to the underlying TextBlock so that i… (#868)

* [WPF] Proxy Label SetFocus call to the underlying TextBlock so that it works
This commit is contained in:
Sergey Shakhnazarov 2018-11-09 21:30:56 +03:00 коммит произвёл Vsevolod Kukol
Родитель da9578b8a7
Коммит 51abe73670
2 изменённых файлов: 29 добавлений и 4 удалений

Просмотреть файл

@ -35,6 +35,7 @@ using SWD = System.Windows.Documents;
using Xwt.Backends; using Xwt.Backends;
using System.Windows.Automation.Peers; using System.Windows.Automation.Peers;
using System.Windows.Threading;
namespace Xwt.WPFBackend 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 bool Selectable { get; set; } // TODO: this is only supported on Win10 with UWP?
public void SetFormattedText (FormattedText text) public void SetFormattedText (FormattedText text)

Просмотреть файл

@ -270,17 +270,18 @@ namespace Xwt.WPFBackend
void FocusOnUIThread () 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 (); Widget.Focus ();
}), SW.Threading.DispatcherPriority.Render); }), SW.Threading.DispatcherPriority.Render);
} }
public void SetFocus () public void SetFocus ()
{ {
if (Widget.IsLoaded) { if (Widget.IsLoaded)
FocusOnUIThread (); FocusOnUIThread ();
} else else
Widget.Loaded += DeferredFocus; Widget.Loaded += DeferredFocus;
} }