dotnet / dotnet/wpf

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

Open
#2,393 13 comments 1 reaction 0 assignees View on GitHub
Bug regression
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

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.

```csharp
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();
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.