2

我正在使用来自 Zag 工作室的文章使用带有标签的 WPF 饼图。此图表每 1 分钟刷新一次新值。它工作得很好,但是为什么每次刷新时饼片的颜色都会改变?是否有任何可能的方法来设置默认颜色。我显示的饼图只有两个切片。

我尝试过的,

 <customControls:LabeledPieChart>
  <customControls:LabeledPieChart.Palette>
   <dv:ResourceDictionaryCollection>
   <ResourceDictionary>                                               
     <Style TargetType="dvc:PieDataPoint">
     <Setter Property="Background" Value="Green"/>
     </Style>
    <Style TargetType="dvc:PieDataPoint">
   <Setter Property="Background" Value="Purple"/>
    </Style>
  </ResourceDictionary>
  </dv:ResourceDictionaryCollection>
 </customControls:LabeledPieChart.Palette>
 </customControls:LabeledPieChart> 

上面的代码片段返回异常为

'设置属性'System.Windows.ResourceDictionary.DeferrableContent' 引发异常。

任何机构都可以提供帮助吗?谢谢。

4

1 回答 1

6

在这篇文章的帮助下,我自己解决了这个问题

这是解决方案

  <!--to set the Pie slice color-->
  <SolidColorBrush x:Key="color1" Color="Maroon" />
  <SolidColorBrush x:Key="color2" Color="DarkBlue" />

  <!--Pie Palette-->
  <customControls:LabeledPieChart.Palette>
    <dv:ResourceDictionaryCollection>
      <ResourceDictionary>
        <Style x:Key="DataPointStyle" TargetType="Control" >
          <Setter Property="Background" Value="{StaticResource color1}"/>
        </Style>
      </ResourceDictionary>
      <ResourceDictionary>
        <Style x:Key="DataPointStyle" TargetType="Control" >
          <Setter Property="Background" Value="{StaticResource color2}"/>
        </Style>
      </ResourceDictionary>
    </dv:ResourceDictionaryCollection>
  </customControls:LabeledPieChart.Palette>
于 2013-05-21T10:45:37.370 回答