I refactored from using custom RenderableSeries to a custom RenderableSeriesViewModel which has fixed a refresh bug in the chart:
public class CustomExclusionRenderableSeriesViewModel : BaseRenderableSeriesViewModel
{
public override Type RenderSeriesType => typeof(CustomExclusionRenderableSeries);
}
However I am invoking MouseLeftButtonUp in the chart code behind and performing a hit test. The HitTest method is not exposed on the BaseRenderableSeriesViewModel:
private void SciChartSurfaceMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
// Perform the hit test relative to the GridLinesPanel
Point hitTestPoint = e.GetPosition(this.sciChart.GridLinesPanel as UIElement);
// Get hit test the RenderableSeries using interpolation
this.ViewModel.HitTestInfo = this.ViewModel.ExclusionSeries.HitTest(hitTestPoint, true);
Is there any way to get the series instance from the view model & hit test it?
- Thomas Hutchinson asked 7 years ago
- You must login to post comments
Hi Thomas
Interesting requirement!
I would suggest to use our ChartModifierBase API to override OnModifierMouseDown for a start. Then perform the hit-test.
You can always then notify the ViewModel via a command binding, or, if you are not averse to slight hacks, direct call on a ViewModel.
e.g. simple case psuedocode becomes
public class HitTestModifierMvvm : ChartModifierBase
{
public override void OnModifierMouseDown(ModifierMouseArgs e)
{
base.OnModifierMouseDown(e);
foreach (var renderSeries in base.ParentSurface.RenderableSeries)
{
var hitTestInfo = renderSeries.HitTest(e.MousePoint);
(renderSeries.DataContext as CustomExclusionRenderableSeriesViewModel).HitTest(hitTestInfo);
}
}
}
Obviously this can be improved, a lot. For example if you have an ICommand Dependency Property in your renderableseries, and bind it to a ViewModel ICommand you can invoke the command directly on the series, instead of doing a cast in your ChartModifier.
You can also choose to forward hit-tests where hitTestInfo.IsHit is true as opposed to all the hit-tests etc.. etc..
Does this help?
Best regards,
Andrew
- Andrew Burnett-Thompson answered 7 years ago
-
Great, thanks. I have implemented a work around in which I get the series from the surface and match on SeriesName but I will try to implement hit testing as explained above
-
I was thinking a better solution would be to have ICommand HitTestCommand on RenderableSeries bound to ICommand HitTestcommand in ViewModel. When the hit-test is invoked on the series it will call it on the ViewModel. Would be a nice addition to scichart MVVM
-
Actually that won’t work … nevertheless I created a task for us to discuss internally https://abtsoftware.myjetbrains.com/youtrack/issue/SC-4036
-
Being able to call hit test more easily with RenderableSeriesViewModels would be great!
- You must login to post comments
Please login first to submit.