在.NetStandard中使用WPF ResourceDictionary

时间:2019-06-29 12:41:56

标签: c# wpf xaml xamarin resourcedictionary

我有一些在WPF和ResourceDictionary中编写的样式和自定义控件。
现在我想在xamarin中使用这些样式,但是我意识到该库应该基于要安装在xamarin上的.NetStandard。

但是现在我看到ResourceDictionary不存在。

如何将WPF的代码升级到xamarin?

1 个答案:

答案 0 :(得分:1)

很遗憾,Xamarin无法使用WPF的ResourceDictionary。

您可以Create and Consume a Xamarin's ResourceDictionary,如下所示。

<Application ...>
    <Application.Resources>
        <ResourceDictionary>
            <Color x:Key="PageBackgroundColor">Yellow</Color>
            <Color x:Key="HeadingTextColor">Black</Color>
            <Color x:Key="NormalTextColor">Blue</Color>
            <Style x:Key="LabelPageHeadingStyle" TargetType="Label">
                <Setter Property="FontAttributes" Value="Bold" />
                <Setter Property="HorizontalOptions" Value="Center" />
                <Setter Property="TextColor" Value="{StaticResource HeadingTextColor}" />
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application>
相关问题