iNKORE-NET / UI.WPF.Modern

Modern (Fluent 2) styles and controls for your WPF applications
GNU Lesser General Public License v2.1
586 stars 52 forks source link

User control issue in the app #47

Open sumit-codebrewer opened 9 months ago

sumit-codebrewer commented 9 months ago

The library looks good on my application, it has several styles that are making my windows look modern. Like, this how I implemented a settings page in my app.

image

The issue is, when I am trying to enable the same modern styles on the user control, it is showing different behaviour. Like this is how the buttons are looking here.

image image

Kindly suggest a way to fix the same, so that the user control have the same properties as a normal window.

NotYoojun commented 9 months ago

Where did you put ThemeResource and XamlControlResource in? They should be put in the App.Resources. Did you follow the Quick Start Guide?

sumit-codebrewer commented 9 months ago

I put that in app.xaml and it is applying the modern styles in every window. But talking about User control, it is not showing the same behaviour in this case.

Ideally, I want this kind of color in dark theme

image

What I am getting in case of user control being called in another window

image

Any ideas, how to fix this?

biocross commented 8 months ago

I was able to get this to work for UserControl by manually merging resources for UserControl, and then forcing the style on the buttons:

<UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ui:ThemeResources />
                <ui:XamlControlsResources />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
<Button
Content="{Binding ButtonContent}"
Style="{StaticResource DefaultButtonStyle}">
NotYoojun commented 8 months ago

I was able to get this to work for UserControl by manually merging resources for UserControl, and then forcing the style on the buttons:

<UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ui:ThemeResources />
                <ui:XamlControlsResources />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
<Button
Content="{Binding ButtonContent}"
Style="{StaticResource DefaultButtonStyle}">

I don't think this is a good idea. It will make the theme resources loaded twice. What about adding those to DesignTimeResources?

biocross commented 8 months ago

Any guides on how I can do this? Would really appreciate it - sorry I'm a little new to WPF development

biocross commented 8 months ago

OK removing the UserControl.Resources and just manually specifying the style in the Button fixed the issue for me:

<Button
Content="{Binding ButtonContent}"
Style="{StaticResource DefaultButtonStyle}">
NotYoojun commented 8 months ago

@biocross Maybe this solution is not bad.

However, in my scenario, everything works fine when adding themes into app.xaml.

I don't know why this doesn't work for you guys. I'm really confused.