WPF LiveCharts 样式:多个图表导致第二个图表出现错误

WPF LiveCharts styling : several charts cause the second one to bug

我遇到 LiveCharts:PieMenu 的问题。 我在资源文件上为 PieChart 和 PieSeries 定义了样式,这样我所有的饼图看起来都一样。 在 UserControl 中,我使用资源字典中的资源文件并将其添加到资源中,然后创建 2 个饼图:

    <Border HorizontalAlignment="Stretch"
            Background="{StaticResource MenuBackgroundScb2}" 
            BorderThickness="2" BorderBrush="{StaticResource WidgetBorderScb}"
            Margin="0 0 0 20">
        <StackPanel HorizontalAlignment="Stretch" >
            <Label Content="Montant des offres selon leurs états" Style="{StaticResource TitleLabel}"/>
            <lc:PieChart Series="{Binding Path=AmountOfferByStatusSeriesCollection}"/>
        </StackPanel>
    </Border>
    <Border HorizontalAlignment="Stretch"
            Background="{StaticResource MenuBackgroundScb2}" 
            BorderThickness="2" BorderBrush="{StaticResource WidgetBorderScb}">
        <StackPanel HorizontalAlignment="Stretch" >
            <Label Content="Nombre d'offres selon leurs états" Style="{StaticResource TitleLabel}"/>
            <lc:PieChart Series="{Binding Path=NbOfferByStatusSeriesCollection}"  />
        </StackPanel>
    </Border>

第一个图表饼看起来不错,但第二个有问题:图例不显示,鼠标悬停会使应用程序崩溃。

这个错误出现是因为我在一个单独的资源文件中而不是在 PieChart 的资源中声明了样式,所以我知道我对系列 NbOfferByStatusSeriesCollection 没有问题。

此外,我有第三个馅饼显示在另一个页面,而不是与前两个同时显示,这个工作正常。

我做错了什么??

这是资源文件的摘录。

<Style TargetType="lc:PieChart">
    <Setter Property="Height" Value="140"/>
    <Setter Property="InnerRadius" Value="25"/>
    <Setter Property="SeriesColors" Value="{StaticResource GraphColors}" />
    <Setter Property="Foreground" Value="{StaticResource LightForegroundScb}"/>
    <Setter Property="LegendLocation" Value="Right" />
    <Setter Property="ChartLegend">
        <Setter.Value>
            <lc:DefaultLegend BulletSize="20"/>
        </Setter.Value>
    </Setter>
    <Setter Property="DataTooltip">
        <Setter.Value>
            <lc:DefaultTooltip SelectionMode="OnlySender" 
                                       Foreground="{StaticResource LightForegroundScb}"
                                       Background="{StaticResource MenuBackgroundScb2}" 
                                       BorderThickness="2"
                                       BorderBrush="{StaticResource MenuBackgroundScb}"
                                       BulletSize="20" />
        </Setter.Value>
    </Setter>
</Style>

<Style TargetType="lc:PieSeries">
    <Setter Property="Stroke" Value="{StaticResource MenuBackgroundScb2}"/>
    <Setter Property="StrokeThickness" Value="3"/>
</Style>

这是调用堆栈:

原来我必须在饼图样式之外设置默认图例和默认数据工具提示的样式,并将它们添加到饼图样式资源中:

<Style TargetType="lc:DefaultLegend" x:Key="PieChartDefaultLegend">
    <Setter Property="BulletSize" Value="20"/>
</Style>

<Style TargetType="lc:DefaultTooltip" x:Key="PieChartDefaultTooltip">
    <Setter Property="SelectionMode" Value="OnlySender"/>
    <Setter Property="Foreground" Value="{StaticResource LightForegroundScb}"/>
    <Setter Property="Background" Value="{StaticResource MenuBackgroundScb2}" />
    <Setter Property="BorderThickness" Value="2"/>
    <Setter Property="BorderBrush" Value="{StaticResource MenuBackgroundScb}"/>
    <Setter Property="BulletSize" Value="20" />
</Style>

<Style TargetType="lc:PieChart">
    <Setter Property="InnerRadius" Value="25"/>
    <Setter Property="SeriesColors" Value="{StaticResource GraphColors}" />
    <Setter Property="Foreground" Value="{StaticResource LightForegroundScb}"/>
    <Setter Property="LegendLocation" Value="Right" />
    <Style.Resources>
        <Style BasedOn="{StaticResource PieChartDefaultLegend}" TargetType="lc:DefaultLegend"/>
        <Style BasedOn="{StaticResource PieChartDefaultTooltip}" TargetType="lc:DefaultTooltip"/>
    </Style.Resources>
</Style>