在 .NetStandard 中使用 WPF ResourceDictionary
Use WPF ResourceDictionary in .NetStandard
我在 WPF 和 ResourceDictionary 中编写了一些样式和自定义控件。
现在我想在 xamarin 中使用这些样式,但我意识到该库应该基于 .NetStandard 才能安装在 xamarin 上。
但现在我看到 ResourceDictionary 不存在。
如何将我的 WPF 代码升级到 xamarin?
不幸的是,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>
我在 WPF 和 ResourceDictionary 中编写了一些样式和自定义控件。
现在我想在 xamarin 中使用这些样式,但我意识到该库应该基于 .NetStandard 才能安装在 xamarin 上。
但现在我看到 ResourceDictionary 不存在。
如何将我的 WPF 代码升级到 xamarin?
不幸的是,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>