Skip to main content

Microsoft Silverlight

Answered Question "Value cannot be null. Parameter name: id" problem with Bubble seriesRSS Feed

(0)

giggs123
giggs123

Member

Member

10 points

35 Posts

"Value cannot be null. Parameter name: id" problem with Bubble series

Hi I have a problem with the bubble chart, using the sliverlight toolkit in a wpf app. I get the following error "Value cannot be null. Parameter name: id" when selecting a bubble.

I attach the source code, any ideas? Thanks

 

<Window x:Class="WpfApplication2.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:chartingprimitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit"
		Title="Window1" 
		Height="600" 
		Width="600">
	<DockPanel>
		<Button Content="Update"
				DockPanel.Dock="Right"
				Margin="5 25 5 25"
				Name="button"
				Click="button_Click" />
		<TextBlock Name="Risk"
				   DockPanel.Dock="Bottom"
				   Text="{Binding RiskLabelValue}" />
		<charting:Chart Opacity="1"
						BorderBrush="#FFFBF5F5">
			<charting:BubbleSeries IndependentValueBinding="{Binding Risk}"
				IsSelectionEnabled="True"
				DependentValueBinding="{Binding Expected2M}"
				SizeValueBinding="{Binding BubbleSize}"
				Name="bubbles"
				SelectionChanged="bubbles_SelectionChanged"
				SnapsToDevicePixels="True" 
				SelectedItem="0">
				<charting:BubbleSeries.DataPointStyle>
					<Style TargetType="Control">
						<Setter Property="Opacity"
						Value="0.8" />
						<Setter Property="Background"
						Value="Blue" />
					</Style>
				</charting:BubbleSeries.DataPointStyle>
			</charting:BubbleSeries>
		</charting:Chart>
	</DockPanel>
</Window>

 

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication2
{
	/// <summary>
	/// Interaction logic for Window1.xaml
	/// </summary>
	public partial class Window1 : Window
	{
		Random ran = new Random();


		public decimal RiskLabelValue
		{
			get { return (decimal)GetValue(RiskLabelValueProperty); }
			set { SetValue(RiskLabelValueProperty, value); }
		}

		// Using a DependencyProperty as the backing store for RiskLabelValue.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty RiskLabelValueProperty =
			DependencyProperty.Register("RiskLabelValue", 
typeof(decimal), 
typeof(Window1), 
new UIPropertyMetadata((decimal)0));



		public Window1()
		{
			InitializeComponent();
			SetData();			
		}

		private void button_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			SetData();
		}

		private void SetData()
		{
			List items = new List();

			for (int i = 0; i < 10; i++)
			{
				items.Add(new DataItem { BubbleSize = 
(ran.Next(1, 10) * 0.01), 
Risk = ran.Next(-5, 5), 
Expected2M = ran.Next(-30, 30) });
			}

			bubbles.ItemsSource = items;
		}

		private void bubbles_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (e.AddedItems.Count > 0)
			{

			}
		}
	}



	public class DataItem
	{

		public decimal Risk
		{
			get;
			set;
		}

		public decimal Expected2M
		{
			get;
			set;
		}

		public double BubbleSize
		{
			get;
			set;
		}

	}
}
 

David Anson
David Anson

Participant

Participant

1718 points

212 Posts

Microsoft
Answered Question

Re: "Value cannot be null. Parameter name: id" problem with Bubble series

Sorry for the trouble! This problem is due to a WPF-only mistake on our part. (Our apologies - but please do recall that WPF Charting hasn't had any testing yet and even isn't officially released.) To fix the problem, please open DataPointSeries.cs and change the declaration of the SelectionChangedEvent to look like the following (the bold part is new):

#if !SILVERLIGHT
        /// <summary>
        /// This event is raised when the selection is changed.
        /// </summary>
        public static readonly RoutedEvent SelectionChangedEvent =
            EventManager.RegisterRoutedEvent("SelectionChanged", RoutingStrategy.Bubble, typeof(SelectionChangedEventHandler), typeof(DataPointSeries));
#endif

You can then rebuild the WPF Charting assembly by following my directions here:

http://blogs.msdn.com/delay/archive/2009/03/26/if-they-can-build-it-they-will-come-enabling-anyone-to-compile-wpf-charting-from-the-silverlight-charting-sources.aspx

I'll check this change into our source tree shortly for inclusion with the next release of Charting. I've verified that your sample application appears to work properly with this change in place.

Thanks for your help!


http://blogs.msdn.com/delay

This posting is provided "AS IS" with no warranties, and confers no rights.

David Anson
David Anson

Participant

Participant

1718 points

212 Posts

Microsoft

Re: "Value cannot be null. Parameter name: id" problem with Bubble series

FYI, while the above should work fine, it's not implementing true RoutedEvent behavior. There'll probably be a more thorough fix sometime in the near future. When there is, I'll post about it on my blog.


http://blogs.msdn.com/delay

This posting is provided "AS IS" with no warranties, and confers no rights.

giggs123
giggs123

Member

Member

10 points

35 Posts

Re: "Value cannot be null. Parameter name: id" problem with Bubble series

Thanks David, that worked.

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities