Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
120
Setting XamDataChart as Content of ContentControl
posted

Hello,

I am having an issue trying to apply the following:

I have a ContentControl that can have its content modified based on a Property. So I have defined a XamDataChart inside the ContentControl Resource Dictionary and when a condition is met using a DataTrigger, the Content is set to the chart resource (You can find a sample application attached).

The problem I'm having is that the actual chart is not rendering. I can see the zoombars but not the chart. I checked if my bindings were correct, and in the output window I'm getting the following errors:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=X1'. BindingExpression:(no path); DataItem=null; target element is 'ScatterLineSeries' (Name=''); target property is 'XAxis' (type 'NumericXAxis')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=Y1'. BindingExpression:(no path); DataItem=null; target element is 'ScatterLineSeries' (Name=''); target property is 'YAxis' (type 'NumericYAxis')

I have followed the usual way of generating a XamDataChart, and if I remove the Chart from the Resource Dictionary and set it directly to the Content it works, but, of course, this is not the behavior I want.

Could this be a bug? Or I'm doing something wrong?

Thank you very much.

Regards,

Sebastian

InfragisticsChartSample.zip
  • 34510
    Offline posted

    Hi Sebastian,

    The way you have the ContentControl setup is a little unorthodox.  You could probably still make it work somehow but I wouldn't recommend doing it this way.  Instead of putting the chart and legend into the ContentControl.Resources collection, stick them inside their own DataTemplate.  Then inside your trigger, set the ContentTemplate property to this DataTemplate and make sure to set the Content property to whatever you want the DataContext for the chart to be.  So something like this:

    <DataTrigger Binding="{Binding Path=IsTextEnabled}" Value="False">
        <Setter Property="Content" Value="{Binding}"/>
        <Setter Property="ContentTemplate" Value="{StaticResource ChartTemplate}"/>
    </DataTrigger>

    I updated your sample.  Let me know if you have any questions.

    InfragisticsChartSample2.zip