[Linux] No Fields from xaml in Code Behind
Hello Everyone,
when I add a UserControl to my Avalonia Project, the Code Behind is created alongside the axaml but I can not access the controls from the Code Behind (as described here: https://docs.avaloniaui.net/docs/fundamentals/code-behind).
I can, however, create an eventHandler automatically.
Let me give you an Example:
<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="Todo.Helper.CustomControls.TestControl">
<Button Name="greetingButton">Hello World</Button>
</UserControl>using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Todo.Helper.CustomControls;
public partial class TestControl : UserControl
{
public TestControl()
{
InitializeComponent();
greetingButton.Content = "Goodbye Cruel World!";
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}The greetingButton.Content is marked and I get the Error “Cannot resolve symbol ‘greetingButton’" and the application cannot be built.
Additionally I have to add the InitializeComponent() method manually, or the call gets marked. This has no effect on the application.
I use Bazzite and Rider has the Version 2026.2.1
Thank you in advance!
Please sign in to leave a comment.