Pre loader

can't make AnnotationCreated event work

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

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=&quot;annotationCreator&quot; 
                            AnnotationCreated=&quot;{Binding OnAnnotationCreated}&quot;                       >
                    </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=&quot;annotationCreator&quot; 
                            AnnotationCreated=&quot;{Binding OnAnnotationCreated}&quot;                       >
                    </s:AnnotationCreationModifier>
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName=&quot;AnnotationCreated&quot;>
                                <CinchV2:EventToCommandTrigger 
                                            Command =&quot;{Binding AnnotationCreatedCmd}&quot;/>
                            </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!

Version
v3.6
  • You must to post comments
0
0

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=&quot;annotationCreator&quot;>
            <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

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies