Chart binding errors in multiple documents within one Docking site

Charts for WPF Forum

Posted 2 months ago by Moreno
Version: 23.1.4
Avatar

Good morning, I have binding errors when I use XYChart in multiple document windows within one Docking site.

In a Docking site I created two documents that draw the exact same chart.
Here is a test code that shows the issue:

    <docking:DockSite>
            <docking:Workspace>
                <docking:TabbedMdiHost>
                    <docking:TabbedMdiContainer>
                        <docking:DocumentWindow Title="Chart1">
                                <charts:XYChart>
                                    <charts:XYChart.YAxes>
                                        <charts:XYDoubleAxis x:Name="yAxis1" AreMajorTicksVisible="True"/>
                                        <charts:XYDoubleAxis x:Name="yAxis2" AreMajorTicksVisible="True"/>
                                    </charts:XYChart.YAxes>
                                    <charts:XYChart.XAxes>
                                        <charts:XYDoubleAxis x:Name="xAxis" AreMajorTicksVisible="True" Title="ms"/>
                                    </charts:XYChart.XAxes>
                                    <charts:LineSeries
                                        XAxis="{Binding ElementName=xAxis}" YAxis="{Binding ElementName=yAxis1}"
                                        ItemsSource="{Binding Path=VelocityFeedForward}"  XPath="Time" YPath="Value"/>
                                    <charts:LineSeries
                                        XAxis="{Binding ElementName=xAxis}" YAxis="{Binding ElementName=yAxis2}"
                                        ItemsSource="{Binding Path=FeedbackVelocity}" XPath="Time" YPath="Value"/>
                                </charts:XYChart>
                        </docking:DocumentWindow>
                        <docking:DocumentWindow Title="Chart2">
                            <charts:XYChart>
                                <charts:XYChart.YAxes>
                                    <charts:XYDoubleAxis x:Name="yAxis11" AreMajorTicksVisible="True"/>
                                    <charts:XYDoubleAxis x:Name="yAxis12" AreMajorTicksVisible="True"/>
                                </charts:XYChart.YAxes>
                                <charts:XYChart.XAxes>
                                    <charts:XYDoubleAxis x:Name="xAxis1" AreMajorTicksVisible="True" Title="ms"/>
                                </charts:XYChart.XAxes>
                                <charts:LineSeries
                                        XAxis="{Binding ElementName=xAxis1}" YAxis="{Binding ElementName=yAxis11}"
                                        ItemsSource="{Binding Path=VelocityFeedForward}"  XPath="Time" YPath="Value"/>
                                <charts:LineSeries
                                        XAxis="{Binding ElementName=xAxis1}" YAxis="{Binding ElementName=yAxis12}"
                                        ItemsSource="{Binding Path=FeedbackVelocity}" XPath="Time" YPath="Value"/>
                            </charts:XYChart>
                        </docking:DocumentWindow>
                    </docking:TabbedMdiContainer>
                </docking:TabbedMdiHost>
            </docking:Workspace>
    </docking:DockSite>

Here the runtime errors:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=xAxis1'. BindingExpression:(no path); DataItem=null; target element is 'LineSeries' (Name=''); target property is 'XAxis' (type 'XYAxisBase')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=yAxis11'. BindingExpression:(no path); DataItem=null; target element is 'LineSeries' (Name=''); target property is 'YAxis' (type 'XYAxisBase')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=xAxis1'. BindingExpression:(no path); DataItem=null; target element is 'LineSeries' (Name=''); target property is 'XAxis' (type 'XYAxisBase')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=yAxis12'. BindingExpression:(no path); DataItem=null; target element is 'LineSeries' (Name=''); target property is 'YAxis' (type 'XYAxisBase')

If I simply swap the order of the document windows, first Chart2 and then Chart1:

                <docking:TabbedMdiContainer>
                    <docking:DocumentWindow Title="Chart2">
                        <charts:XYChart>
                            <charts:XYChart.YAxes>
                                <charts:XYDoubleAxis x:Name="yAxis11" AreMajorTicksVisible="True"/>
                                <charts:XYDoubleAxis x:Name="yAxis12" AreMajorTicksVisible="True"/>
                            </charts:XYChart.YAxes>
                            <charts:XYChart.XAxes>
                                <charts:XYDoubleAxis x:Name="xAxis1" AreMajorTicksVisible="True" Title="ms"/>
                            </charts:XYChart.XAxes>
                            <charts:LineSeries
                                        XAxis="{Binding ElementName=xAxis1}" YAxis="{Binding ElementName=yAxis11}"
                                        ItemsSource="{Binding Path=VelocityFeedForward}"  XPath="Time" YPath="Value"/>
                            <charts:LineSeries
                                        XAxis="{Binding ElementName=xAxis1}" YAxis="{Binding ElementName=yAxis12}"
                                        ItemsSource="{Binding Path=FeedbackVelocity}" XPath="Time" YPath="Value"/>
                        </charts:XYChart>
                    </docking:DocumentWindow>
                    <docking:DocumentWindow Title="Chart1">
                        <charts:XYChart>
                            <charts:XYChart.YAxes>
                                <charts:XYDoubleAxis x:Name="yAxis1" AreMajorTicksVisible="True"/>
                                <charts:XYDoubleAxis x:Name="yAxis2" AreMajorTicksVisible="True"/>
                            </charts:XYChart.YAxes>
                            <charts:XYChart.XAxes>
                                <charts:XYDoubleAxis x:Name="xAxis" AreMajorTicksVisible="True" Title="ms"/>
                            </charts:XYChart.XAxes>
                            <charts:LineSeries
                                        XAxis="{Binding ElementName=xAxis}" YAxis="{Binding ElementName=yAxis1}"
                                        ItemsSource="{Binding Path=VelocityFeedForward}"  XPath="Time" YPath="Value"/>
                            <charts:LineSeries
                                        XAxis="{Binding ElementName=xAxis}" YAxis="{Binding ElementName=yAxis2}"
                                        ItemsSource="{Binding Path=FeedbackVelocity}" XPath="Time" YPath="Value"/>
                        </charts:XYChart>
                    </docking:DocumentWindow>
                </docking:TabbedMdiContainer>

Now I have these runtime errors:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=xAxis'. BindingExpression:(no path); DataItem=null; target element is 'LineSeries' (Name=''); target property is 'XAxis' (type 'XYAxisBase')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=yAxis1'. BindingExpression:(no path); DataItem=null; target element is 'LineSeries' (Name=''); target property is 'YAxis' (type 'XYAxisBase')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=xAxis'. BindingExpression:(no path); DataItem=null; target element is 'LineSeries' (Name=''); target property is 'XAxis' (type 'XYAxisBase')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=yAxis2'. BindingExpression:(no path); DataItem=null; target element is 'LineSeries' (Name=''); target property is 'YAxis' (type 'XYAxisBase')

Alone the Chart1 and Chart2 documents do not give errors and work while when both are present the second document gives binding errors.

If necessary, here is the code that generates the charts data:

public class GraphicPoint
{
    public double Time { get; set; }
    public double Value { get; set; }
}

public GraphicPoint[] VelocityFeedForward { get; private set; }
double[]? velocityFeedForward = new double[] { 636.619583, 636.619583, 1909.858710, 1909.858710, 3183.097648, 3183.097648, 4456.336889, 4456.336889, 5729.580380, 5729.580380, 7002.822960, 7002.822960, 8276.061898, 8276.061898, 9549.300835, 9549.300835, 10822.539773, 10822.539773, 12095.779318, 12095.779318, 13369.017648, 13369.017648, 14642.258407, 14642.258407, 15915.496738, 15915.496738, 17188.738711, 17188.738711, 18461.980684, 18461.980684, 19735.221443, 19735.221443, 21008.462202, 21008.462202, 22281.699318, 22281.699318, 23554.938863, 23554.938863, 24828.178408, 24828.178408, 26101.417953, 26101.417953, 27374.657497, 27374.657497, 28647.899471 };

public GraphicPoint[] FeedbackVelocity { get; private set; }
double[]? feedbackVelocity = new double[] { 494.519129, 307.720930, 252.780198, -703.186644, -538.364655, 1516.414922, -241.685409, 65.982208, 208.827797, 494.518901, 153.886894, -175.756856, -769.115652, 648.352595, 131.910580, 296.732560, -175.756932, -1054.807059, 714.281224, -384.531302, 1318.628277, -1417.415124, 615.388357, 252.780103, -549.353102, 1120.842163, -296.626198, -2032.750357, -197.733142, 219.815826, 1285.664114, -1450.379438, -933.937300, 714.281679, -362.554713, 1043.925506, -1087.771222, 230.803969, 791.198565, 2538.310639, -505.400531, -351.566760, 54.993989, 142.898932, 571.436014 };

private void Init()
{
    int i;
    double time = 0;
    int len = velocityFeedForward!.Length;
    VelocityFeedForward = new GraphicPoint[len];
    for (i = 0; i < len; i++)
    {
        VelocityFeedForward[i] = new GraphicPoint { Time = time, Value = velocityFeedForward[i] };
        time += 0.5;
    }

    velocityFeedForward = null;

    time = 0;
    len = feedbackVelocity!.Length;
    FeedbackVelocity = new GraphicPoint[len];
    for (i = 0; i < len; i++)
    {
        FeedbackVelocity[i] = new GraphicPoint { Time = time, Value = feedbackVelocity[i] };
        time += 0.5;
    }

    feedbackVelocity = null;
}

Comments (2)

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I think what's happening here is that the chart doesn't build up its element hierarchy in code until its template is applied.  However for the chart that is not loaded into the visual tree, that causes the element name references to temporarily fail (thereby causing the binding error output) until it does enter the visual tree at a later time.  At that point, the bindings should be found and work.

You might be able to work around this by using x:Reference instead of ElementName:

XAxis="{Binding Source={x:Reference xAxis}}"


Actipro Software Support

Posted 2 months ago by Moreno
Avatar

The workaround resolved the issue. Thank you.

The latest build of this product (v24.1.2) was released 5 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.