Problem changing ViewportPanel.ViewportWidthProperty?

Nov 12, 2009 at 11:39 PM
Edited Nov 12, 2009 at 11:40 PM

Hi,

I'm playing with the ColumnChartSample and so far, things are great.  One thing that I have run into is the following: the ViewportPanel.ViewportWidth is set to a default in the TemplateMarkerGenerator, but I need to change it based on a value in my data which gets calculated (based on the min and max x values I have) when the UserControl is loaded.  

<d3:ChartPlotter x:Name="plotter" Visible="0,0,1,1" Grid.ColumnSpan="2" Margin="30" SnapsToDevicePixels="True">
	<d3:ColumnChart x:Name="chart" ItemsSource="{Binding}" MarkerBuilderChanged="chart_MarkerBuilderChanged">
		<d3:TemplateMarkerGenerator Custom:SelectiveScrollingGrid.SelectiveScrollingOrientation="Horizontal">
			<DataTemplate>
				<Rectangle Fill="{d3:SelfBinding (d3:PointChartBase.Index), Converter={StaticResource fillsConverter}}"
					d3:ViewportPanel.ViewportWidth="1" Margin="0,0,1,0">
					...
					...

In my code behind, I have been unsuccessfully trying to set the property as follows

<d3:ChartPlotter Name="plotter" Visible="0,0,100,1" Grid.ColumnSpan="2" >
<d3:ColumnChart Name="chart" ItemsSource="{Binding}">
<d3:TemplateMarkerGenerator>
<DataTemplate>
<Rectangle Fill="{d3:SelfBinding (d3:PointChartBase.Index), Converter={StaticResource fillsConverter}}"
  d3:ViewportPanel.ViewportWidth="1"
chart.AddPropertyBinding<Point>(ViewportPanel.ViewportWidthProperty,
    p => {
        // I have a myMarkerWidth (type: double) that I would like to use here,
        // but I cannot get it to work.
        return myMarkerWidth;
    }
);

but when I run, I encounter the following exception:
System.InvalidCastException was unhandled
  Message="Specified cast is not valid."
  Source="DynamicDataDisplay.Markers"
  StackTrace:
       at DynamicDataDisplay.Markers.DataSources.ValueConverters.GenericLambdaConverter`2.Convert(Object value, Type targetType, Object parameter, CultureInfo culture) in C:\downloads\dynamicdatadisplay-29304\Nightly\DynamicDataDisplay build 4394\src\DynamicDataDisplay.Markers\DataSources\ValueConverters\GenericLambdaConverter.cs:line 26
       at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
       at System.Windows.Data.BindingExpression.Activate(Object item)
       at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
       at System.Windows.Data.BindingExpression.AttachOverride(DependencyObject target, DependencyProperty dp)
       at System.Windows.Data.BindingExpressionBase.Attach(DependencyObject target, DependencyProperty dp)
       at System.Windows.Data.BindingExpressionBase.OnAttach(DependencyObject d, DependencyProperty dp)
       at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
       at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
       at System.Windows.FrameworkElement.SetBinding(DependencyProperty dp, BindingBase binding)
       at Microsoft.Research.DynamicDataDisplay.Charts.Markers.DevMarkerChart.AddCommonBindings(FrameworkElement marker) in C:\downloads\dynamicdatadisplay-29304\Nightly\DynamicDataDisplay build 4394\src\DynamicDataDisplay.Markers\DevMarkerChart.cs:line 420
       at Microsoft.Research.DynamicDataDisplay.Charts.Markers.ColumnChart.AddCommonBindings(FrameworkElement marker) in C:\downloads\dynamicdatadisplay-29304\Nightly\DynamicDataDisplay build 4394\src\DynamicDataDisplay.Markers\ColumnChart.cs:line 46
       at Microsoft.Research.DynamicDataDisplay.Charts.Markers.DevMarkerChart.CreateAndAddMarker(Object dataItem, Int32 actualChildIndex) in C:\downloads\dynamicdatadisplay-29304\Nightly\DynamicDataDisplay build 4394\src\DynamicDataDisplay.Markers\DevMarkerChart.cs:line 205
       at Microsoft.Research.DynamicDataDisplay.Charts.Markers.DevMarkerChart.DrawAllMarkers(Boolean reuseExisting, Boolean continueAfterDataPrepaired) in C:\downloads\dynamicdatadisplay-29304\Nightly\DynamicDataDisplay build 4394\src\DynamicDataDisplay.Markers\DevMarkerChart.cs:line 164
       at Microsoft.Research.DynamicDataDisplay.Charts.Markers.DevMarkerChart.DrawAllMarkers(Boolean reuseExisting) in C:\downloads\dynamicdatadisplay-29304\Nightly\DynamicDataDisplay build 4394\src\DynamicDataDisplay.Markers\DevMarkerChart.cs:line 88
       at Microsoft.Research.DynamicDataDisplay.Charts.Markers.DevMarkerChart.OnDataSourceChanged(PointDataSourceBase prevSource, PointDataSourceBase currSource) in C:\downloads\dynamicdatadisplay-29304\Nightly\DynamicDataDisplay build 4394\src\DynamicDataDisplay.Markers\DevMarkerChart.cs:line 48
       at Microsoft.Research.DynamicDataDisplay.Charts.NewLine.PointChartBase.OnDataSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) in C:\downloads\dynamicdatadisplay-29304\Nightly\DynamicDataDisplay build 4394\src\DynamicDataDisplay.Markers\PointChartBase.cs:line 270

Please help!
Thanks very much,
E.

 

 

Nov 13, 2009 at 12:16 AM

Well, I looked at the BarChartPage sample and saw how Segment was being used to specify size and location, so I used that metaphore.  Works wonderfully.  Awesome library - wonderful samples.  Thank you!