WPFToolkit覆盖ColumnDataPoint模板

时间:2014-05-02 19:52:03

标签: c# wpf .net-4.5

我正在使用 WPF Tookit http://wpf.codeplex.com/)并使用图表控件使用 ColumnSeries 制作柱形图。我正在尝试覆盖默认的 ColumnDataPoint 样式,但是当我运行应用程序时,列不再呈现,我看到“ System.NotSupportedException ”和“调试输出日志中的System.Xaml.XamlObjectWriterException “。我做错了什么或是过时的 WPF工具包的问题?谢谢。

包括:

xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"

图表:

<chartingToolkit:Chart  Name="columnChart" Title="Results" >
     <chartingToolkit:ColumnSeries DataPointStyle="{DynamicResource ModernColumnStyle}" DependentValuePath="Count" IndependentValuePath="Method" ItemsSource="{Binding Results}" />
</chartingToolkit:Chart>

资源风格:

只有我从原始来源做的改变是我删除了VisualStateManager的东西

<Grid.Resources>
    <Style TargetType="chartingToolkit:ColumnDataPoint" x:Key="ModernColumnStyle" BasedOn="{StaticResource {x:Type chartingToolkit:ColumnDataPoint}}">
            <Setter Property="Template">
                <Setter.Value>
                <ControlTemplate TargetType="chartingToolkit:ColumnDataPoint">
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Opacity="0" x:Name="Root">
                        <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>
                        </Grid>
                        <ToolTipService.ToolTip>
                            <ContentControl Content="{TemplateBinding FormattedDependentValue}" />
                        </ToolTipService.ToolTip>
                    </Border>
                </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
</Grid.Resources>

1 个答案:

答案 0 :(得分:0)

也许您应该将“DynamicResource”更改为“StaticResource”,如下所示:

<chartingToolkit:ColumnSeries DataPointStyle="{StaticResource ModernColumnStyle}" DependentValuePath="Count" IndependentValuePath="Method" ItemsSource="{Binding Results}" />