Avalonia Events logo

Avalonia Events

Community
linuxdevel
avalonia-events

Use when working with Avalonia routed events — defining custom RoutedEvent, handling bubbling or tunneling events, attaching handlers with AddHandler, RoutingStrategies, the OnApplyTemplate/PART_ pattern, or class-level static handlers via AddClassHandler.

Overview

Publisherlinuxdevel
RepositoryAvalonia-skills
Skill nameavalonia-events
Stars
50
Forks
4
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by linuxdevel on GitHub. Read the source before you install it.

Installation

Install the Avalonia Events AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/linuxdevel/Avalonia-skills/tree/main/skills/avalonia/avalonia-events
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/linuxdevel/Avalonia-skills.git /tmp/Avalonia-skills
mkdir -p .claude/skills
cp -r /tmp/Avalonia-skills/skills/avalonia/avalonia-events .claude/skills/avalonia-events
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Avalonia Events in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Avalonia Events on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Avalonia Events is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Avalonia Routed Events

Overview

Avalonia uses routed events that travel the logical tree. Three strategies:

  • Bubble — source → root (default for most input events)
  • Tunnel — root → source (Preview prefix by convention)
  • Direct — only raised on source element

All input events (PointerPressed, KeyDown, etc.) are routed. Version labels: see avalonia-versions.

Handling Events

XAML:

xml
<Button Click="Button_Click"/>
<StackPanel PointerPressed="Panel_PointerPressed"/>

Code-behind (direct +=):

csharp
myButton.Click += Button_Click;
private void Button_Click(object? sender, RoutedEventArgs e) { }

AddHandler — explicit routing strategy, required for tunneling:

csharp
// Catch bubbled clicks from any child Button
myPanel.AddHandler(Button.ClickEvent, OnAnyButtonClick, RoutingStrategies.Bubble);

// Intercept before children see it (tunneling)
myPanel.AddHandler(InputElement.PointerPressedEvent, OnPreviewPointerPressed,
    RoutingStrategies.Tunnel);

private void OnAnyButtonClick(object? sender, RoutedEventArgs e)
{
    Console.WriteLine($"Clicked: {e.Source}");
}

Remove handler:

csharp
myPanel.RemoveHandler(Button.ClickEvent, OnAnyButtonClick);

Stopping Propagation

csharp
private void OnKeyDown(object? sender, KeyEventArgs e)
{
    if (e.Key == Key.Escape)
    {
        e.Handled = true; // stops further bubbling/tunneling
    }
}

e.Handled = true prevents subsequent handlers in the route from firing.

Defining Custom Routed Events

csharp
public class MyControl : Control
{
    // Event registration
    public static readonly RoutedEvent<RoutedEventArgs> ActivatedEvent =
        RoutedEvent.Register<MyControl, RoutedEventArgs>(
            name: "Activated",
            routingStrategy: RoutingStrategies.Bubble);

    // CLR event wrapper
    public event EventHandler<RoutedEventArgs> Activated
    {
        add => AddHandler(ActivatedEvent, value);
        remove => RemoveHandler(ActivatedEvent, value);
    }

    // Raise it
    protected void RaiseActivated()
        => RaiseEvent(new RoutedEventArgs(ActivatedEvent, this));
}

Custom event args:

csharp
public class ValueChangedEventArgs : RoutedEventArgs
{
    public double OldValue { get; }
    public double NewValue { get; }

    public ValueChangedEventArgs(RoutedEvent routedEvent, object source,
        double oldValue, double newValue)
        : base(routedEvent, source)
    {
        OldValue = oldValue;
        NewValue = newValue;
    }
}

public static readonly RoutedEvent<ValueChangedEventArgs> ValueChangedEvent =
    RoutedEvent.Register<MyControl, ValueChangedEventArgs>(
        "ValueChanged", RoutingStrategies.Bubble);

Tunneling Events (Preview)

Convention: tunneling events prefixed with Preview.

csharp
public static readonly RoutedEvent<PointerPressedEventArgs> PreviewPointerPressedEvent =
    RoutedEvent.Register<InputElement, PointerPressedEventArgs>(
        "PreviewPointerPressed",
        RoutingStrategies.Tunnel);

Use pattern:

csharp
// Parent intercepts before child
myParent.AddHandler(InputElement.PointerPressedEvent, Handler, RoutingStrategies.Tunnel);

RoutingStrategies Enum

ValueMeaning
DirectOnly raised on source element
BubbleSource → root
TunnelRoot → source
AllBoth tunnel and bubble (fire twice)

OnApplyTemplate Pattern

Called when ControlTemplate is applied. Use to wire up named template parts:

csharp
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
    base.OnApplyTemplate(e);

    // Get required part (throws if missing)
    _button = e.NameScope.Get<Button>("PART_Button");
    _button.Click += OnPartButtonClick;

    // Get optional part (returns null if missing)
    _indicator = e.NameScope.Find<Border>("PART_Indicator");
}

// Clean up old subscriptions if template changes
private Button? _button;
private Border? _indicator;

Template XAML:

xml
<ControlTemplate TargetType="local:MyControl">
    <StackPanel>
        <Border Name="PART_Indicator" Background="Gray"/>
        <Button Name="PART_Button" Content="Click"/>
    </StackPanel>
</ControlTemplate>

Convention: template part names prefixed with PART_.

Declare expected parts (documentation + tooling):

csharp
[TemplatePart("PART_Button", typeof(Button))]
[TemplatePart("PART_Indicator", typeof(Border))]
public class MyControl : TemplatedControl { }

Class Handlers (Static, All Instances)

csharp
static MyControl()
{
    // Fires for every instance when a child Button is clicked
    Button.ClickEvent.AddClassHandler<MyControl>((instance, e) =>
        instance.OnChildButtonClicked(e));

    // Intercept tunneling on all instances
    InputElement.PointerPressedEvent.AddClassHandler<MyControl>(
        (instance, e) => instance.OnPreviewPointerPressed(e),
        RoutingStrategies.Tunnel);
}

private void OnChildButtonClicked(RoutedEventArgs e)
{
    Console.WriteLine($"Button clicked in {this}");
}

Focus and Gesture Events

csharp
// (12.0+) FocusChangedEventArgs: OldFocusedElement, NewFocusedElement, NavigationMethod, KeyModifiers
private void OnGotFocus(object? sender, FocusChangedEventArgs e) { }
// (11.x) GotFocusEventArgs

(12.0+) Cancellable: GettingFocus / LosingFocus raise FocusChangingEventArgs (TryCancel(), TrySetNewFocusedElement(el)).

Gesture events are routed events declared on InputElement: Tapped, RightTapped, DoubleTapped, Holding, Pinch, PinchEnded, PullGesture, ScrollGesture, SwipeGesture, etc.

xml
<Border Pinch="OnPinch"/>              <!-- (12.0+) -->
<Border Gestures.Pinch="OnPinch"/>     <!-- (11.x) -->
csharp
myPanel.AddHandler(InputElement.TappedEvent, OnTapped);   // works in all versions

Interaction Events (Non-Routed) vs Routed

Control.AttachedToVisualTree / DetachedFromVisualTree — not routed, fires on control directly:

csharp
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
    base.OnAttachedToVisualTree(e);
    // Safe to access TopLevel, start subscriptions
}

protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
    base.OnDetachedFromVisualTree(e);
    // Clean up subscriptions
}

Common Mistakes

  • += vs AddHandler routing strategies — myPanel.PointerPressed += Handler only catches Bubble by default; use AddHandler with RoutingStrategies.Tunnel for preview intercept
  • Tunnel events won't fire with default Bubble strategy — must explicitly pass RoutingStrategies.Tunnel to AddHandler
  • new RoutedEventArgs(MyEvent) missing source — always pass this as source: new RoutedEventArgs(MyEvent, this)
  • Forgetting e.Handled = true in a handler that should consume the event — other handlers in the route still fire
  • OnApplyTemplate without cleaning up previous subscriptions — template can be re-applied; detach old handlers before attaching new ones
  • (12.0+) GotFocusEventArgs / Gestures. prefix — replaced by FocusChangedEventArgs / events directly on InputElement
  • e.NameScope.Get<T> throws if part missing — use Find<T> for optional parts to avoid KeyNotFoundException

Frequently asked questions

What does the Avalonia Events AI skill do?

Use when working with Avalonia routed events — defining custom RoutedEvent, handling bubbling or tunneling events, attaching handlers with AddHandler, RoutingStrategies, the OnApplyTemplate/PART_ pattern, or class-level static handlers via AddClassHandler.

Why use Avalonia Events on TypingMind?

Because you install it once and use it with any model. Avalonia Events is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Avalonia Events in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/linuxdevel/Avalonia-skills/tree/main/skills/avalonia/avalonia-events. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Avalonia Events?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Avalonia Events?

As many as you like. As long as a model supports skills, you can use Avalonia Events with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Avalonia Events AI skill free?

Yes. It is published on GitHub by linuxdevel under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇