wpf icon indicating copy to clipboard operation
wpf copied to clipboard

Windows 11 Theming Does Not Work In PowerShell WPF Window

Open nkasco opened this issue 8 months ago • 9 comments

URL(s)

https://github.com/dotnet/core/blob/main/release-notes/9.0/preview/preview4/9.0.0-preview.4.md

Description

The following code should render a Windows 11 style WPF Window in PowerShell 7 (fx dependent, using .NET 9 Preview 4)

Add-Type -AssemblyName PresentationFramework

[xml]$xaml = @"
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Name="Window">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/PresentationFramework.Fluent;component/Resources/Fluent.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <StackPanel>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
            <TextBox x:Name="MyTextBox" Width="150" />
            <Button x:Name="SubmitButton" Content="Submit" Margin="5" />
        </StackPanel>
    </StackPanel>
</Window>
"@

$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$window = [Windows.Markup.XamlReader]::Load($reader)

$window.ShowDialog()

Current Result: Black window, although I can tell the elements are there because if I hover over the textbox my cursor changes. Doesn't appear to be properly loading the ResourceDictionary image

Confirmed that my PowerShell 7 console is using .NET 9 preview 4:

> [System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription
.NET 9.0.0-preview.4.24266.19

Perhaps I am just missing something beyond adding the proper ResourceDictionary?

nkasco avatar May 31 '24 00:05 nkasco