Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Working with cursors on WPF graph

Solved!
Go to solution

Hello friends,

 

I have been working on how to use cursors with a WPF graph in an MVVM application but I am having trouble accomplishing a few things. I have created a cursor on my graph with the following statement...

<ni:Cursor SnapToData="False" InteractionMode="Mouse" AllowablePlots="Single" Plot="{Binding ElementName = channelPlot}" HorizontalCrosshairLength="0" TargetSize="0,0"/>

I set the HorizontalCrosshairLength to 0 because I am only interested in the vertical crosshair. I set the TargetSize to 0,0 because I do not need anything to display at the intersection of the crosshairs.

 

With that being said I have the following questions...

  1. At the intersection of the vertical & horizontal crosshairs, the X and Y value of the intersection are displayed, how can I hide these X and Y values?
  2. How can I set the default position of my vertical crosshair?
  3. How can I change the color of my cursor?

Thanks!

0 Kudos
Message 1 of 7
(4,585 Views)
Solution
Accepted by topic author b!tmaster

1) You can use the ValueVisibility property to hide the display of the value.

 

2) By default, a Cursor takes a position in the center of the plot area at the time it is loaded into a graph. To change this position, you will need to call one of the Set*Position methods, such as SetRelativePosition or SetDataPosition.

 

3) Since you are hiding the target, you can use the CrosshairBrush property to change the color of your cursor.

~ Paul H
0 Kudos
Message 2 of 7
(4,543 Views)

phasen,

  1. I set the ValueVisibility property to collapsed and this removed the value display.
  2. Unfortunately I think I am going to have to break my MVVM pattern to use the Set*Position methods in my code behind but regardless, thanks for pointing out which methods I need to move cursor position.
  3. I am now able to change the color of my cursor using the mentioned property.

Thanks for your help!

0 Kudos
Message 3 of 7
(4,540 Views)

For the Set*Position methods, you could also optionally create an attached property to do a one-time set using XAML, if that makes more sense for your scenario.

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

It sounds like that may make more sense for my scenario, I am unaware of how to implement an attached property though so I will do some research.

0 Kudos
Message 5 of 7
(4,535 Views)

From a quick search, this article might be a helpful reference: Introduction to Attached Behaviors in WPF.

~ Paul H
0 Kudos
Message 6 of 7
(4,526 Views)

Thanks for the reference, I realized that I am going to have to be able to set the position of the cursors repeatedly (not just one time) so I am just going to use the code behind approach.

0 Kudos
Message 7 of 7
(4,521 Views)