How do you enumerate child charts on a chart group?
My purpose is to try to call ZoomExtents() for each chart in a group after I an event is triggered from the ViewModel which reflects on code-behind of the Window.
Thanks.
- jaysonragasa asked 10 years ago
- last edited 10 years ago
- You must login to post comments
Hi Jayson,
You can’t enumerate the charts easily, as they are templated. If you really need to do this I would suggest looking at this article on ItemsControl.GetContainerFromItem.
However, sounds like you just want to zoom to extents on the child charts, am I right?
If so, we’ve literally just added the ability to Zoom Extents in our own Create Multi Pane Stock Charts example in v3.1, as we omitted this feature in v3.0. The code we’ve added to do this is below:
I’ve omitted irrelevant parts of the code.
1. The SciStockChart in the SciChartGroup ItemTemplate binds to a ViewportManager
<!-- Databinds a SciChartGroup to a list of ChartPaneViewModels --> <!-- Child chart panes are generated using the ItemTemplate below --> <s:SciChartGroup ... > <s:SciChartGroup.ItemTemplate> <DataTemplate> <!-- Databinds each child SciStockChart ... --> <s:SciStockChart ... ViewportManager="{Binding ParentViewModel.ViewportManager}" SeriesSource="{Binding ChartSeriesViewModels}"> ... </s:SciStockChart> </DataTemplate> </s:SciChartGroup.ItemTemplate> </s:SciChartGroup>
2. The ParentViewModel (shared by all charts) contains a ViewportManager instance
private IViewportManager _viewportManager;_viewportManager = new DefaultViewportManager(); public IViewportManager ViewportManager { get { return _viewportManager; } }
3. The ZoomExtents operation can now be performed via the ViewportManager
// Inside your ViewModel which hosts the ViewportManager private void ZoomExtents() { ViewportManager.AnimateZoomExtents(TimeSpan.FromMilliseconds(500)); }
That’s it! You can then control the viewport, zoom to extents etc… directly from your ViewModel
- Andrew Burnett-Thompson answered 10 years ago
- You must login to post comments
Please login first to submit.