Share via

Default Style for a Custom Control

Nathan Sokalski 4,111 Reputation points
2021-04-09T16:39:09.427+00:00

I have a Custom Control which inherits from GridLayout, and uses an XML Layout with a root of merge. The first line in my Initialize method is:

Inflate(context, Resource.Layout.CircleButton, this);

However, I cannot find a way to set a style (like having a style="..." in a layout file) to the GridLayout (which is what the root of the control is, since it inherits from GridLayout). What I have been doing as a workaround is just including the style (the one I want to use by default when the Custom Control is created) in the XML when using the control. However, this is very inconvenient, it is just extra xml that will (almost) always be the same. Is there a way to assign a default style to a Custom Control?

Developer technologies | .NET | Xamarin

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.