Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Accessing CoreApplication.Views[0].Dispatcher throws in XamlIsland #174

Closed
jasonwurzel opened this issue Sep 3, 2019 · 2 comments
Closed
Milestone

Comments

@jasonwurzel
Copy link

I'm submitting a...

  • Bug report (I searched for similar issues and did not find one)

Current behavior

When accessing CoreApplication.Views in a UWP control that is inside a WindowsXamlHost in a WPF App, the CoreApplication.Views[0].Dispatcher property throws an Exception. When hosting the same control in a vanilla UWP App, the property can be accessed.

Expected behavior

Accessing CoreApplication.Views[0].Dispatcher should return the correct CoreDispatcher in both the mentioned cases.

Minimal reproduction of the problem with instructions

see https://github.com/jasonwurzel/XamlIslandDispatcherProblem for a repo. Start either ControlPlaygroundPackage (WPF - XamlIsland - Uwp) or UwpApp (UWP App) (in Debug - x64). Starting UwpApp results in no exception, starting the WPF App results in an exception when CoreApplication.Views[0].Dispatcher is accessed.

  • Min Windows version is 1903
  • dotnet core sdk 3.0.100-preview5-011568 is expected to be present

Environment

Nuget Package(s): 
- Microsoft.Toolkit.Wpf.UI.XamlHost 6.0.0-preview7.1
- Microsoft.Toolkit.Uwp.UI.Controls 5.1.1
- Microsoft.Toolkit.Uwp 5.1.1
- Microsoft.NETCore.App 3.0.0-preview7-27912-14

Package Version(s): 

Windows 10 Build Number:
- Windows 1903 18362

App min and target version:
- Windows 1903 18362

Device form factor:
- Desktop

Visual Studio 
- 2019 (version: 16.2.3)

@jasonwurzel jasonwurzel changed the title Accessing CoreApplication.Views[0].Dispatcher throws Accessing CoreApplication.Views[0].Dispatcher throws in XamlIsland Sep 3, 2019
@azchohfi
Copy link
Contributor

azchohfi commented Sep 3, 2019

Preview 5 is not recent, but the issue you are hitting has nothing to do with it. This is by design.
As you can see in your sample, using Window.Current.Dispatcher works. This should be used instead.
UWP controls running in a Xaml Islands Context are not supposed to work as-is. Minor tweaks might be required, like setting the XamlRoot of a popup to be the XamlIslands one, or Accessing the Disposer with that other pattern. We are working on the documentation, and all the workaround you did in your sample to reference a UWP class library from the WPF project should not be required. A simplified set of instructions to reference everything properly can be found here: #159 (comment)

@azchohfi azchohfi closed this as completed Sep 3, 2019
@jasonwurzel
Copy link
Author

Hi @azchohfi ,
thank you for the hint using the simplified instructions. That looks like a sane route to go.
My issue above stems from a change that was made in RxUI , so I'm a bit detached from any control there. But I guess we'll find a workaround/fix.

@michael-hawker michael-hawker added this to the 6.0.0 milestone Nov 1, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants