0

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

<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')

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

4

0 回答 0