dotnet / dotnet/maui

Application Style gets applied even though separate style provided

Open
#8,439 11 comments 0 reactions 0 assignees View on GitHub
area-xaml platform/android platform/windows s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 14h
Merged PRs (30d)
296

Description

### 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

```cs
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

```xaml



<Setter Property="Spacing" Value="50"/>



```

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](https://github.com/dotnet/maui/files/9019357/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_

Contributor guide

Open the contributing guide

Research direction

Start by running the attached MauiApp15.zip sample on Android and Windows, then inspect the application Styles.xaml, CustomView resources, and HorizontalStackLayout setup. Reproduce the conflict between the application style and the per-view or instance style; done means the separately provided style is applied instead of the application-level style.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.