I need to figure out to make this work is why one of my bindings works and the other doesn’t.
<!-- Define shared X Axis' drawn characteristics and information -->
<SciChart:SciChartSurface.XAxis>
<SciChart:DateTimeAxis DrawMajorGridLines="True" DrawMinorGridLines="True" DrawLabels="True" Name="XAxis"
DataContext="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Grid}, AncestorLevel= 3}, Path=DataContext}"
VisibleRange="{Binding SharedXVisibleRange, Mode=TwoWay}"/>
</SciChart:SciChartSurface.XAxis>
<!---->
<!-- Apply all chart modifiers, their triggers, and their bindings -->
<SciChart:SciChartSurface.ChartModifier>
<SciChart:ModifierGroup SciChart:MouseManager.MouseEventGroup="Group" Name="modGroup">
<SciChart:ZoomPanModifier Name="Pan" ExecuteOn="MouseLeftButton" DataContext="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Grid}}, Path=DataContext}"
IsEnabled="{Binding PanEnabled, Mode=TwoWay}"
ZoomExtentsY="False" XyDirection="{Binding ZoomPanDir, Mode=TwoWay}" ReceiveHandledEvents="False"/>
</SciChart:ModifierGroup>
</SciChart:SciChartSurface.ChartModifier>
The above is the section in question. I’ve got a window that creates instances of the user control, quoted here, and in doing so needs to bind the visible range of all x-axes together as well as have all of the chart modifiers for any axis act on all of them. Now, the visible range binding works fine but the chart modifiers bindings do not.
I’ve tried binding the datacontext of both the group and individual modifiers, but neither works. Any idea why? I can include more code is necessary.
- rcannon asked 10 years ago
- You must login to post comments
Hi,
It seems to me you just need to set the DataContext property on the most higher level once (UserControl). It will be propagated down the visual tree and axes, modifiers will inherit it. So try this:
-
remove DataContext bindings from your code
-
set DataContext once on the UserControl(in code behind or add it as a resource and reference via StaticResource)
Please, let us know if you get it working.
Best regards,
Yuriy
- Yuriy Zadereckiy answered 10 years ago
-
I can't allow the implicit binding like that. I'm dynamically creating an unknown number of series by binding to the SeriesViewModel, which requires binding to the user control, but at the same time I've got multiple user controls for displaying multiple series sets that all need to have their chartmodifiers linked to the parent window's static resource. Basically, I used the Realtime Ticking Stock Charts data binding, but I'm also trying to implement a chart modifier synchronization and the two of them are interfering with each other. I'll include my base model for reference.
-
Try using the ElementName binding instead of RelativeSource, because chart modifiers don't participate in VisualTree. Also, some of them use own DataContexts, so you'd better use direct binding to prevent DataContext from being overridden by modifier internally. Best regards, Yuriy
- You must login to post comments
Please login first to submit.