Charts WPF工具包图表don';t显示我是否更改.NET 4中数据点的ControlTemplate

Charts WPF工具包图表don';t显示我是否更改.NET 4中数据点的ControlTemplate,charts,tooltip,wpftoolkit,controltemplate,Charts,Tooltip,Wpftoolkit,Controltemplate,在.NET4环境中,我遇到了一个非常奇怪的WPF工具包图表问题。 基本上,我只想自定义ColumnDataPoints的工具提示模板。为此,我将toolkit源代码(generic.xaml)中ColumnDataPoint的默认样式复制到我的控件资源中,并将TooltipService部分更改为: <UserControl.Resources> <Style TargetType="charts:ColumnDataPoint" x:Key="CustomDataPointS

在.NET4环境中,我遇到了一个非常奇怪的WPF工具包图表问题。 基本上,我只想自定义ColumnDataPoints的工具提示模板。为此,我将toolkit源代码(generic.xaml)中ColumnDataPoint的默认样式复制到我的控件资源中,并将TooltipService部分更改为:

<UserControl.Resources>
<Style TargetType="charts:ColumnDataPoint" x:Key="CustomDataPointStyle">
    <Setter Property="Background" Value="Orange" />
    <Setter Property="BorderBrush" Value="Black" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="charts:ColumnDataPoint">
                <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Opacity="0" x:Name="Root">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.1" />
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Normal" />
                            <VisualState x:Name="MouseOver">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="MouseOverHighlight" Storyboard.TargetProperty="Opacity" To="0.6" Duration="0" />
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="SelectionStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.1" />
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Unselected" />
                            <VisualState x:Name="Selected">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="SelectionHighlight" Storyboard.TargetProperty="Opacity" To="0.6" Duration="0" />
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="RevealStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.5" />
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Shown">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Hidden">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="0" Duration="0" />
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Grid Background="{TemplateBinding Background}">
                        <Rectangle>
                            <Rectangle.Fill>
                                <LinearGradientBrush>
                                    <GradientStop Color="#77ffffff" Offset="0" />
                                    <GradientStop Color="#00ffffff" 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>
                    <ToolTipService.ToolTip>
                        <StackPanel>
                            <ContentControl Content="Custom ToolTip" FontWeight="Bold"/>
                            <ContentControl Content="{TemplateBinding FormattedDependentValue}"/>
                        </StackPanel>
                    </ToolTipService.ToolTip>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

现在的问题是,只要我应用CustomDataPointStyle(即使我不做任何更改!),ColumnSeries就不会显示在我的图表中

<Grid x:Name="ChartGrid" DataContext="{Binding}">
<charts:Chart x:Name="Chart1" Margin="5,0,0,0"
    VerticalAlignment="Stretch" HorizontalAlignment="Stretch"                       
    Title="{Binding Path=Title}">
    <charts:Chart.Axes>
        <charts:CategoryAxis Orientation="X" Title="{Binding Path=XAxisTitle}" Location="Bottom" />
        <charts:CategoryAxis Orientation="Y" Title="{Binding Path=YAxisTitle}" Location="Right" ShowGridLines="True" />
    </charts:Chart.Axes>

    <charts:ColumnSeries x:Name="ColumnSeries" Title="{Binding Path=SeriesTitle}"
                ItemsSource="{Binding Path=Data}" DataPointStyle="{StaticResource CustomDataPointStyle}"
                DependentValueBinding="{Binding Path=Value}" IndependentValueBinding="{Binding Path=Key}">
    </charts:ColumnSeries>
</charts:Chart>

结果如下:


我想我缺少了一个VisualState或一些实际呈现图表的东西,但既然我复制了(!)原始样式,那怎么可能呢?工具包是为.NET 3.5设计的,我必须在我的应用程序中使用.NET 4,这可能是原因吗?

哦,天哪,我找到了答案:我用4.0版本替换了.NET 3.5的System.Windows.DataVisualization.Toolkit.dll,现在它可以工作了

您也可以尝试在边框样式块中设置Opacity=“1”:


是的,我通过替换
System.Windows.DataVisualization.Toolkit.dll