question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to find suitable setter or adder for property when using binding for usercontrols

See original GitHub issue

I’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:open
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
MarchingCubecommented, Mar 20, 2020

@grokys I guess another part that needs to be covered in updated documentation for properties.

1reaction
Gillibaldcommented, Mar 20, 2020

You need to fulfill the naming convention.

string String { get.... ; set....} AvaloniaProperty StringProperty

Read more comments on GitHub >

github_iconTop Results From Across the Web

Button will not work, unable to find suitable setter or getter
'Unable to find suitable setter or adder for property Click of type Avalonia.Controls:Avalonia.Controls.Button for argument Avalonia.Markup: ...
Read more >
Unable to find a setter that allows multiple assignments to the ...
Unable to find a setter that allows multiple assignments to the property Content of type Avalonia.Controls:Avalonia.Controls.ContentControl.
Read more >
UserControl Class - Typedescriptor
Unable to find suitable setter or adder for property when using binding for usercontrols #3682. Open cemeceme on Sep 16 2020 / AvaloniaUI/Avalonia....
Read more >
Creating and binding Attached Properties
First we have to create our attached property. The method AvaloniaProperty.RegisterAttached is used for that purpose. Note that by convention the public static ......
Read more >
Avalonia user control with design time XAML property setter
1 Answer. By 'default' the preference is to use a StyledProperty , as these can be bound or styled. If you don't need...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found