Unable to find suitable setter or adder for property when using binding for usercontrols
See original GitHub issueI’m trying to create a usercontrol that will accept some properties, however it appears that it fails with the error:
Error XAMLIL: Unable to find suitable setter or adder for property stringProperty of type Client:Client.test for argument Avalonia.Markup:Avalonia.Data.Binding, available setter parameter lists are:
System.String
The main window xaml is:
<Window 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"
xmlns:local="clr-namespace:Client"
x:Class="Client.MainWindow"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600"
Title="Title" Background="LightGray" Width="800" Height="600">
<TextBlock Text="{Binding dataString}"/>
<local:test stringProperty="{Binding dataString}"/>
</Window>
MainWindows ViewModel is:
namespace Client
{
public class MainWindowViewModel
{
public string dataString{ get{ return("sample text");} }
}
}
The test xaml is:
<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"
x:Class="Client.test" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450">
<TextBlock Text="Some text"/>
</UserControl>
And the code-behind for test is:
namespace Client
{
public class test : UserControl
{
public string stringProperty { get; set; }
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
public test()
{
this.InitializeComponent();
}
}
}
I have also tried to use direct/attached/styled/etc. properties, but nothing seems to have helped.
One thing I have noticed however, is that when not using databinding in the main window, the code does compile and work as expected. I left out bindings in the usercontrol and related code to make sure that wasn’t causing the issue, and when using just a static string the property is indeed set properly.
I’m fairly new to Avalonia and mvvm so I might have misconceptions about how usercontrols and their properties work. So if this is intended behavior and I’m using the wrong control or something do tell me, as I have been stuck for the past few days.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
@grokys I guess another part that needs to be covered in updated documentation for properties.
You need to fulfill the naming convention.
string String { get.... ; set....}AvaloniaProperty StringProperty