WPF图表中的绑定错误

时间:2016-04-29 14:57:12

标签: wpf data-binding datavisualization.toolkit

我正在尝试解决一些实际上没有影响我的应用程序功能的数据绑定错误。我已将问题简化为以下内容:

<Window x:Class="Testing.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:local="clr-namespace:Testing"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <ScrollViewer Height="40" x:Name="Testing">
        <chartingToolkit:Chart Name="Chart" Width="Auto">
            <chartingToolkit:Chart.Series>
                <chartingToolkit:BarSeries >
                    <chartingToolkit:BarSeries.DataPointStyle>
                        <Style TargetType="chartingToolkit:BarDataPoint">
                            <Setter Property="Height" Value="{Binding Path=Height, ElementName=Testing}"
                                PresentationTraceSources.TraceLevel="High"/>
                        </Style>
                    </chartingToolkit:BarSeries.DataPointStyle>
                </chartingToolkit:BarSeries>
            </chartingToolkit:Chart.Series>
        </chartingToolkit:Chart>
    </ScrollViewer>
</Grid>
</Window>

会产生以下错误:

System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Height; DataItem=null; target element is 'BarDataPoint' (Name=''); target property is 'Height' (type 'Double')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Height; DataItem=null; target element is 'BarDataPoint' (Name=''); target property is 'Height' (type 'Double')
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Height; DataItem=null; target element is 'BarDataPoint' (Name=''); target property is 'Height' (type 'Double')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=Testing'. BindingExpression:Path=Height; DataItem=null; target element is 'BarDataPoint' (Name=''); target property is 'Height' (type 'Double')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=Testing'. BindingExpression:Path=Height; DataItem=null; target element is 'BarDataPoint' (Name=''); target property is 'Height' (type 'Double')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=Testing'. BindingExpression:Path=Height; DataItem=null; target element is 'BarDataPoint' (Name=''); target property is 'Height' (type 'Double')

我对解决方法不感兴趣,而是理解为什么我所做的事情是错误的。 在实际应用中,(略有不同)数据绑定仍然会产生这些错误,但也能正常工作。我怀疑图表库中有一些东西将样式应用到可视树之外的某些数据点,但我不确定如何进一步调查,因为我无法访问Charting源代码(这里有)有些在codeplex上,但它看起来已经过时了,因为我找不到DataPointStyle属性。)

0 个答案:

没有答案