Skip to content

[Bug]: AvaloniaCreatesCommandBinding has different behaviour from CreatesCommandBindingViaCommandParameter #122

@deryaza

Description

@deryaza

Describe the bug 🐞

AvaloniaCreatesCommandBinding throws if command is null:

https://github.com/reactiveui/ReactiveUI.Avalonia/blob/main/src/ReactiveUI.Avalonia/AvaloniaCreatesCommandBinding.cs#L76

While default impl does not:

https://github.com/reactiveui/ReactiveUI/blob/main/src/ReactiveUI/Bindings/Command/CreatesCommandBindingViaCommandParameter.cs#L85

Step to reproduce

In view:

this.BindCommand(ViewModel, x => x.LeCommand, x => x.Btn);

And example view model:

using System.Windows.Input;
using ReactiveUI;

namespace ReactiveUIDemo.ViewModels
{
    internal class FooViewModel : ReactiveObject, IRoutableViewModel
    {
        public FooViewModel(IScreen screen) => HostScreen = screen;
        public string UrlPathSegment => "Foo";
        public IScreen HostScreen { get; }
        
        public ICommand? LeCommand { get; }
    }
}

Reproduction repository

https://github.com/reactiveui/ReactiveUI

Expected behavior

ViewModel's null command property should be set in the control

Screenshots 🖼️

No response

IDE

No response

Operating system

No response

Version

No response

Device

No response

ReactiveUI.Avalonia Version

No response

Additional information ℹ️

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions