MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
14.87k stars 3.4k forks source link

Design time view is not the same as runtime #3254

Open mouawadma opened 1 year ago

mouawadma commented 1 year ago

Bug explanation

Hello, see the attached screenshot. Essentially, I set up this fresh project exactly as the get started instructions state (except for switching the basetheme from light to dark in app.xaml) and there is a discrepancy in how it is displayed when moving from design view to runtime view. Is there a way to fix this?

image


App.xaml

<Application x:Class="MDIXtest.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:MDIXtest"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <materialDesign:BundledTheme BaseTheme="Dark"
                                             PrimaryColor="DeepPurple"
                                             SecondaryColor="Lime" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

MainWindow.Xaml

<Window x:Class="MDIXtest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:MDIXtest"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
        TextElement.Foreground="{DynamicResource MaterialDesignBody}"
        Background="{DynamicResource MaterialDesignPaper}"
        TextElement.FontWeight="Medium"
        TextElement.FontSize="14"
        FontFamily="{materialDesign:MaterialDesignFont}">
    <StackPanel>
        <GroupBox Style="{StaticResource MaterialDesignGroupBox}"
                  Header="test">
            <TextBlock Text="test" />
        </GroupBox>
    </StackPanel>
</Window>

Version

4.9.0

Keboo commented 11 months ago

Hi @mouawadma this is likely an issue with how the designed loads and parses the App.xaml resources and how those are loaded (dynamically at runtime after those properties are set rather than at design-time). For the 5.0.0 release we are doing a major update to the theming dictionaries and theming, and I will see if there are any options when we build these dictionaries to do them in a way that the designer will like (however I can't promise a fix as we are limited by what the designer will support).

Keboo commented 3 weeks ago

Hi @mouawadma after digging into this after the v5 release, I was hoping for you to re-test. The behavior that I see is that the design does follow the theme colors, but only when viewing the Window, user controls will not follow the theme colors. For these, you can always setup design time color using the d: prefix. Something like this: d:Foreground="Red"