回答

6

如果在工具包的源代碼中搜索「調色板」,您將看到圖表控件的默認樣式具有Palette屬性,該屬性是ResourceDictionary的集合。您可以在您的應用中以類似的方式將其應用於圖表Style或直接作爲其屬性,例如,

<charting:Chart 
    x:Name="PieChartWithCustomPalette" 
    Title="Pie Chart with Custom Palette" 
    Margin="70,0"> 
    <charting:Chart.Palette> 
     <charting:ResourceDictionaryCollection> 
      <!-- Blue --> 
      <ResourceDictionary> 
       <SolidColorBrush 
        x:Key="Background" 
        Color="#4586d8" /> 
       <Style 
        x:Key="DataPointStyle" 
        TargetType="Control"> 
        <Setter 
         Property="Background" 
         Value="{StaticResource Background}" /> 
       </Style> 
       <Style 
        x:Key="DataShapeStyle" 
        TargetType="Shape"> 
        <Setter 
         Property="Stroke" 
         Value="{StaticResource Background}" /> 
        <Setter 
         Property="StrokeThickness" 
         Value="2" /> 
        <Setter 
         Property="StrokeMiterLimit" 
         Value="1" /> 
        <Setter 
         Property="Fill" 
         Value="{StaticResource Background}" /> 
       </Style> 
      </ResourceDictionary> 
      <!-- Red --> 
      <ResourceDictionary> 
       <SolidColorBrush 
        x:Key="Background" 
        Color="#dc443f" /> 
       <Style 
        x:Key="DataPointStyle" 
        TargetType="Control"> 
        <Setter 
         Property="Background" 
         Value="{StaticResource Background}" /> 
       </Style> 
       <Style 
        x:Key="DataShapeStyle" 
        TargetType="Shape"> 
        <Setter 
         Property="Stroke" 
         Value="{StaticResource Background}" /> 
        <Setter 
         Property="StrokeThickness" 
         Value="2" /> 
        <Setter 
         Property="StrokeMiterLimit" 
         Value="1" /> 
        <Setter 
         Property="Fill" 
         Value="{StaticResource Background}" /> 
       </Style> 
      </ResourceDictionary> 
     </charting:ResourceDictionaryCollection> 
    </charting:Chart.Palette> 
    <charting:Chart.Series> 
     <Series:PieSeries 
      Title="Population" 
      ItemsSource="{Binding Items}" 
      IndependentValueBinding="{Binding Name}" 
      DependentValueBinding="{Binding Value}" 
      IsSelectionEnabled="True" /> 
    </charting:Chart.Series> 
</charting:Chart> 

我將此添加到示例項目以供將來參考。

enter image description here