[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:
Родитель
da9578b8a7
Коммит
51abe73670
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче