Hello PatrickRyder,
Welcome to our Microsoft Q&A platform!
There are some errors when testing the above code. The 'RowDefinitions = Rows.Define' line code can not be complied correctly, do you use some other package. I created a basic demo to test the function, which works fine. Here is the sample code, you could refer to:
public partial class MainPage : ContentPage
{
public MainPage()
{
var ButtonStyle = new Style(typeof(Button))
{
Setters =
{
new Setter { Property = Button.BackgroundColorProperty, Value = Color.Yellow }
}
};
var grid = new Grid()
{
BackgroundColor = Color.Transparent,
RowDefinitions =
{
new RowDefinition { Height = new GridLength(0, GridUnitType.Auto) }
},
ColumnDefinitions =
{
new ColumnDefinition()
}
};
var button = new Button
{
Text = "Press Me",
Style = ButtonStyle
};
grid.Children.Add(button);
Grid.SetRow(button, 0);
Grid.SetColumn(button, 0);
Content = grid;
button.Clicked += Button_Clicked;
}
}
The style is consumed successfully on the button.
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.