【问题标题】:Use WPF ResourceDictionary in .NetStandard在 .NetStandard 中使用 WPF ResourceDictionary
【发布时间】:2019-06-29 12:41:56
【问题描述】:

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

但现在我看到 ResourceDictionary 不存在。

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

【问题讨论】:

    标签: c# wpf xaml xamarin resourcedictionary


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 2012-01-19
      • 2014-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多