Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with touch being disabled when having two windows in two different threads (like a splash screen) #2393

Open
mbendtsen opened this issue Jan 2, 2020 · 4 comments
Assignees
Milestone

Comments

@mbendtsen
Copy link

@mbendtsen mbendtsen commented Jan 2, 2020

I found an issue where touch would be disabled.
If you want to create a custom splash screen and creates a new Thread for it, and then create the main window in the Main Thread, touch will no longer work.
This same code works fine in .NET Framework.

Project for reproducing the issue can be found here including description: https://github.com/mbendtsen/touch_issue_net_core
Requires a touch enabled device.

public partial class App : Application
{
   private Thread _splashThread;
   
   protected async override void OnStartup(StartupEventArgs e)
   {
       base.OnStartup(e);
       
       ShowSplash();
       
       // Simulate long running work.
       await Task.Delay(2000);
       
       _splashViewModel.SetInitialized();
       
       var window = new MainWindow()
       {
          DataContext = new MainWindowViewModel()
       };
       window.Show();
   }
   
   private void ShowSplash()
   {
       _splashViewModel = new SplashViewModel();
       
       _splashThread = new Thread(() =>
       {
          new Splash { DataContext = _splashViewModel }.Show();
          Dispatcher.Run();
       });
       _splashThread.SetApartmentState(ApartmentState.STA);
       _splashThread.IsBackground = true;
       _splashThread.Name = "Splash";
       _splashThread.Start();
   }
}
@mbendtsen mbendtsen changed the title Issue with touch being disabled in certain scenarios Issue with touch being disabled when having two windows in tow different threads (like a splash screen) Jan 2, 2020
@mbendtsen mbendtsen changed the title Issue with touch being disabled when having two windows in tow different threads (like a splash screen) Issue with touch being disabled when having two windows in two different threads (like a splash screen) Jan 2, 2020
@mbendtsen

This comment has been minimized.

Copy link
Author

@mbendtsen mbendtsen commented Jan 2, 2020

Found a workaround. Add this line before showing the splash screen: _ = Tablet.TabletDevices;

@rladuca

This comment has been minimized.

Copy link
Member

@rladuca rladuca commented Jan 2, 2020

@mbendtsen This looks like an issue with triggering tablet initialization on the new thread. Thanks for pointing it out. Usually a new window should initialize the stylus thread (via HwndStylusInputProvider I believe), but it doesn't seem like that is happening.

@lindexi

This comment has been minimized.

Copy link
Contributor

@lindexi lindexi commented Jan 21, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.