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

How can I manipulate individual properties of a style Class? #630

Closed
andreas-spindler-mw opened this issue Mar 20, 2024 · 5 comments
Closed
Labels
enhancement New feature or request theming 🖌️
Milestone

Comments

@andreas-spindler-mw
Copy link

andreas-spindler-mw commented Mar 20, 2024

Hi there!
I'm having a hard time adjusting individual properties on, as an example, OutlinedButton style class. I want to change the border width for all "OutlineButtons". But my changes either won't get applied, or I loose the existing outline button properties which I want to retain.
I know I can use the StyleResource.Overrides to overwrite entires styles. But that's not what I want. I'd like to extend an existing style class. How would I do that, without creating a second style Class="ThickBorder" which I would have to apply basically everywhere.

In App.xaml

<Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary x:Name="AppColors" Source="Resources/Styles/Colors.xaml" />
                <ResourceDictionary x:Name="AppStyles" Source="Resources/Styles/Theme.xaml" />
                <material:StyleResource
                    ColorsOverride="{x:Reference AppColors}"
                    BasedOn="{x:Reference AppStyles}">
                    <!-- <material:StyleResource.Overrides> -->
                    <!--     <ResourceDictionary Source="Resources/Styles/Theme.xaml" /> -->
                    <!-- </material:StyleResource.Overrides> -->
                </material:StyleResource>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

In Theme.xaml

<! -- overwriting the base style works -->
<Style TargetType="Button" BaseResourceKey="BaseButtonStyle">
        <Setter Property="CornerRadius" Value="0" />
        <Setter Property="BackgroundColor"
                Value="{AppThemeBinding
                Light={StaticResource SecondaryContainer},
                Dark={StaticResource SecondaryContainerDark}}" />
</Style>

<! -- Crashes the app, because OutlineButton is not found. How would I extend OutlineButton style class? -->
<Style TargetType="Button" Class="MyOutlinedButton" BasedOn="{StaticResource OutlineButton}">
        <Setter Property="BorderWidth" Value="5" />
</Style>

Any help is highly appreciated. Thank you guys!

@andreas-spindler-mw andreas-spindler-mw changed the title How can I manipulate individual properties on a StyleClass How can I manipulate individual properties of a style Class? Mar 20, 2024
@enisn
Copy link
Owner

enisn commented Mar 20, 2024

Yeah, you can't use static resource from a different file in the current state of the application because the resources haven't been built and compiled yet. Can you try to define BaseResourceKey instead BasedOn property in the style?

<Style TargetType="Button" Class="MyOutlinedButton" BaseResourceKey="BaseButtonStyle">

But OutlineButton style doesn't have key in the library. So it's not possible to use it in this way. I'll add keys into library.

@andreas-spindler-mw
Copy link
Author

Hi! Yes, I can do this, but this will of course apply a border to all buttons, and not just use a different border width on the outline buttons.
So, I understand that it is currently not possible to extend or change certain aspects of the current outline button style, right?

@enisn enisn added the enhancement New feature or request label Mar 21, 2024
@enisn enisn added this to the v2.9 milestone Mar 21, 2024
DevFromDownUnder pushed a commit to DevFromDownUnder/UraniumUI that referenced this issue Mar 21, 2024
Add keys to styles
Standardise style key names
Add an example of an override dictionary entry
@DevFromDownUnder
Copy link
Contributor

Yeah, you can't use static resource from a different file in the current state of the application because the resources haven't been built and compiled yet. Can you try to define BaseResourceKey instead BasedOn property in the style?

<Style TargetType="Button" Class="MyOutlinedButton" BaseResourceKey="BaseButtonStyle">

But OutlineButton style doesn't have key in the library. So it's not possible to use it in this way. I'll add keys into library.

Added a pull for this

@andreas-spindler-mw
Copy link
Author

Awesome! Thank you so much, for the immediate support!

enisn added a commit that referenced this issue Mar 25, 2024
@DevFromDownUnder
Copy link
Contributor

Can be closed

@enisn enisn closed this as completed Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request theming 🖌️
Projects
None yet
Development

No branches or pull requests

3 participants