0

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

  • For starters, `` should define its `ItemsSource` property, where to get points from, even before any style can be applied. – jsanalytics Apr 29 '16 at 20:38
  • @jstreet Absolutely, and in the actual code it does. I'm just concerned with the errors I'm getting, and I stripped out as much as I could without removing the errors. – Jared Windover-Kroes Apr 29 '16 at 20:40
  • But that's kind of important information, because your `DataPointStyle` is supposed to be binding to some public property belonging to the element type held by `ItemsSource`. – jsanalytics Apr 29 '16 at 21:03
  • Maybe I'm misunderstanding, but I think my DataPointStyle should be binding to the height I set on my ScrollViewer (ElementName=Testing). – Jared Windover-Kroes Apr 29 '16 at 21:07
  • I'm not going to get into why anyone would bind a `DataPoint` to a `ScrollViewer`, but i submit to you that the binding is looking for its source element within `ItemsSource` and obviously is not finding it. A clue is the `DataItem=null` in the error message. – jsanalytics Apr 29 '16 at 22:15

0 Answers0