DiagramEditorControl
Avalonia diagram editor control with toolbar and keyboard shortcuts.
Inherits: UserControl
Constructors
public DiagramEditorControl()
diagramEditorControl = DiagramEditorControl()
Initializes a new instance of the DiagramEditorControl.
Properties
public bool CanPaste { get; }
value = diagramEditorControl.CanPaste
Whether paste is available.
public bool CanRedo { get; }
value = diagramEditorControl.CanRedo
Whether redo is available.
public bool CanUndo { get; }
value = diagramEditorControl.CanUndo
Whether undo is available.
public CompositionDiagramElement Composition { get; set; }
value = diagramEditorControl.Composition
diagramEditorControl.Composition = value
The composition element being edited.
public bool IsEditing { get; set; }
value = diagramEditorControl.IsEditing
diagramEditorControl.IsEditing = value
Whether editing is enabled.
public DiagramElement SelectedElement { get; }
value = diagramEditorControl.SelectedElement
Selected element.
public string SelectedNodeKey { get; }
value = diagramEditorControl.SelectedNodeKey
Selected node key.
public bool ShowToolbar { get; set; }
value = diagramEditorControl.ShowToolbar
diagramEditorControl.ShowToolbar = value
Whether to show the toolbar.
public double Zoom { get; set; }
value = diagramEditorControl.Zoom
diagramEditorControl.Zoom = value
Current zoom level.
Methods
public void AddElement(DiagramElement element)
diagramEditorControl.AddElement(element)
Adds an element to the diagram at default position (0, 0).
- element
- The element to add.
public void AddElementAt(DiagramElement element, double x, double y)
diagramEditorControl.AddElementAt(element, x, y)
Adds an element to the diagram at specified position.
- element
- The element to add.
- x
- X position on canvas (diagram coordinates).
- y
- Y position on canvas (diagram coordinates).
public void ClearDiagram()
diagramEditorControl.ClearDiagram()
Clear all elements from the diagram.
public void ConnectPalette(DiagramPaletteControl palette)
diagramEditorControl.ConnectPalette(palette)
Connects a palette control to this editor for drag-drop support.
- palette
- The palette control to connect.
public void DisconnectPalette(DiagramPaletteControl palette)
diagramEditorControl.DisconnectPalette(palette)
Disconnects a palette control from this editor.
- palette
- The palette control to disconnect.
public void ExportToImage(string filePath, ExportOptions options)
diagramEditorControl.ExportToImage(filePath, options)
Export the diagram to an image file.
- filePath
- The output file path.
- options
- Export options. If null, uses defaults.
public byte[] ExportToImageBytes(ExportOptions options)
result = diagramEditorControl.ExportToImageBytes(options)
Export the diagram to a byte array.
- options
- Export options. If null, uses defaults.
Returns: The image data as bytes, or null if export failed.
public void ExportToImageStream(Stream stream, ExportOptions options)
diagramEditorControl.ExportToImageStream(stream, options)
Export the diagram to an image stream.
- stream
- The output stream.
- options
- Export options. If null, uses defaults.
public void HandleDrop(DragEventArgs e)
diagramEditorControl.HandleDrop(e)
Handle drop event on the panel. Call this from DragOver/Drop events.
public DiagramElement HandlePaletteDrop(PaletteItem item, Point dropPosition)
result = diagramEditorControl.HandlePaletteDrop(item, dropPosition)
Handles drag events from a palette control. Call this from the palette's DragStarted event handler.
- item
- The palette item being dragged.
- dropPosition
- The position on the panel where the item was dropped (screen coordinates).
Returns: The created element, or null if creation failed.
public static DiagramFileData LoadFromFile(string filePath)
result = DiagramEditorControl.LoadFromFile(filePath)
Load diagram data from a file. Note: This only returns the data structure. Use composition loading for full restore.
- filePath
- The file path to load from.
Returns: Diagram file data, or null if invalid.
public static DiagramFileData LoadFromStream(Stream stream)
result = DiagramEditorControl.LoadFromStream(stream)
Load diagram data from a stream. Note: This only returns the data structure. Use composition loading for full restore.
- stream
- The stream to read from.
Returns: Diagram file data, or null if invalid.
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
diagramEditorControl.OnPropertyChanged(change)
public bool RestoreDiagram(DiagramFileData data, ElementFactory elementFactory)
result = diagramEditorControl.RestoreDiagram(data, elementFactory)
Restore a diagram from file data into the current composition.
- data
- The file data to restore from.
- elementFactory
- Optional factory for creating elements by type.
Returns: True if restore was successful.
public bool RestoreFromFile(string filePath, ElementFactory elementFactory)
result = diagramEditorControl.RestoreFromFile(filePath, elementFactory)
Restore a diagram from a file into the current composition.
- filePath
- The file path to restore from.
- elementFactory
- Optional factory for creating elements by type.
Returns: True if restore was successful.
public void SaveToFile(string filePath)
diagramEditorControl.SaveToFile(filePath)
Save the diagram to a file.
- filePath
- The file path to save to.
public void SaveToStream(Stream stream)
diagramEditorControl.SaveToStream(stream)
Save the diagram to a stream.
- stream
- The stream to write to.
public string SaveToString()
result = diagramEditorControl.SaveToString()
Save the diagram to a JSON string.
Returns: JSON representation of the diagram.
Events
public event EventHandler ModelModified
diagramEditorControl.ModelModified += handler
Occurs when the diagram model is modified.
public event EventHandler<DiagramElement> SelectionChanged
diagramEditorControl.SelectionChanged += handler
Occurs when the selected diagram element changes.
Fields
public static readonly StyledProperty<CompositionDiagramElement> CompositionProperty
value = DiagramEditorControl.CompositionProperty
Identifies the Composition dependency property.
public static readonly StyledProperty<bool> IsEditingProperty
value = DiagramEditorControl.IsEditingProperty
Identifies the IsEditing dependency property.
public static readonly StyledProperty<bool> ShowToolbarProperty
value = DiagramEditorControl.ShowToolbarProperty
Identifies the ShowToolbar dependency property.