I’m trying to have the user create an annotation, similar to the Create annotations Dynamically example. The problem is that when I try to attach a handler to the AnnotationCreated event, either the scichart surface won’t display, or the handler is never invoked.The things I’ve tried are:
1) creating a handler in the code behind causes the surface not to load:
<sciChart:SciChartSurface.ChartModifier>
<s:ModifierGroup >
<s:AnnotationCreationModifier x:Name="annotationCreator"
AnnotationCreated="{Binding OnAnnotationCreated}" >
</s:AnnotationCreationModifier>
</s:ModifierGroup>
</sciChart:SciChartSurface.ChartModifier>
2) The way I’ve been handling mouse events using cinch mvvm won’t work in this either. The chart surface loads, but the handler is never invoked:
<sciChart:SciChartSurface.ChartModifier>
<s:ModifierGroup >
<s:AnnotationCreationModifier x:Name="annotationCreator"
AnnotationCreated="{Binding OnAnnotationCreated}" >
</s:AnnotationCreationModifier>
<i:Interaction.Triggers>
<i:EventTrigger EventName="AnnotationCreated">
<CinchV2:EventToCommandTrigger
Command ="{Binding AnnotationCreatedCmd}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</s:ModifierGroup>
</sciChart:SciChartSurface.ChartModifier>
Removing the handler line in the xaml in 1) above and adding an event handler in the view model.onViewLoaded() is the only way I can make this work:
view.annotationCreator.AnnotationCreated += AnnotationCreatorOnAnnotationCreated;
I can work around the problem with the last approach, but why don’t the other approaches work for the annotation created event?
thanks!
- tecman234 asked 11 years ago
- last edited 7 years ago
- You must login to post comments
Hi,
In Xaml usually you have to create a binding to some property only. To attach event handler, simply do this:
<sciChart:SciChartSurface.ChartModifier> <s:ModifierGroup > <!-- Attach OnAnnotationCreated handler defined in code behind --> <s:AnnotationCreationModifier x:Name="annotationCreator" AnnotationCreated="OnAnnotationCreated"> </s:AnnotationCreationModifier> </s:ModifierGroup> </sciChart:SciChartSurface.ChartModifier>
In MVVM you can use the EventTrigger to pass the event over to a view model, like this:
<sciChart:SciChartSurface.ChartModifier>
<s:ModifierGroup >
<!-- Attach OnAnnotationCreated handler defined in code behind -->
<s:AnnotationCreationModifier x:Name="annotationCreator">
<i:Interaction.Triggers>
<i:EventTrigger EventName="AnnotationCreated" SourceObject="{Binding RelativeSource={RelativeSource AncestorType={x:Type s:AnnotationCreationModifier}}}">
<i:InvokeCommandAction Command="{Binding LineAnnotationCreatedEvent}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</s:AnnotationCreationModifier>
</s:ModifierGroup>
</sciChart:SciChartSurface.ChartModifier>
Please, let us know if you get it working or need further assistance,
Best regards,
Yuriy
- Yuriy Zadereckiy answered 11 years ago
- last edited 7 years ago
- You must login to post comments
Please login first to submit.