【问题标题】:Xamarin.Forms: Setting Style in a ClassXamarin.Forms:在类中设置样式
【发布时间】:2018-08-22 18:48:35
【问题描述】:

我有这个 XAML,我正在尝试将其转换为自定义控件:

这个作品:

 <Label Style="{StaticResource MaterialFontIcon}" />

我在下面写了这个,但风格没有通过:

public class MaterialLabel: Label
{
    public MaterialLabel()
    {
        this.Style = {How to access a app.xaml defined style}???;
    }

参考:

 <me:MaterialLabel Style="{StaticResource MaterialFontIcon}" />

【问题讨论】:

  • Style 和 StyleClass 是两个不同的东西,对吧?
  • 如果它在您的 App.xaml 中,您可以使用 this.Style = Application.Current.Resources["MaterialFontIcon"] as Style;

标签: xamarin xamarin.forms


【解决方案1】:

解决方案是 this.Style = (Style)Application.Current.Resources["MaterialFontIcon"]; 。微软在他们的文档here 中展示了这一点。确保浏览文档,那里有一些很好的信息。

【讨论】:

    【解决方案2】:

    来自瑞克

     this.Style = Application.Current.Resources["MaterialFontIcon"] as Style;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-14
      • 2020-07-06
      • 1970-01-01
      • 1970-01-01
      • 2018-12-15
      • 1970-01-01
      • 2018-07-06
      • 1970-01-01
      相关资源
      最近更新 更多