Replies: 2 comments 3 replies
-
There are two things that normally happen before you can start loading Xaml content.
The thread which displays content is also expected to have a Microsoft.UI.Dispatching.DispatcherQueue on it. I know that one is made during the initialisation, but I'm not sure exactly when. But yes, that runtime class derived from Application is a real sticking point. |
Beta Was this translation helpful? Give feedback.
3 replies
-
A C# demo with no XAML may get you started? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Sysadmins often create simpler UI based tools entirely within PowerShell, today with WinForms or WPF, but would love to be able to create something a bit more modern using WinUI 3. The reason why it's more desirable to do entirely within PowerShell rather than a C# app that then loads PowerShell is largely that Sysadmins are simply more comfortable staying within that language.
It's my understanding that I'd need to load the C# projection assemblies to have access to the metadata based types within PowerShell 7.
After some digging, I found this deep dive that helps lay out some of the dependencies and it appears to state there is a projection assembly already created?
https://blogs.windows.com/windowsdeveloper/2020/07/07/a-deep-dive-into-winui-3-in-desktop-apps/#:~:text=It%E2%80%99s%20the%20Microsoft.WinUI.dll%20library.%20This%20library%20is%20included%20in%20the%20WinUI%203%20NuGet%20Package
With that in mind, I attempted the following:
add-type -Path "path\to\Microsoft.Windows.SDK.NET.dll"
add-type -Path "path\to\WinRT.Runtime.dll"
add-type -Path "path\to\Microsoft.WinUI.dll"
Which I obtained by creating a new solution in Visual Studio, building, and then extracting those dlls. All of those assemblies successfully load into my session without issue.
Once I load those, I seem to have access to the types:
However, when I try to create a new object I get the following error:
MethodInvocationException: Exception calling ".ctor" with "0" argument(s): "The type initializer for '_IWindowFactory' threw an exception."
I've tried to create objects using both the XamlReader Load method and New() straight from the type:
Same thing even if I try to create a standalone textbox from Microsoft.UI.Xaml.Controls.Textbox, etc. I think I'm just missing a few dependencies, but I'm struggling to figure out where to go from here.
Can anyone on this side of the fence assist with a simple Hello World implementation to load this into PowerShell?
Beta Was this translation helpful? Give feedback.
All reactions