将样式应用于自定义渲染器中的控件

Apply style to control in custom renderer

我想将样式应用于控件。这是风格

<Application.Resources>
    <ResourceDictionary>
        <SolidColorBrush x:Key="BackgroundColor" Color="Yellow" />

        <Style TargetType="Button" x:Name="myNewButtonStyle">
            <Setter Property="Background" Value="{StaticResource BackgroundColor}" />
        </Style>
    </ResourceDictionary>
</Application.Resources>

,可以在 App.xaml(UWP 项目)中找到。这是自定义渲染器:

protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
    base.OnElementChanged(e);

    if (this.Element != null)
    {
        var style = Windows.UI.Xaml.Application.Current.Resources["myNewButtonStyle"] as Windows.UI.Xaml.Style;
        this.Control.Style = style;
    }
}

这个想法是基于。但是没有应用样式。在代码中设置背景颜色确实有效:

this.Control.BackgroundColor = new SolidColorBrush(Windows.UI.Colors.Yellow);

如何将样式应用到自定义呈现器中的控件?

我已经填写了错误报告。它应该在即将发布的版本之一 (> XF 2.3.3.166-pre4) 中得到修复。