ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

how to get click on cursor or annotation [wpf graphs]

How to do that? I need to know when they are clicked, so I'l be able to update their configuration.

0 Kudos
Message 1 of 13
(8,040 Views)

Ideally, you would be able to use the GetChildrenAtPoint method from the PlotAreaMouseLeftButtonDown event, however a bug in the current version of Measurement Studio prevents that from working.


For cursors, the PositionChanged event is fired whenever the value of the cursor changes during a drag, but there is no corresponding event for just a mouse click. You could override the GetCursorDragStartScreenPosition method, which is called when the mouse is clicked at the start of a drag.


For annotations, we do not expose any event or method called on click, but you can override the OnDragMoveCore method to respond to a drag.




If you could give more detail on what you mean by “update their configuration”, maybe there is an alternate approach that would better fit your needs?

~ Paul H
0 Kudos
Message 2 of 13
(8,027 Views)

Hello, Paul!

 

Basically I allow user to control appearance of the curcor/annotation (colors, shapes, etc.). I've got only single set of controls, so I have to know which cursor/annotation is active now, so I apply changes to proper one.

0 Kudos
Message 3 of 13
(7,998 Views)

I can see how letting the user click directly on the graph child they want to update would be convenient, though the graph has no notion of an “active” child. It might make more sense to use a control explicitly for this purpose, allowing the user to see and change the selected child.


Here is a simple example showing how you could expose all the graph’s children using a ComboBox to support selection:


    // XAML
    <StackPanel>
        <ComboBox x:Name="activeChild" ItemsSource="{Binding Children, ElementName=graph}">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Label}" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>

        <TextBox x:Name="label" />

        <Button Content="_Apply" Click="OnApplyClicked" />
    </StackPanel>


    // code
    private void OnApplyClicked( object sender, RoutedEventArgs e ) {
        object child = activeChild.SelectedItem;

        var cursor = child as CursorBase;
        if( cursor != null )
            cursor.Label = label.Text;

        var annotation = child as Annotation;
        if( annotation != null )
            annotation.Label = label.Text;
    }

~ Paul H
0 Kudos
Message 4 of 13
(7,992 Views)

Hmm, our interface is touch based, so it's very natural to click on annotation to be able to configure it.

 

I don't understand why annotation itself doesn't provide mouse events...

0 Kudos
Message 5 of 13
(7,989 Views)
I don't understand why annotation itself doesn't provide mouse events...

The functionality exposed by the WPF controls is based on a combination of new WPF concepts with the existing Windows Forms control features. In Windows Forms, hit testing is exposed through a single method on the graph, rather than through events on each individual. As mentioned before, we expose the same general-purpose hit testing functionality in WPF (with the caveat that annotation hit testing will need to wait for the next version of Measurement Studio).




Given the current functionality, we are always happy to get feedback, and adding additional events to the cursors and annotations is certainly something we would consider for a future release. It would be very helpful if you would post the details of what you are looking for to the Measurement Studio Idea Exchange. This is one of the primary resources we use when considering new features each release.

~ Paul H
0 Kudos
Message 6 of 13
(7,984 Views)

Just wanted to let you know that the annotation hit testing issue (#374462) was fixed in the Measurement Studio 2013 release.

~ Paul H
0 Kudos
Message 7 of 13
(7,842 Views)

How was it fixed? PlotAreaMouseLeftButtonDown event isn't raised when I click on annotation.

0 Kudos
Message 8 of 13
(7,747 Views)

The GetChildrenAtPoint method was fixed, allowing annotations to appear in the results.


There is a separate issue regarding interactive elements swallowing mouse events, which was not fixed in time for the 2013 release (i.e. if you have an annotation with an InteractionMode allowing target dragging, then clicking on the target will not raise a mouse down event). Instead of using the mouse down event, you can use the preview event instead:


    graph.PreviewMouseLeftButtonDown += OnPreviewMouseLeftButtonDown;
    ...
    private void OnPreviewMouseLeftButtonDown( object sender, MouseButtonEventArgs e ) {
        Point screenPosition = e.GetPosition( graph );
        var children = graph.GetChildrenAtPoint( screenPosition );
        ...
    }

~ Paul H
0 Kudos
Message 9 of 13
(7,744 Views)

I see. But this annotation detection works only for the target, not for the label or arrow.

0 Kudos
Message 10 of 13
(7,725 Views)