Jump to content
Software FX Community

Data Binding Exception


nabils

Recommended Posts

I am trying to bind to an IEnumerable<T> using chart.ItemsSource = data where data is the IEnumerable<T>. The xaml I am using is:

 <cfx:Chart Gallery="Pie" Name="chart">

<cfx:SeriesAttributes BindingPath="{Binding Path=Value}"/>

</cfx:Chart>

As soon as the chart.ItemsSource = data line is executed I get a recurring exception which hangs the whole application (see below). What am I doing wrong?

 Thanks

System.NullReferenceException: Object reference not set to an instance of an object.

at k.a(Object A_0, Type A_1, String A_2)

at at.a(Object A_0, Object A_1, Type A_2, Int32 A_3)

at cb.a(Object A_0, Object A_1, Type A_2, Int32 A_3)

at ChartFX.WPF.DataValues.a(IEnumerable A_0, Int32 A_1, Int32 A_2, NotifyCollectionChangedAction A_3, IIndexedCollection`1 A_4, ah A_5)

at ChartFX.WPF.DataValues.a(IEnumerable A_0, Int32 A_1, Int32 A_2, NotifyCollectionChangedAction A_3, ah A_4)

at ChartFX.WPF.DataValues.a(ah A_0)

at ChartFX.WPF.Chart.at()

at ChartFX.WPF.Chart.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at System.Windows.Controls.Border.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at System.Windows.Controls.Control.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at System.Windows.Controls.Border.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at System.Windows.Controls.Control.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at System.Windows.Controls.Border.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at System.Windows.Controls.Control.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)

at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)

at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at System.Windows.Controls.Border.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at System.Windows.Controls.Grid.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

at System.Windows.UIElement.Measure(Size availableSize)

at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)

at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)

at System.Windows.FrameworkElement.MeasureCore(Size availableSize)

Link to comment
Share on other sites

xmlns:cfxData="clr-namespace:ChartFX.WPF.Data;assembly=ChartFX.WPF.Data" 

<

Page.Resources>  <XmlDataProvider x:Key="myXmlData">   <x:XData>   <Elems xmlns="">   <Elem Product="CocaCola" Image="pack://siteoforigin:,,,/Img/CocaCola.png" Month="Jan" Sales="12"/>   <Elem Product="Pepsi" Image="pack://siteoforigin:,,,/Img/Pepsi.png" Month="Jan" Sales="10"/>   <Elem Product="Pepsi" Image="pack://siteoforigin:,,,/Img/Pepsi.png" Month="Jan" Sales="1"/>   <Elem Product="Pepsi" Image="pack://siteoforigin:,,,/Img/Pepsi.png" Month="Feb" Sales="8"/>   <Elem Product="CocaCola" Image="pack://siteoforigin:,,,/Img/CocaCola.png" Month="Feb" Sales="14"/>   <Elem Product="Pepsi" Image="pack://siteoforigin:,,,/Img/Pepsi.png" Month="Mar" Sales="9"/>   <Elem Product="CocaCola" Image="pack://siteoforigin:,,,/Img/CocaCola.png" Month="Mar" Sales="13"/>   <Elem Product="Sprite" Image="pack://siteoforigin:,,,/Img/Sprite.png" Month="Mar" Sales="5"/>   </Elems>   </x:XData>  </XmlDataProvider>  <DataTemplate x:Key="productTemplate">   <StackPanel Orientation="Horizontal">   <Image Source="{Binding XPath=@Image}" Width="24" Height="24"/>   <TextBlock Text="{Binding XPath=@Product}" Margin="2,0" VerticalAlignment="Center"/>   </StackPanel>  </DataTemplate></Page.Resources>

<

cfx:Chart Gallery="Bar" x:Name="chart1">  <cfx:Chart.ItemsSource>   <Binding Source="{StaticResource myXmlData}" XPath="Elems/Elem" />  </cfx:Chart.ItemsSource>  <cfx:Chart.DataTransforms>   <cfxData:CrosstabTransform RowPath="@Month" ColumnPath="@Product" ValuePath="@Sales" Sorted="true"/>  </cfx:Chart.DataTransforms>  <cfx:Chart.AllSeries>   <cfx:AllSeriesAttributes ContentTemplate="{Binding Source={StaticResource productTemplate}}"/>  </cfx:Chart.AllSeries></cfx:Chart>

In this sample we are using the image in the data as part of the series content which will be shown in both tooltips and in the legendbox.

Regards,

JuanC

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...