Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows 11 Theming Does Not Work In PowerShell WPF Window #9338

Open
nkasco opened this issue May 31, 2024 · 6 comments
Open

Windows 11 Theming Does Not Work In PowerShell WPF Window #9338

nkasco opened this issue May 31, 2024 · 6 comments
Labels
area-wpf Issues related to WPF in .NET Core

Comments

@nkasco
Copy link

nkasco commented May 31, 2024

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?

@antonfirsov antonfirsov added area-wpf Issues related to WPF in .NET Core and removed area-release-notes labels Jun 2, 2024
@antonfirsov
Copy link
Member

cc @dotnet/wpf-developers

@dipeshmsft
Copy link
Member

Hey @antonfirsov, there is a slight issue here. As of now, the mechanism for accent color, theme switching, etc. will work when the resource dictionary is added to App.xaml, in coming preview releases we will add the support for using Win11 themes at window level explictly.

For now, you will have to add it in your app.xaml.

@nkasco
Copy link
Author

nkasco commented Jun 3, 2024

Hey @antonfirsov, there is a slight issue here. As of now, the mechanism for accent color, theme switching, etc. will work when the resource dictionary is added to App.xaml, in coming preview releases we will add the support for using Win11 themes at window level explictly.

For now, you will have to add it in your app.xaml.

@dipeshmsft Appreciate this insights. Is there an issue, branch, or PR that can be tracked to know when it is released?

@nkasco
Copy link
Author

nkasco commented Jun 12, 2024

Not fixed still in .NET 9 preview 5

@nkasco
Copy link
Author

nkasco commented Jul 9, 2024

Not fixed still in .NET 9 preview 6

@antonfirsov
Copy link
Member

@dotnet/wpf-developers is there a tracking issue in dotnet/wpf we can link, so we can close this? Or should we transfer this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-wpf Issues related to WPF in .NET Core
Projects
None yet
Development

No branches or pull requests

3 participants