【问题标题】:Xamarin Form - Utilizing ResourceDictionary Style with Custom UserControlXamarin 表单 - 使用自定义 UserControl 的 ResourceDictionary 样式
【发布时间】:2017-09-12 18:02:17
【问题描述】:

我有一个自定义用户控件,用于在应用程序上使用 FontAwesome 字体,它可以正常工作。

我想在 App.xaml 的 ResourceDictionary 中使用 Style 设置控件的样式。

使用该样式的页面是:

            <StackLayout x:Name="TopStack">
            <Grid VerticalOptions="FillAndExpand" BackgroundColor="#012c50" HeightRequest="200">
                <Image Source="{local:ImageResource AAAApp.Images.navbartop.png}" Aspect="AspectFill" />
                <userControls:FontAwesomeLabel Text="{x:Static userControls:Icon.FAUserCircle}" Style="{StaticResource SideMenuNameIcon}" />
                <userControls:FontAwesomeLabel Text="{x:Static userControls:Icon.FAChevronRight}" />
                <Label Text="Name Here" Style="{StaticResource SideMenuName}" />
                <Label Text="1234567891231" Style="{StaticResource SideMenuAccount}" />
            </Grid>
        </StackLayout>

请注意,样式在常规标签上正常工作 - 绿色箭头。

当我运行应用程序时,我收到以下错误:

所以我发现问题在于样式中的 TargetType。

不过,我试过了:

  • TargetType="标签">
  • TargetType="Label.FontFamily"
  • TargetType="FontFamily">
  • TargetType="userControls:FontAwesomeLabel">
  • TargetType="userControls">
  • TargetType="FontAwesomeLabel">

结果相同。

UserControl 代码是:

我错过了什么?

谢谢!

【问题讨论】:

    标签: c# mobile xamarin.forms styles custom-controls


    【解决方案1】:

    添加

    Added xmlns:ctrls="clr-namespace:AAAApp.UserControls" to app.xaml and Change
    

    在 App.xaml 中并尝试将 TargetType 设置为

    TargetType="{x:Type ctrls:FontAwesomeLabel}"
    

    还有大约 100 种变体。同样的问题。

    还修复了设置器中的拼写错误 - 空格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-25
      • 1970-01-01
      • 2021-06-28
      • 1970-01-01
      相关资源
      最近更新 更多