I have a custom control (MyControl) in my Xamarin.Forms project. I wonder if it is possible to style my control with CSS? Currently I do not know how to specify a selector for my custom control.
If I style the control in XAML, I need to import a namespace and use it:
xmlns:ctrls="clr-namespace:DemoApp.Controls"
...
<Style TargetType="ctrls:MyControl"...
CSS also supports namespaces:
@namespace ctlrs "clr-namespace:DemoApp.Controls";
However, if I try to write a CSS rule...
ctrls|MyControl {
margin: 10;
}
...I get a System.NotSupportedException: 'AT-rules not supported'.
So I wonder if there is a solution for custom control to be styled with CSS.
Elements with a specific class attribute can be selected with the case sensitive .class selector:
For example , set the style of
Labelstyle.css
in xaml
In your case , you should make sure that your custom control has the property
Margin.For more details about using CSS in xamarin.forms you can check here .
Update
You can set the style as following
Or you can directly set it in xaml