-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get both nodes to re-render after connection made. #484
Comments
I had the same scenario, my solution was to create a custom Behavior that listens to Diagram.PointerUp and then looks if the targeted model is a port. If so, it triggers an event on the port: // Custom behavior listening to Diagram.PointerUp
private void HandlePointerUp(Model? model, PointerEventArgs e)
{
// BasePortModel is a custom abstract class inheriting PortModel.
if (model is BasePortModel basePortModel)
{
basePortModel.TriggerPointerUp();
}
} Then, in my blazor port component, I simply listen to the port's event and do a StateHasChanged(). I would also like to note I do not have snapping activated or any other special things related to ports, I do not know what the behavior would be like with anything like that. |
Hello, are the events available to you not enough for this? For example What do you think? |
That works for me, thank you! |
I had expected these functionalities to be in the Diagram.Options area. Instead, the Diagram.Links.Added with the TargetAttached event (plus the Diagrams.Links.Removed if a link is deleted) did the job. Diagram.Links.Added += OnLinkAdded;
Diagram.Links.Removed += OnLinkRemoved; private static void OnLinkRemoved(BaseLinkModel obj)
{
if (obj.Source.Model is PortModel sourceNode)
{
var node = sourceNode.GetParent<NodeModel>();
node.Refresh();
}
if (obj.Target.Model is PortModel targetNode)
{
var node = targetNode.GetParent<NodeModel>();
node.Refresh();
}
}
private static void OnLinkAdded(BaseLinkModel obj)
{
if (obj.Source.Model is PortModel port)
{
var node = port.GetParent<NodeModel>();
node.Refresh();
}
obj.TargetAttached += OnTargetAttached;
}
private static void OnTargetAttached(BaseLinkModel obj)
{
if (obj.Target.Model is PortModel port)
{
var node = port.GetParent<NodeModel>();
node.Refresh();
}
} |
In my custom scenario, the appearance of the nodes/ports (can) change if a link is made between them. For example: the port either requires a number input or a link which provides the number. If the link is provided, the number input disappears. If the link is removed, the number input shows back up again.
However, the appearance of the nodes doesn't change until I select the node, at which case it updates, rather than when the link is added/removed.
Either this is a missing feature or I am doing something wrong; however, if this is a missing feature, I would like to have virtual methods for the Diagram itself which get invoked when links are added/removed (which the port/node of each side being shown and the option to re-render them).
The text was updated successfully, but these errors were encountered: