问题
I'm using a Bar Chart in the system.windows.controls.datavisualization.toolkit in a WPF/C# project. I would like to print this chart on a page, but it appears none of the binding are executed before printing. I end up with an empty square where the chart should be.
My XAML code looks like this (I've ommitted layout things)
<Grid x:Name="LayoutRoot">
<chartingToolkit:Chart x:Name="GUIchart" Style="{StaticResource TheGUIChartStyle}" FontSize="12">
<chartingToolkit:BarSeries x:Name="Series" ItemsSource="{Binding}">
<chartingToolkit:BarSeries.DependentRangeAxis>
<chartingToolkit:LinearAxis x:Name="Xaxis" Minimum="0" Maximum="100" Interval="10" ShowGridLines="True" Orientation="X"/>
</chartingToolkit:BarSeries.DependentRangeAxis>
</chartingToolkit:BarSeries>
</chartingToolkit:Chart>
</Grid>
In c# I'm adding some titels and the bindings:
// set the X-axis title
Xaxis.Title = "Score in %";
// do the binding
Series.IndependentValuePath = "Name";
Series.DependentValuePath = "Score";
Series.ItemsSource = scores;
When debugging, this binding is actually executed before the chart is being add to the page. Nevertheless, I end up with an "empty" chart.
回答1:
One possible cause for this the default fade-in animation in the chart. It is described in this forum post. You should be able to copy the default chart style from the source code and comment out the VSM animation.
You can download the source code for the latest DataVisualization development release here. Once you have the source, the file you want to look at is in the Core.WPF project - Themes\Generic.xaml. All the styles can be found there.
I have not actually tried it, but you should be able to copy the BarDataPoint style and remove the "RevealStates" VisualStateGroup.
来源:https://stackoverflow.com/questions/4080486/wpf-chart-print-system-windows-controls-datavisualization-toolkit