Mouse Hover Event

Hi,

If possible please provide a code snippet to simulate a MouseHover event (Silverlight).

Thanks
Rich

OK, that was fun!

[code] public class CustomToolManager : ToolManager {
public override void DoMouseMove() {
base.DoMouseMove();
RestartHoverTimer();
}

public event EventHandler Hover;

protected virtual void OnHover() {
  if (this.Hover != null) this.Hover(this.Diagram, EventArgs.Empty);
}

private System.Windows.Threading.DispatcherTimer myTimer;

private void RestartHoverTimer() {
  if (myTimer == null) {
    myTimer = new System.Windows.Threading.DispatcherTimer();
    myTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000);  // wait 1 second
    myTimer.Tick += (s, e) => {
      myTimer.Stop();
      OnHover();
    };
    this.Diagram.Panel.MouseLeave += (s, e) => { myTimer.Stop(); };
  } else {
    myTimer.Stop();
  }
  myTimer.Start();
}

}[/code]
Example use:

CustomToolManager toolmgr = new CustomToolManager(); toolmgr.Hover += (s, e) => { System.Diagnostics.Debug.WriteLine("Hover event at: " + DateTime.Now.ToString()); }; myDiagram.DefaultTool = toolmgr;
Caution: I have not tried this in v1.0, nor have I tried this in WPF. Those two cases are left as exercises for the reader.

Thanks for the quick response.

One last thing. On the hover event I need to execute something like:

Link link = Part.FindAncestor(e.OriginalSource as UIElement);

Since e.OriginalSource is not available how do I determine the object that is being Hovered over.

Thanks
Rich

Change the code to:

protected virtual void OnHover() { if (this.Hover != null) { Part p = FindPartAt(this.Diagram.LastMousePointInModel, false); this.Hover(p, EventArgs.Empty); } }
Then the source argument will be a Part, or null if it’s in the background.

Can you post the code for the FindPartAt function? I need to be able to figure out what part the user dropped something on in silverlight

But anything involving drag-and-drop by definition will not involve a “hover” event, and vice-versa.

Instead, you may want to customize the DraggingTool. If you are using 1.1 beta and turn on DraggingTool.DropOntoEnabled, the DraggingTool.DragOverPart property is updated during a drag and that part’s Part.IsDropOntoAccepted property is temporarily set to true, typically so that the part can change its appearance when a drop may occur onto it.

The DraggingTool.DropOnto method is also called when the drop happens.