Rmunoz
Topic Author
Posts: 13
Joined: 27 Aug 2022, 20:44

Wpf app with Noesis theme looks different as in xamltoy

19 Aug 2024, 20:42

I created a dummy WPF application (.net framework 4.8 )
Nuget package was installed: Noesis.GUI.Extensions (3.0.30.13778)
Referenced the theme with the pack-uri
    <Application.Resources>
        <ResourceDictionary Source="pack://application:,,,/Noesis.GUI.Extensions;component/Theme/NoesisTheme.DarkBlue.xaml" />
    </Application.Resources>
I use for testing the sample code of Xamltoy "Noesis Theme" sample:


The theme looks like it's only partially applied.
BadColors.png

Focusing for example only in the resource Brush.Window.Background, on the editor preview, it shows like it will be a dark color, but if you select the static resource and go to its source it shows it should be a white SolidColorBrush.

ResouceFound_Mismatch.png

The unexpected color showing into the xaml preview on the left looks like it is matching what is shown when you launch the application

Hardcoding the background to be white improves the situation a little but does not solve the issue at all, the colors do not match at all the equivalent Theme sample in xaml toy
Hardcoded_White_Background.png
What can i do to address this issue?

Note: LightBlue looks much better even without the background hack ( i guess the default theme of xamltoy is LightBlue). Maybe there is some specific issue with DarkBlue. But still, why does the DarkBlue theme, look off?


LightThemeLooksOk.png
 
User avatar
sfernandez
Site Admin
Posts: 3106
Joined: 22 Dec 2011, 19:20

Re: Wpf app with Noesis theme looks different as in xamltoy

27 Aug 2024, 23:45

Hi,

Using a Grid as root means that the default value of the Foreground property (Black) is used for TextBlocks, as that property is not inherited from any Control. And because XamlToy uses NoesisTheme.LightBlue.xaml as the theme for the application resources, the black texts look quite good.

If you change your root to something like a Page, then the control style will set the appropriate Foreground depending on the Dark/Light theme.
Focusing for example only in the resource Brush.Window.Background, on the editor preview, it shows like it will be a dark color, but if you select the static resource and go to its source it shows it should be a white SolidColorBrush.
In the dark themes, the brushes use the Colors.Dark.xaml that just have the same names but inverted (so Color.White is the darkest one in this case). That way both Dark and Light brushes xaml are exactly the same, just changing the reference to the Colors xaml, so nothing wrong here.

Hope this clarifies things a bit.
 
Rmunoz
Topic Author
Posts: 13
Joined: 27 Aug 2022, 20:44

Re: Wpf app with Noesis theme looks different as in xamltoy

28 Aug 2024, 19:23

I have misdirected the explanation by providing that xamltoy

The host of the window in the Noesis Win32 application with the SDK is indeed a window

Dark_ThemeColours_App.png
Dark_ThemeColours_MainWindow.png

I've broken my local sdk setup but ill double check with the sdk on win32 and wasm
 
User avatar
sfernandez
Site Admin
Posts: 3106
Joined: 22 Dec 2011, 19:20

Re: Wpf app with Noesis theme looks different as in xamltoy

02 Sep 2024, 18:44

I understand now, the problem is that the root element is a custom control and implicit styles only apply when the type matches exactly the same type. So in this case, as there is no Style defined for "workspace_hello.MainWindow" it won't apply any style from the theme. There are two options:

- Define a style for the custom type:
<Style TargetType="{x:Type local:MainWindow}" BasedOn="{StaticResource {x:Type ContentControl}}"/>
- The same way you are setting the Background on the root grid, you can set the Foreground for the window:
<Window x:Class="workspace_hello.MainWindow" ...
  Foreground="{StaticResource Brush.Foreground.Normal}">
  <Grid Background="{StaticResource Brush.Window.Background}".../>
</Window>

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 0 guests