AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.47k stars 2.21k forks source link

AttachedToVisualTree or Loaded on UserControl gives Invalid Markup #16749

Open Dakar2008Inropa opened 1 month ago

Dakar2008Inropa commented 1 month ago

Describe the bug

When trying to use AttachedToVisualTree or Loaded on a UserControl element it gives an Invalid Markup in the axaml designer.

To Reproduce

<UserControl xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="AvaloniaPad.MainView" Name="MainViewUC" Loaded="UserControl_Loaded"></UserControl>

Expected behavior

No response

Avalonia version

11.1.3

OS

Windows

Additional context

No response

workgroupengineering commented 1 month ago

The known issue has been fixed in 11.2-beta1.

Workaround, add the code as follows to your user control

    public static void AddLoadedHandler(Interactive element, EventHandler<RoutedEventArgs> handler)
    {
        element.AddHandler(LoadedEvent, handler);
    }