maui
maui copied to clipboard
[Grid] Using Grid.Resources inside Grid (e.g. for Buttons, Labels, ...) with just some Properties set (e.g. HorizontalOptions or TextAlignment) overwrites global Style entirely
Description
When using Grid.Resources like in the example below the default Style and Coloring for Buttons defined in the global Styles.xaml get overwritten. Not only the properties that are set in the Grid.Resources (e.g. HeightRequest), but the entire Styling.
Tried it with the Nightly Build: "8.0.6-nightly.9863"
<Grid ColumnDefinitions="Auto, Auto" ColumnSpacing="5" HeightRequest="35" Margin="20" HorizontalOptions="End">
<Grid.Resources>
<Style TargetType="Button">
<Setter Property="FontAutoScalingEnabled" Value="True" />
<Setter Property="HeightRequest" Value="35" />
<Setter Property="WidthRequest" Value="105" />
<Setter Property="Padding" Value="15, 7, 15, 10" />
</Style>
</Grid.Resources>
<Button Grid.Column="0" Text="{loc:Translate CancelButtonText}" Command="{Binding CancelFoodItemCommand}" />
<Button Grid.Column="1" Text="{loc:Translate OKButtonText}" Command="{Binding SaveFoodItemCommand}" />
</Grid>
Steps to Reproduce
- Have your own Color for a Button that is set in the global Styles.xaml to see the difference
- Define a Grid.Resource just for Buttons within a Grid as in the example Code above
- Use some Properties that do not overwrite the default Coloring you specified for Buttons (e.g. a HeightRequest Property)
- See that the Color you specified in Styles.xaml is overwritten by that
Link to public reproduction project repository
No response
Version with bug
8.0.6-nightly.9863
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
7.0.101
Affected platforms
iOS, Android
Affected platform versions
No response
Did you find any workaround?
Yes, just use a Resource in the ContentPage and using that Style will not overwrite the default Style then:
<ContentPage.Resources>
<ResourceDictionary>
<Style x:Key="GridButton" TargetType="Button">
<Setter Property="FontAutoScalingEnabled" Value="True" />
<Setter Property="HeightRequest" Value="35" />
<Setter Property="WidthRequest" Value="105" />
<Setter Property="Padding" Value="15, 7, 15, 10" />
</Style>
</ResourceDictionary>
</ContentPage.Resources>
<Grid ColumnDefinitions="Auto, Auto" ColumnSpacing="5" HeightRequest="35" Margin="20" HorizontalOptions="End">
<Button Grid.Column="0" Text="{loc:Translate CancelButtonText}" Command="{Binding CancelFoodItemCommand}" Style="{StaticResource GridButton}" />
<Button Grid.Column="1" Text="{loc:Translate OKButtonText}" Command="{Binding SaveFoodItemCommand}" Style="{StaticResource GridButton}" />
</Grid>
Relevant log output
No response