adospace/reactorui-maui

Is it possible define default style in c# code not in xaml?

nomurayoshuak opened this issue · 7 comments

@adospace
Is it possible define default style in c# code not in xaml?
For example, I have bellow Style.xaml in the Resources/Styles directory and add it in the MauiProgram.cs.

<Style TargetType="Button">
    <Setter Property="BorderThickness" Value="5" />
    <Setter Property="Foreground" Value="Black" />
    <Setter Property="BorderBrush" >
        <Setter.Value>
            <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                <GradientStop Color="Yellow" Offset="0.0" />
                <GradientStop Color="Red" Offset="0.25" />
                <GradientStop Color="Blue" Offset="0.75" />
                <GradientStop Color="LimeGreen" Offset="1.0" />
            </LinearGradientBrush>
        </Setter.Value>
    </Setter>
</Style>

However, I'd like to be that only define as c# code.
I already know a way that use Theme.cs like this https://github.com/adospace/reactorui-maui/blob/c1d4ab64591faa662584b8b2390f68c5d06307fa/samples/Calculator/Resources/Styles/Theme.cs.
However that way I should reference a Theme class in the each component. Is it possible I apply default styles to default components such as Button and Label and more?

no, unfortunately, it is not possible with MauiReactor currently. It was possible with my old library (ReactorUI for XamarinForms).

The reason I didn't port that feature to MauiReactor is that I found it rarely used and also a bit slow because every time a widget was created it had to look up the tree to find the style where it was defined to apply it.

I'm curious, how would you like to define it?

Thank you for your response.
I understood the reasons why it cannot be. I upon reconsideration, it seems like handling custom components with something like the Theme class might be the best practice.
I appreciate your always thoughtful responses.

I'll write down a fanciful idea of something that might not be feasible. It may not be in demand (as I mentioned earlier, I also increasingly feel that an implementation like the Theme class is sufficient).

For example, is it possible to define interfaces the standard components provided by MauiReactor and replace them with custom implementations? It might end up being more trouble than it's worth, but...

I'm working on a new feature inspired by your comment (#14 (comment))

Let me know if it could be of any help to your use case.

@adospace
Your solution is so great! I like it.
Thank you for listen to my opinion.

Be following

Theming feature has been published, check it out:

https://adospace.gitbook.io/mauireactor/components/theming

@adospace
Thank you! I checked it and it works good on my project!
It is so great feature. Thank you for your amazing work🙏