StyleDispenserExtensions threading crash, from PowerBoots

Jul 20, 2009 at 3:01 AM

Hey guys, I'm loving the toolkit, but among other things, I do a lot of WPF from PowerShell via PowerBoots...

After the last release, I've been working on creating some graphing/charting scripts and when I finally decided I needed to change the tooltips, I ran into a bit of a threading issue (I'll refrain from ranting about needing to template the whole control just to get at the tooltips).

I followed a blog post by Delay and an article on the Expression Blend site, and came up with a reasonable template which works ... except that when I try to create two charts in a row, it dies the second time when I set the .DataPointStyle .... because somewhere deep in the StylePalettePropertyChanged event, I get a thread access exception:

 

at System.Windows.Threading.Dispatcher.VerifyAccess()
at System.Windows.Threading.DispatcherObject.VerifyAccess()
at System.Windows.Style.get_TargetType()
at System.Windows.Controls.DataVisualization.StyleDispenserExtensions.<>c__DisplayClass1.b__0(Style style) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataVisualization\StyleDispenserExtensions.cs:line 27
at System.Windows.Controls.DataVisualization.Charting.StyleEnumerator.GetIndexOfNextSuitableStyle(Int32 startIndex) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataVisualization\Charting\StyleEnumerator.cs:line 90
at System.Windows.Controls.DataVisualization.Charting.StyleEnumerator.MoveNext() in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataVisualization\Charting\StyleEnumerator.cs:line 189
at System.Windows.Controls.DataVisualization.Charting.DataPointSingleSeriesWithAxes.RefreshStyles() in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataVisualization\Charting\Series\DataPointSingleSeriesWithAxes.cs:line 263
at System.Windows.Controls.DataVisualization.Charting.Chart.OnStylePalettePropertyChanged(Collection`1 newValue) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataVisualization\Charting\Chart\Chart.cs:line 282
at System.Windows.Controls.DataVisualization.Charting.Chart.OnStylePalettePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataVisualization\Charting\Chart\Chart.cs:line 270
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)

...

I haven't dug very far, but I was hoping someone might see this and say something like "oh, yeah, you've made the mistake of reusing the same ... thingy ... twice"  or something.  I can't figure it out, except that if I don't set the DataPointStyle, I don't have a problem, and if I only have one chart, I'm fine.  Thoughts? Questions?  I can post my code (mostly in PowerShell) and templates...