amwx / FluentAvalonia

Control library focused on fluent design and bringing more WinUI controls into Avalonia
MIT License
985 stars 93 forks source link

NumberBox crashes if there is a bindings to the ViewModel #566

Closed DkmS1953 closed 4 months ago

DkmS1953 commented 4 months ago

Describe the bug A clear and concise description of what the bug is and any steps to reproduce it. Sample code or a minimal repro is helpful.

  1. Create the Avalonia MVVM project
  2. Place NumberBox control in the main window
  3. Create TestNumberBox property in the model
  4. Bind 2 and 3 with Value="{Binding TestNumberBox}".
  5. Run the program, click on the number in the field, see the NumberBox tools.
  6. Click on ✖
  7. The program crashes (if it is run under the debugger, it will show an exception in the Main method). Screenshots If applicable, add screenshots to help explain your problem. image image

Desktop/Platform (please complete the following information):

Additional context Controls without bindings react normally - after clearing they show the placeholder text.

There is a test project in the attachment. NumberBox.MvvM.zip

amwx commented 4 months ago

Your ViewModel property type needs to match the type of Value from NumberBox, which is double. The binding system won't do that conversion for you.

DkmS1953 commented 4 months ago

Is this supposed to be a joke? All right.

timunie commented 4 months ago

If you clear it, it makes your value null. If your property isn't nullable, that throws if you have compiled bindings enabled. ReflectionBinding can handle it. This is by design.