dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.21k stars 1.75k forks source link

Application Style gets applied even though separate style provided #8439

Open PaulAndersonS opened 2 years ago

PaulAndersonS commented 2 years ago

Description

I have a custom view of type ContentView. In that i have a HorizontalStackLayout with two labels. I have set a new style for HorizontalStackLayout as below

HorizontalStackLayout hStackLayout = new HorizontalStackLayout()
            {
                Style = new Style(typeof(HorizontalStackLayout)),
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions = LayoutOptions.Fill,
            };

Also tried setting Style for the CustomView using resources like below

<local:CustomView>
                <local:CustomView.Resources>
                    <Style TargetType="HorizontalStackLayout">
                        <Setter Property="Spacing" Value="50"/>
                    </Style>
                </local:CustomView.Resources>
            </local:CustomView>

But both of the approach not getting applied and the Style present in the Styles.xaml in the Application Resources gets applied.

Facing this issue in Android and Windows. Not yet tried in iOS and MacCatalsyt.

Sample: MauiApp15.zip

Steps to Reproduce

Run the attached sample.

Version with bug

6.0.400 (current)

Last version that worked well

6.0 Release Candidate 2 or older

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

ANDROID 12

Did you find any workaround?

No response

Relevant log output

No response

rachelkang commented 2 years ago

Hi, @PaulAndersonS - thanks for uploading this issue. Would you please reshare the sample in the form of a GitHub repository so that we may investigate further? We unfortunately are only able to accept samples in that form. Thanks for understanding!

janseris commented 2 years ago

@rachelkang

Would you please reshare the sample in the form of a GitHub repository so that we may investigate further? We unfortunately are only able to accept samples in that form.

That is not true what you write about github repositories being the only accepted source. Full sample in zip does the job 100% (runnable project/solution). It was never needed until I saw you writing this some days ago. Also, imagine being a developer having 50 random repos for every maui issue out there if I did like you wrote. That sounds really silly.

hartez commented 2 years ago

Also, imagine being a developer having 50 random repos for every maui issue out there if I did like you wrote. That sounds really silly.

You could use one repo and multiple branches.

kristinx0211 commented 2 years ago

verified repro on windows and android with above project.

jfversluis commented 2 years ago

@janseris in the bug template we already ask for reproductions through GitHub and under the link there is more information about why a reproduction project is imporant and we repeat the request for providing it through a GitHub repo

image

I'm sorry if that is not something you like, but something that we are going to enforce from a security standpoint. I will add a bit of clarification in the link above on why that is. Thanks for your cooperation!

mattleibow commented 1 year ago

Looking at this code for future things and there are 3 "styles" in this sample:

  1. App style
  2. Main page style
  3. Blank C# style

It appears that the new blank style set in C# is preventing the main page style from applying - but not the app style.

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

homeyf commented 1 year ago

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 1.0. Can repro on Windows and Android Platform with sample project. MauiApp15.zip image