代码之家  ›  专栏  ›  技术社区  ›  Ian Vink

表单:在类中设置样式

  •  0
  • Ian Vink  · 技术社区  · 6 年前

    我有一个试图转换为自定义控件的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}" />
    
    2 回复  |  直到 6 年前
        1
  •  0
  •   Andrew    6 年前

    解决办法是 this.Style = (Style)Application.Current.Resources["MaterialFontIcon"]; here . 一定要浏览文档,里面有一些好的信息。

        2
  •  -1
  •   Ian Vink    6 年前

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