Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Action on Hovering (Read 4795 times)
Pontius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 51
Joined: May 13th, 2011
Action on Hovering
Jan 25th, 2012 at 9:03am
Print Post  
Hi,

I would like to display some text when hovering over a node's AnchorPoint. The Tooltips do not provice the format I want to use.
Is there a chance to trigger on an event when hovering over an AnchorPoint?

Regards,
Pontius
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Action on Hovering
Reply #1 - Jan 25th, 2012 at 2:46pm
Print Post  
Hi,

You could detect that like this:

Code
Select All
void diagram_PreviewMouseMove(object sender, MouseEventArgs e)
{
	if (hoverTimer.IsEnabled)
	{
		hoverTimer.Stop();
		return;
	}

	var point = e.GetPosition(diagram.DocumentPlane);
	var node = diagram.GetNodeAt(point, 4);
	if (node == null)
		return;

	foreach (AnchorPoint p in node.AnchorPattern.Points)
	{
		var r = node.Bounds;
		var appos = new Point(r.X + r.Width * p.X / 100, r.Y + r.Height * p.Y / 100);

		if (Math.Abs(point.X - appos.X) <= 4 && Math.Abs(point.Y - appos.Y) <= 4)
		{
			// found anchor point at mouse position
			currentNode = node;
			currentPoint = p;
			hoverTimer.Interval = TimeSpan.FromSeconds(1);
			hoverTimer.Tick += hoverTimer_Tick;
			hoverTimer.Start();
		}
	}
}

void hoverTimer_Tick(object sender, EventArgs e)
{
	hoverTimer.Stop();
	// show custom tooltip here
}

DispatcherTimer hoverTimer = new DispatcherTimer();
DiagramNode currentNode;
AnchorPoint currentPoint; 



You could also define an attached event to raise from the hover timer if you need to handle this elsewhere.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Pontius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 51
Joined: May 13th, 2011
Re: Action on Hovering
Reply #2 - Feb 2nd, 2012 at 2:14pm
Print Post  
Hi Stoyan,

thank you very much for the code snipped.
It works fine.
I have included a System.Windows.Controls.Primitives.Popup that replaces my ToolTip. Finding the correct position for the Popup was not easy since I also have a ScrollViewer that includes my Mindfusion Diagram.

In order to implement the Popup in the XAML code I added a Grid like in the folowing code.
Code
Select All
<UserControl x:Class="MyTool.CtrlDiagram"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mindfusion="http://mindfusion.eu/diagramming/wpf"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="300"
            ...

             Name="MyDiagram">
    <ScrollViewer Name="scrollViewer"
                  Focusable="False"
                  HorizontalAlignment="Stretch"
                  VerticalAlignment="Top"
                  HorizontalScrollBarVisibility="Hidden"
                  VerticalScrollBarVisibility="Hidden"
                  PreviewMouseWheel="scrollViewer_PreviewMouseWheel" >
        <Grid>
            <mindfusion:Diagram Name="diagram"
                            DefaultShape="Rectangle"
                            ...

                            PreviewMouseMove="diagram_PreviewMouseMove" >
                <mindfusion:Diagram.LayoutTransform>
                    <TransformGroup>
                        <ScaleTransform x:Name="scaleTransform" />
                    </TransformGroup>
                </mindfusion:Diagram.LayoutTransform>
            </mindfusion:Diagram>
            <Popup Name="anchorPopup" Placement="Bottom" AllowsTransparency="True"
                IsOpen="{Binding Path=ShowAnchorPopup, ElementName=MyDiagram, Mode=TwoWay}"
                >
                <Grid Background="YellowGreen" Opacity="1.0" >
                    <TextBlock Margin="5"  FontSize="12"
                        Text="{Binding Path=AnchorPopupText, ElementName=MyDiagram, Mode=TwoWay}"
                        FontFamily="Constantia">
                    </TextBlock>
                </Grid>
            </Popup>
        </Grid>
    </ScrollViewer>
</UserControl> 



After I added the Grid the pan mode of the Diagram (Alt + Left Mouse) does not work anymore.

Do you know why?

Regards,
Pontius
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Action on Hovering
Reply #3 - Feb 2nd, 2012 at 6:42pm
Print Post  
Hi,

Panning is implemented by setting the parent scroll viewer's offsets, and it will work only if the diagram's direct parent control is a ScrollContentPresenter of some kind. The diagram won't search for scrollviewers further up in the WPF visual tree. So you will have to remove the grid that stands between the scrollviewer and the diagram. I suppose something like this should work:

grid
  scrollviewer
    diagram
  popup

Finding the popup's position should not be a problem. In WPF you can always call the TransformToVisual method to convert coordinates from one control to another. E.g. if you need to find the position of a diagram point relative to a parent grid that contains the popup:

var p = diagram.DocumentPlane.TransformToVisual(parentGrid).Transform(diagramPoint);

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Pontius
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 51
Joined: May 13th, 2011
Re: Action on Hovering
Reply #4 - Feb 6th, 2012 at 3:57pm
Print Post  
Thanks Stoyan,

now it works fine. Smiley

Regards,
Pontius
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint