如何在WPF饼图中为饼图切片设置默认颜色

时间:2013-05-21 09:56:00

标签: c# wpf xaml wpf-controls wpftoolkit

我使用来自Zag studio的文章使用带有标签的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'   抛出异常。

任何人都可以帮忙吗?感谢。

1 个答案:

答案 0 :(得分:6)

我已经在post

的帮助下解决了这个问题

这是解决方案

  <!--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>
相关问题