Skip to content

Migrating from UWP to Windows App SDK, how to configure ui thread for StoreContext #1866

Answered by andrewleader
lospeq asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @lospeq, the docs for InitializeWithWindow are a bit outdated, the code in the docs works for .NET Core 3 apps but not .NET 5/6 apps.

Here's what you should use instead! Use the WinRT.Interop.InitializeWithWindow.Initialize(...) method as seen below... no need for defining the interface with the GUID anymore 😊

// Get the StoreContext
var storeContext = Windows.Services.Store.StoreContext.GetDefault();

// Get your HWND
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(m_window);

// And set the HWND on the StoreContext
WinRT.Interop.InitializeWithWindow.Initialize(storeContext, hwnd);

// Then use like normal!

We'll get the docs updated!

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@lospeq
Comment options

Answer selected by andrewleader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants