SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

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.