【发布时间】:2020-01-30 10:11:18
【问题描述】:
我的 Xamarin.Forms 项目中有一个自定义控件 (MyControl)。 我想知道是否可以使用 CSS 为我的控件设置样式?目前我不知道如何为我的自定义控件指定一个选择器。
如果我在 XAML 中设置控件样式,我需要导入一个命名空间并使用它:
xmlns:ctrls="clr-namespace:DemoApp.Controls"
...
<Style TargetType="ctrls:MyControl"...
CSS 也支持命名空间:
@namespace ctlrs "clr-namespace:DemoApp.Controls";
但是,如果我尝试编写 CSS 规则...
ctrls|MyControl {
margin: 10;
}
...我收到 System.NotSupportedException: 'AT-rules not supported'。
所以我想知道是否有解决方案让自定义控件使用 CSS 设置样式。
【问题讨论】:
-
你解决了吗?
标签: xamarin.forms xamarin.forms-styles