Binding errors in WPF charting

184 views Asked by At

I'm trying to iron our some databinding errors that aren't actually effecting the functionality of my app. I've reduced the problem to the following:

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

Which generates the following errors:

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

I'm not interested in workarounds, so much as understanding why what I'm doing is wrong. In the actual application, the (slightly different) databinding still gives those errors, but also works correctly. My suspicion is that there's something going on with the charting library that applies the style to some data points outside of the visual tree, but I'm not sure how to investigate further since I don't have access to the Charting source code (there's some on codeplex but it looks out of date, as in I couldn't find the DataPointStyle property).

0

There are 0 answers