【问题标题】:How to set a default color to the Pie slices in WPF Pie chart如何为 WPF 饼图中的饼图设置默认颜色
【发布时间】:2013-05-21 09:55:59
【问题描述】:

我正在使用来自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> 

上面的 sn-p 返回异常为

'设置属性'System.Windows.ResourceDictionary.DeferrableContent' 抛出异常。

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

【问题讨论】:

    标签: c# wpf xaml wpf-controls wpftoolkit


    【解决方案1】:

    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多