### Minimal NodifyEditor Setup in XAML
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
This XAML demonstrates the basic setup for NodifyEditor, binding essential collections and commands. It includes templates for grid lines, connections, pending connections, and nodes.
```xml
```
--------------------------------
### NodifyEditor XAML Setup
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
This snippet shows a minimal XAML setup for the NodifyEditor, demonstrating how to bind essential properties like ItemsSource, Connections, and Zoom, and how to define templates for grid lines, connections, pending connections, and nodes.
```APIDOC
## NodifyEditor XAML Setup
### Description
This is a minimal XAML setup for the `NodifyEditor` control. It demonstrates binding to node and connection collections, handling pending connections, and configuring visual elements like grid lines, connections, pending connections, and nodes through `DataTemplate` definitions.
### XAML
```xml
```
```
--------------------------------
### Full Node Usage with Customization
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
Example of a Node control with a custom header, input/output connectors, and resize enabled. This demonstrates how to bind properties like Location, Input, and Output, and how to define custom templates for connectors.
```xml
```
--------------------------------
### ConnectorViewModelBase Properties and Static Flags
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
Provides an example of a custom ConnectorViewModelBase implementation and demonstrates setting static flags on the Connector type to enable specific behaviors like sticky connections and cancellation.
```csharp
// Connector properties on ConnectorViewModelBase
public partial class MyConnectorVm : ConnectorViewModelBase
{
// Anchor is updated automatically by the Connector control
// IsConnected controls visual state and whether Disconnect fires
// Flow drives the connection direction converter
}
// Static flags on the Connector type
Connector.EnableStickyConnections = true; // two-click connect mode
Connector.AllowPendingConnectionCancellation = true; // right-click cancels drag
```
--------------------------------
### PendingConnectionViewModelBase Implementation
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
The ViewModelBase for PendingConnection handles the logic for starting and finishing connection drags. It requires an IEditor instance to perform connection operations.
```csharp
// Corresponding view model (provided by PendingConnectionViewModelBase)
public partial class PendingConnectionViewModelBase : ObservableObject
{
[ObservableProperty] private ConnectorViewModelBase? _source;
[ObservableProperty] private object? _previewTarget; // bound OneWayToSource
[ObservableProperty] private string? _previewText;
[RelayCommand] public void Start(ConnectorViewModelBase item) => Source = item;
[RelayCommand] public void Finish(ConnectorViewModelBase? target)
{
if (target == null || target == Source) return;
_editor.Connect(Source, target);
}
}
```
--------------------------------
### Programmatic KnotNode Creation and Connection
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
Shows how to create a KnotNodeViewModel programmatically, add it to the Nodes collection, and establish connections through its connector. This also illustrates splitting an existing connection.
```csharp
// Creating a KnotNode programmatically and connecting through it
var knot = new KnotNodeViewModel { Location = new Point(200, 150) };
Nodes.Add(knot);
knot.Connector.IsConnected = true;
// Split an existing connection at a point
// (ConnectionViewModelBase.SplitConnectionCommand does this automatically)
Connections.Add(new ConnectionViewModelBase(this, sourceConnector, knot.Connector));
Connections.Add(new ConnectionViewModelBase(this, knot.Connector, targetConnector));
```
--------------------------------
### Programmatic NodeGroup Construction
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
Illustrates the programmatic creation of a NodeGroupViewModel, setting its initial properties such as Location, Header, Size, and CanResize, and adding it to the Nodes collection.
```csharp
// Programmatic NodeGroup construction
var group = new NodeGroupViewModel // implement BaseNodeViewModel
{
Location = new Point(0, 0),
Header = "Processing Stage",
Size = new Size(400, 300),
CanResize = true
};
Nodes.Add(group);
```
--------------------------------
### Create ConnectionViewModelBase Instance
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
Instantiate ConnectionViewModelBase directly to represent a wire between two connectors. This class manages connection data and exposes commands for manipulation.
```csharp
// Direct construction
var conn = new ConnectionViewModelBase(editorVm, sourceConnector, targetConnector, "Data flow");
// Splitting a connection at a point (creates a KnotNode automatically)
// Triggered in XAML via: SplitCommand="{Binding SplitConnectionCommand}"
// Parameter passed by BaseConnection is the Point where the doubleclick occurred
// Removing a connection
// Triggered via: DisconnectCommand="{Binding DisconnectConnectionCommand}"
// or from the editor: RemoveConnectionCommand="{Binding RemoveConnectionCommand}"
```
--------------------------------
### Toggle Theme at Runtime
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
Switches the application's theme between dark and light variants programmatically. Ensure `Application.Current` is not null.
```csharp
// Toggle theme at runtime
private void ToggleTheme()
{
Application.Current!.RequestedThemeVariant =
Application.Current.ActualThemeVariant == ThemeVariant.Dark
? ThemeVariant.Light
: ThemeVariant.Dark;
}
```
--------------------------------
### Applying Dark Theme in App.axaml
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
Applies the built-in dark theme for NodifyM. Avalonia styles are automatically loaded via compiled bindings.
```xml
```
--------------------------------
### Create ConnectorViewModelBase Instances
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
Define ConnectorViewModelBase objects to represent input and output pins on nodes. The 'Anchor' property is automatically managed by the Connector control.
```csharp
var outputPin = new ConnectorViewModelBase
{
Title = "Result",
Flow = ConnectorViewModelBase.ConnectorFlow.Output,
IsConnected = false,
// Anchor is set automatically by the Connector control
};
var inputPin = new ConnectorViewModelBase
{
Title = "Value",
Flow = ConnectorViewModelBase.ConnectorFlow.Input
};
```
--------------------------------
### Smooth Bézier Connection with Label
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
Use Connection to draw a smooth cubic Bézier curve between two anchors. Supports labels, arrowheads, and commands for splitting or disconnecting.
```xml
```
--------------------------------
### Subscribe to BaseNode Events
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
Demonstrates how to subscribe to LocationChanged and IsSelectChanged events on a BaseNode instance. Programmatically setting the Location property will trigger the LocationChanged event.
```csharp
// Subscribing to location changes on a BaseNode instance
baseNode.LocationChanged += (sender, e) =>
{
// e.Location contains the new Point
Console.WriteLine($"Node moved to {e.Location}");
};
baseNode.IsSelectChanged += (sender, e) =>
{
Console.WriteLine($"Node selected: {e.IsSelected}");
};
// Setting location programmatically triggers the LocationChanged event
baseNode.Location = new Point(200, 150);
```
--------------------------------
### NodeInput with Label
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
Use NodeInput to define an input point for a node, optionally including a header with a label and icon.
```xml
```
--------------------------------
### Configure PendingConnection in XAML
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
Use PendingConnection to display a visual indicator while dragging a connection. Configure its appearance and behavior through XAML properties.
```xml
```
--------------------------------
### Custom GraphViewModel Implementation
Source: https://context7.com/maklith/nodifym.avalonia/llms.txt
Subclass NodifyEditorViewModelBase to create a custom graph view model. Override the Connect method for custom validation logic, such as preventing self-connections. The DisconnectConnector method can also be overridden for custom actions.
```csharp
using NodifyM.Avalonia.ViewModelBase;
using System.Collections.ObjectModel;
using Avalonia;
public partial class GraphViewModel : NodifyEditorViewModelBase
{
public GraphViewModel()
{
// Create connectors
var outA = new ConnectorViewModelBase { Title = "Out", Flow = ConnectorViewModelBase.ConnectorFlow.Output };
var inB = new ConnectorViewModelBase { Title = "In", Flow = ConnectorViewModelBase.ConnectorFlow.Input };
// Create nodes
Nodes.Add(new NodeViewModelBase
{
Title = "Node A",
Location = new Point(50, 100),
Output = new ObservableCollection