hi,
Yes, you need to customize the LinkingTool (and maybe the RelinkingTool) to get the effects that you want.
I suggest that instead of overriding DoStart and DoStop, you override DoMouseMove. Something like:
[code]public class MyLinkingTool : LinkingTool {
private FrameworkElement OldTarget { get; set; }
public override void DoMouseMove() {
base.DoMouseMove();
if (this.Active) {
if (this.OldTarget != null && this.OldTarget != this.TargetPort) {
ShowPorts(this.OldTarget, false);
}
if (this.TargetPort != null) {
ShowPorts(this.TargetPort, true);
}
this.OldTarget = this.TargetPort;
}
}
private void ShowPorts(FrameworkElement port, bool show) {
var node = Part.FindAncestor(port);
if (node != null) node.Tag = show;
}
public override void DoStop() {
base.DoStop();
if (this.OldTarget != null) {
ShowPorts(this.OldTarget, false);
this.OldTarget = null;
}
}
}[/code]
Caution: I haven’t even tried compiling this code.
This code assumes that highlight of port elements is performed in the same manner as in the FlowChart sample: in XAML via data-binding. That has the advantage of styling and definition in XAML. But you could make the changes in code, by iterating over all of the ports of the Node and changing their Visibility programmatically.
if (targetNode != null)
{
if (show)
{
foreach (FrameworkElement port in targetNode.Ports)
{
port.Visibility = Visibility.Visible;
}
}
else
{
foreach (FrameworkElement port in targetNode.Ports)
{
string portid = Node.GetPortId(port);
bool haslinks = (targetNode.FindLinksConnectedWithPort(portid).FirstOrDefault() != null);
if (haslinks)
port.Visibility = Visibility.Visible;
else
port.Visibility = Visibility.Collapsed;
}
}
}
}
}
public override void DoMouseMove()
{
base.DoMouseMove();
if (this.Active)
{
if (this.OldTarget != null && this.OldTarget != this.TargetPort)
{
SetAllNodesPortsVisible(this.OldTarget, false);
}
if (this.TargetPort != null)
{
SetAllNodesPortsVisible(this.TargetPort, true);
}
this.OldTarget = this.TargetPort;
}
}
I see you’re directly changing the Visibility of the ports, rather than depending on data-binding the Visibility to the Node.Tag. That’s fine.
If it’s all in a custom LinkingTool, and if it’s working the way you want, the only thing left is maybe customizing the RelinkingTool similarly – if your application supports relinking.
no no its not working as required even i made changes as suggested by you.
I just tried this, and I think it does what you say you want:
[code] public class MyLinkingTool : LinkingTool {
public override void DoStop() {
base.DoStop();
foreach (Node n in this.Diagram.Nodes) {
n.Tag = false;
}
this.PreviousTarget = null;
}
private Node PreviousTarget { get; set; }
public override void DoMouseMove() {
base.DoMouseMove();
Node target = null;
if (this.TargetPort != null) target = Part.FindAncestor<Node>(this.TargetPort);
if (this.PreviousTarget != target) {
if (this.PreviousTarget != null) this.PreviousTarget.Tag = false;
if (target != null) target.Tag = true;
this.PreviousTarget = target;
}
}
}[/code]
This is I made to the FlowChart sample. But you’ll probably want to do the same in the RelinkingTool.
If you still want to set your port Visibility property directly in code, that’s fine too.