DiagramPanel
Avalonia control that hosts and renders diagram elements.
Inherits: Control
Constructors
public DiagramPanel()
diagramPanel = DiagramPanel()
Initializes a new instance of the DiagramPanel.
Properties
public bool IsEditing { get; set; }
value = diagramPanel.IsEditing
diagramPanel.IsEditing = value
Whether editing is enabled.
public ICompositionModel Model { get; set; }
value = diagramPanel.Model
diagramPanel.Model = value
The diagram model to display.
public Point PanOffset { get; set; }
value = diagramPanel.PanOffset
diagramPanel.PanOffset = value
Pan offset for scrolling.
public string SelectedNodeKey { get; set; }
value = diagramPanel.SelectedNodeKey
diagramPanel.SelectedNodeKey = value
Key of the selected node.
public IReadOnlySet<string> SelectedNodeKeys { get; }
value = diagramPanel.SelectedNodeKeys
Get all selected node keys.
public double Zoom { get; set; }
value = diagramPanel.Zoom
diagramPanel.Zoom = value
Current zoom level.
Methods
public void AddToSelection(string nodeKey)
diagramPanel.AddToSelection(nodeKey)
Add a node to the selection.
public void ClearDropTargetHighlight()
diagramPanel.ClearDropTargetHighlight()
Clears any drop target highlighting.
public void DeleteLink(string fromNodeKey, string fromSocketId, string toNodeKey, string toSocketId)
diagramPanel.DeleteLink(fromNodeKey, fromSocketId, toNodeKey, toSocketId)
Delete the link between two sockets.
public void DeleteSelected()
diagramPanel.DeleteSelected()
Delete selected nodes and their connected links.
public Point DiagramToScreen(Point diagram)
result = diagramPanel.DiagramToScreen(diagram)
Converts a diagram coordinate to screen coordinate.
- diagram
- Diagram coordinate.
Returns: Screen coordinate relative to this control.
public string GetNodeAtPosition(Point screenPosition)
result = diagramPanel.GetNodeAtPosition(screenPosition)
Gets the node key at the specified screen position, if any.
- screenPosition
- Screen position to test.
Returns: Node key if found, null otherwise.
public void HideDragPreview()
diagramPanel.HideDragPreview()
Hides the drag preview.
public void HighlightDropTarget(string nodeKey, bool isValid)
diagramPanel.HighlightDropTarget(nodeKey, isValid)
Highlights a node as a potential drop target.
- nodeKey
- Key of the node to highlight, or null to clear.
- isValid
- Whether this is a valid drop target.
protected override void OnPointerMoved(PointerEventArgs e)
diagramPanel.OnPointerMoved(e)
protected override void OnPointerPressed(PointerPressedEventArgs e)
diagramPanel.OnPointerPressed(e)
protected override void OnPointerReleased(PointerReleasedEventArgs e)
diagramPanel.OnPointerReleased(e)
protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
diagramPanel.OnPointerWheelChanged(e)
public Point ScreenToDiagram(Point screen)
result = diagramPanel.ScreenToDiagram(screen)
Converts a screen coordinate to diagram coordinate.
- screen
- Screen coordinate relative to this control.
Returns: Diagram coordinate.
public void ShowDragPreview(Point screenPosition, string elementName, Color? previewColor)
diagramPanel.ShowDragPreview(screenPosition, elementName, previewColor)
Shows a drag preview ghost at the specified screen position.
- screenPosition
- Screen position relative to this control.
- elementName
- Name to display in the preview.
- previewColor
- Optional custom color for the preview.
public void UpdateDragPreview(Point screenPosition)
diagramPanel.UpdateDragPreview(screenPosition)
Updates the drag preview position during drag.
- screenPosition
- New screen position.
Events
public event EventHandler ModelModified
diagramPanel.ModelModified += handler
Occurs when the diagram model is modified.
public event EventHandler<string> SelectionChanged
diagramPanel.SelectionChanged += handler
Occurs when the selected node changes.
Fields
public static readonly StyledProperty<bool> IsEditingProperty
value = DiagramPanel.IsEditingProperty
Identifies the IsEditing dependency property.
public static readonly StyledProperty<ICompositionModel> ModelProperty
value = DiagramPanel.ModelProperty
Identifies the Model dependency property.
public static readonly StyledProperty<Point> PanOffsetProperty
value = DiagramPanel.PanOffsetProperty
Identifies the PanOffset dependency property.
public static readonly StyledProperty<string> SelectedNodeKeyProperty
value = DiagramPanel.SelectedNodeKeyProperty
Identifies the SelectedNodeKey dependency property.
public static readonly StyledProperty<double> ZoomProperty
value = DiagramPanel.ZoomProperty
Identifies the Zoom dependency property.