SciChartĀ® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.


Hello again.

As you’ve suggested in other posts, to avoid mouse events broadcasting across multiple windows with charts (and in my case, crashing said windows, ’cause they’re in multiple UI threads), I do binding like this:

<sciChart:ModifierGroup mouse:MouseManager.MouseEventGroup="{Binding MouseGroupId}">

Where MouseGroupId is just a GUID converted to a string. The problem is, this binding (or any binding, even for the constant string in the view model) doesn’t work. Binding trace is as follows:

System.Windows.Data Warning: 55 : Created BindingExpression (hash=43894578) for Binding (hash=31482310)
System.Windows.Data Warning: 57 : Path: 'MouseGroupId'
System.Windows.Data Warning: 59 : BindingExpression (hash=43894578): Default mode resolved to OneWay
System.Windows.Data Warning: 60 : BindingExpression (hash=43894578): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 61 : BindingExpression (hash=43894578): Attach to Abt.Controls.SciChart.ModifierGroup.MouseEventGroup (hash=44711291)
System.Windows.Data Warning: 66 : BindingExpression (hash=43894578): Resolving source
System.Windows.Data Warning: 69 : BindingExpression (hash=43894578): Found data context element: ModifierGroup (hash=44711291) (OK)
System.Windows.Data Warning: 77 : BindingExpression (hash=43894578): Activate with root item ChartPanelViewModelProxy (hash=11922526)
System.Windows.Data Warning: 107 : BindingExpression (hash=43894578): At level 0 – for ChartPanelViewModelProxy.MouseGroupId found accessor RuntimePropertyInfo(MouseGroupId)
System.Windows.Data Warning: 103 : BindingExpression (hash=43894578): Replace item at level 0 with ChartPanelViewModelProxy (hash=11922526), using accessor RuntimePropertyInfo(MouseGroupId)
System.Windows.Data Warning: 100 : BindingExpression (hash=43894578): GetValue at level 0 from ChartPanelViewModelProxy (hash=11922526) using RuntimePropertyInfo(MouseGroupId): 'Mouse831A0392'
System.Windows.Data Warning: 79 : BindingExpression (hash=43894578): TransferValue – got raw value 'Mouse831A0392'
System.Windows.Data Warning: 88 : BindingExpression (hash=43894578): TransferValue – using final value 'Mouse831A0392'
System.Windows.Data Warning: 95 : BindingExpression (hash=43894578): Got PropertyChanged event from ModifierGroup (hash=44711291) for DataContext
System.Windows.Data Warning: 78 : BindingExpression (hash=43894578): Deactivate
System.Windows.Data Warning: 102 : BindingExpression (hash=43894578): Replace item at level 0 with {NullDataItem}
System.Windows.Data Warning: 77 : BindingExpression (hash=43894578): Activate with root item <null>
System.Windows.Data Warning: 105 : BindingExpression (hash=43894578): Item at level 0 is null – no accessor
System.Windows.Data Warning: 79 : BindingExpression (hash=43894578): TransferValue – got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 87 : BindingExpression (hash=43894578): TransferValue – using fallback/default value <null>
System.Windows.Data Warning: 88 : BindingExpression (hash=43894578): TransferValue – using final value <null>
System.Windows.Data Warning: 78 : BindingExpression (hash=43894578): Deactivate
System.Windows.Data Warning: 102 : BindingExpression (hash=43894578): Replace item at level 0 with {NullDataItem}
System.Windows.Data Warning: 62 : BindingExpression (hash=43894578): Detach

So, the getter on view model is being called, and binding receives the initial value, but then ModifierGroup loses its data context, and the bound value is lost.

Because I use the chart in the ItemsControl (while looking forward to using the SciChartGroup, when it’ll be released), the charts are created by the ItemsControl and I couldn’t find an event that’ll allow me to set mouse event group programmatically.

So, how should I do this, prefereably with MVVM?

Full itemscontrol xaml is like this:

    &lt;ItemsControl x:Name=&quot;PanelContainer&quot; ItemsSource=&quot;{Binding Panels}&quot;&gt;
                &lt;UniformGrid Columns=&quot;1&quot; /&gt;

                &lt;sciChart:SciStockChart BarTimeFrame=&quot;{Binding BarTimeFrame, UpdateSourceTrigger=PropertyChanged}&quot;
                                        SeriesSource=&quot;{Binding ChartSeries}&quot;
                                        XAxisVisibleRange=&quot;{Binding ElementName=ChartContainer, Path=DataContext.SharedXVisibleRange, Mode=TwoWay}&quot;
                                        sciChart:SciChartGroup.VerticalChartGroup=&quot;{Binding VerticalGroupId}&quot;
                        &lt;sciChart:ModifierGroup mouse:MouseManager.MouseEventGroup=&quot;{Binding MouseGroupId, PresentationTraceSources.TraceLevel=High}&quot;&gt;
                            &lt;sciChart:RubberBandXyZoomModifier IsXAxisOnly=&quot;True&quot; ReceiveHandledEvents=&quot;True&quot; /&gt;
                            &lt;sciChart:MouseWheelZoomModifier /&gt;
                            &lt;sciChart:RolloverModifier ReceiveHandledEvents=&quot;True&quot; /&gt;
                            &lt;sciChart:XAxisDragModifier /&gt;
                            &lt;sciChart:ZoomExtentsModifier ExecuteOn=&quot;MouseDoubleClick&quot; /&gt;

Also, what’s the right way to use SciChartOverview with the ItemsControl, again, preferably with MVVM? (I’ve found SciChartOverview.BackgroundChartSurface in change log, but couldn’t do anything with it.

  • You must to post comments

Ok. I don;t know why that doesn’t work – it should. The method you’ve proposed seems sound. My only suggestion is to look for any other binding errors as they occasionally prevent the binding engine from continuing to evaluate other bindings (well, i’ve seem some wierd behaviour around this before lets say).

Another idea is – as you’ve pointed out – set the binding in code. What about SciChartSurface.Loaded event? This should be fired when the Item is created. Alternatively you could create a derived class of ItemsControl and override ItemsControl.GetContainerForItemOverride or using this hack workaround to get a notification of items changed.

Try those, let me know how it goes. You’re right MouseManager is not multi-UI thread safe as it forwards events to each child surface in the same group. Maybe we should look at this.

Best regards,

  • You must to post comments

Hi, I’ve isolated the issue in the attached project: it opens two windows with two charts, the first window has the mouse group hardcoded into the xaml, the second has it bound from a view model property. Otherwise they’re copy-and-paste clones of each other. The first window forwards events as expected, while the second one doesn’t (the binding trace is the same).

Maybe I’m doing something wrong, but I can’t find out, what it is šŸ™

Loaded event is a nice suggestion, thank you, and it works. Here’s my event handler code for others to use:
// Workaround for the mouse event group
private void ChartPanelLoaded(object sender, RoutedEventArgs e)
if (sender == null) throw new ArgumentNullException("sender");

        // get chart panel
        SciStockChart chart = sender as SciStockChart;

        // check
        if (chart == null)
            throw new InvalidOperationException(&quot;This event handler works only with SciStockChart, but instead got &quot; + sender.GetType().Name);

        // set the mouse event group
        MouseManager.SetMouseEventGroup((ModifierGroup)chart.ChartModifier, ((ChartPanelViewModel) chart.DataContext).MouseGroupId);

In my application, there is no use case for cross-threaded MouseManager, mine was just a remark. I think, MouseManager that operates in the context of a current thread is much simpler and performant solution.

  • Andrew
    Ok, I got around to investigating this today. Sorry about the delay!Turns out there is a bug (1-line of code fix) in SciChartSurface.cs.When we detach and re-attach a chart modifier (occurs during application of themes) then the ChartModifier.DataContext is set to null. This means your binding stops working as soon as the theme is applied to the chart.I've fixed this and have committed it to both our 1.6 branch and v2.0 branch, so soon will be in both.Thanks for reporting, and for the excellent solution to reproduce!Best regards, Andrew
  • gman
    I've upgraded to v1.7.0.2424 and it works with the bindings now, thanks!
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.