Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use mvvm to bind #15756

Closed
MarkoShenodaa opened this issue May 17, 2024 · 2 comments
Closed

Can't use mvvm to bind #15756

MarkoShenodaa opened this issue May 17, 2024 · 2 comments
Labels

Comments

@MarkoShenodaa
Copy link

Describe the bug

Unable to resolve property or method of name 'ClickCommand' on type 'AvaloniaApplication2.ViewModels.MainViewModel'.

I start new Avalonia App as it is just add one more property and one command to test.

here is the code


<UserControl.DataContext>
<vm:MainViewModel />
</UserControl.DataContext>




public partial class MainViewModel : ViewModelBase
{
public MainViewModel()
{
ButtonTitle = "Click me";
}
private int count = 0;

[ObservableProperty]
private string _greeting = "Welcome to Avalonia!";

[ObservableProperty]
private string _buttonTitle ;

[RelayCommand]
public void Click()
{
    count++;

    if (count == 1) 
    {
        ButtonTitle = $"You Clicked Me {count} Time";
        return; 
    }

    ButtonTitle = $"You Clicked Me {count} Times";
}

}

To Reproduce

just start new project and add the property and the command

Expected behavior

No response

Avalonia version

11.0.2

OS

No response

Additional context

No response

@stevemonaco
Copy link
Contributor

This almost certainly isn't a bug and should be moved to discussions.

But what XAML are you using? Particularly, the entirety of your <Button ... />

@thevortexcloud
Copy link
Contributor

I am guessing this is a casting problem. In which case you can either cast to your view model type or use reflection binding.

https://docs.avaloniaui.net/docs/basics/data/data-binding/compiled-bindings#type-casting

@timunie timunie added question and removed bug labels May 19, 2024
@AvaloniaUI AvaloniaUI locked and limited conversation to collaborators May 21, 2024
@timunie timunie converted this issue into discussion #15773 May 21, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

4 participants