Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将DVC:Chart中列系列的条形背景更改为红色?_C#_Visual Studio_Charts_Wpf Controls_Wpftoolkit - Fatal编程技术网

C# 如何将DVC:Chart中列系列的条形背景更改为红色?

C# 如何将DVC:Chart中列系列的条形背景更改为红色?,c#,visual-studio,charts,wpf-controls,wpftoolkit,C#,Visual Studio,Charts,Wpf Controls,Wpftoolkit,您好,我正在下载Microsoft wpftoolkit,使用图表控件绘制columnseries图形。 我可以使用我的数据绘制图形,但条形图的背景色没有改变。如何将条形图的颜色改为红色,而不是默认的LightSteelBlue颜色。 这是我的密码 <Window x:Class="net.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.mi

您好,我正在下载Microsoft wpftoolkit,使用图表控件绘制columnseries图形。 我可以使用我的数据绘制图形,但条形图的背景色没有改变。如何将条形图的颜色改为红色,而不是默认的LightSteelBlue颜色。 这是我的密码

<Window x:Class="net.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:DV="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
Title="Window1" Height="800" Width="800" xmlns:my="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit">
<Grid>
       <DVC:Chart Canvas.Top="80" Canvas.Left="10" Name="mcChart"
        Width="800" Height="450" FontSize="12"
        Background="DarkGray" Foreground="DarkRed">
        <DVC:Chart.Series>
            <DVC:ColumnSeries x:Name="Barchart" Title="Students"
               ItemsSource="{Binding list}" 
               IndependentValueBinding="{Binding Path=Name}"
               DependentValueBinding="{Binding Path=students}" >
            </DVC:ColumnSeries> 
        </DVC:Chart.Series>
     </DVC:Chart>
</Grid>

有人能告诉我怎么做吗

提前谢谢。
请回答此问题。

为了解决此问题,您可以覆盖样式

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit">

  <!-- Resource dictionary entries should be defined here. -->
  <Style x:Key="MyColumnDataPointStyle"
         TargetType="{x:Type chartingToolkit:ColumnDataPoint}">
    <Setter Property="Background"
            Value="Red" />
    <Setter Property="BorderBrush"
            Value="Black" />
    <Setter Property="BorderThickness"
            Value="1" />
    <Setter Property="IsTabStop"
            Value="False" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type chartingToolkit:ColumnDataPoint}">

          <Border x:Name="Root"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}">
            <Border.ToolTip>
              <ContentControl Content="{TemplateBinding FormattedDependentValue}" />
            </Border.ToolTip>
            <Grid Background="{TemplateBinding Background}">
              <Rectangle>
                <Rectangle.Fill>
                  <LinearGradientBrush>
                    <GradientStop Color="#77FFFFFF"
                                  Offset="0" />
                    <GradientStop Color="Transparent"
                                  Offset="1" />
                  </LinearGradientBrush>
                </Rectangle.Fill>
              </Rectangle>
              <Border BorderBrush="#CCFFFFFF"
                      BorderThickness="1">
                <Border BorderBrush="#77FFFFFF"
                        BorderThickness="1" />
              </Border>
              <Rectangle x:Name="SelectionHighlight"
                         Fill="Red"
                         Opacity="0" />
              <Rectangle x:Name="MouseOverHighlight"
                         Fill="White"
                         Opacity="0" />
            </Grid>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>

用法



希望这对您有所帮助…

为了解决此问题,您可以覆盖样式

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit">

  <!-- Resource dictionary entries should be defined here. -->
  <Style x:Key="MyColumnDataPointStyle"
         TargetType="{x:Type chartingToolkit:ColumnDataPoint}">
    <Setter Property="Background"
            Value="Red" />
    <Setter Property="BorderBrush"
            Value="Black" />
    <Setter Property="BorderThickness"
            Value="1" />
    <Setter Property="IsTabStop"
            Value="False" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type chartingToolkit:ColumnDataPoint}">

          <Border x:Name="Root"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}">
            <Border.ToolTip>
              <ContentControl Content="{TemplateBinding FormattedDependentValue}" />
            </Border.ToolTip>
            <Grid Background="{TemplateBinding Background}">
              <Rectangle>
                <Rectangle.Fill>
                  <LinearGradientBrush>
                    <GradientStop Color="#77FFFFFF"
                                  Offset="0" />
                    <GradientStop Color="Transparent"
                                  Offset="1" />
                  </LinearGradientBrush>
                </Rectangle.Fill>
              </Rectangle>
              <Border BorderBrush="#CCFFFFFF"
                      BorderThickness="1">
                <Border BorderBrush="#77FFFFFF"
                        BorderThickness="1" />
              </Border>
              <Rectangle x:Name="SelectionHighlight"
                         Fill="Red"
                         Opacity="0" />
              <Rectangle x:Name="MouseOverHighlight"
                         Fill="White"
                         Opacity="0" />
            </Grid>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>

用法



希望这对您有所帮助…

在DataPointStyle中只设置后台属性也会起作用

资源:

<Style x:Key="RedColumnDataPointStyle"
       TargetType="{x:Type DVC:ColumnDataPoint}">
    <Setter Property="Background" Value="Red" />
</Style>

用法:

  <DVC:ColumnSeries x:Name="Barchart"
                    DataPointStyle="{StaticResource RedColumnDataPointStyle}"
                    Title="Students"
                    ItemsSource="{Binding list}"
                    IndependentValueBinding="{Binding Path=Name}"
                    DependentValueBinding="{Binding Path=students}">
  </DVC:ColumnSeries>

仅在DataPointStyle中设置背景属性也会起作用

资源:

<Style x:Key="RedColumnDataPointStyle"
       TargetType="{x:Type DVC:ColumnDataPoint}">
    <Setter Property="Background" Value="Red" />
</Style>

用法:

  <DVC:ColumnSeries x:Name="Barchart"
                    DataPointStyle="{StaticResource RedColumnDataPointStyle}"
                    Title="Students"
                    ItemsSource="{Binding list}"
                    IndependentValueBinding="{Binding Path=Name}"
                    DependentValueBinding="{Binding Path=students}">
  </DVC:ColumnSeries>


ColumnSerie.DataPointStyle非ColumnSerie.StyleColumnSerie.DataPointStyle非ColumnSerie.Style