Skip to content

OneWayBind Null Value throws #2476

@stokara

Description

@stokara

OneWayBind throws an error when the value is null

The vm has a reactiveProperty called appointment which itself has a reactive DateTime property Canceled

this.OneWayBind(ViewModel, vm => vm.Appointment.Canceled, v => v.CanceledDateTime.Text, dt => dt?.ToString("G"));

compiles but at runtime when vm.Appointment.Canceled is null throws System.ArgumentNullException
message: Value cannot be null.
Parameter name: paramValue

It looks like BindToDirect,(PropertyBinderImplementation.cs line 322) is looking for a setter, but it is a oneWayBind so there is no setter

Changing to Bind gets around the problem:
this.Bind(ViewModel, vm => vm.Appointment.Canceled, v => v.CanceledDateTime.Text, dt => dt?.ToString("G"), s=> s == "" ? (DateTime?) null : DateTime.Parse(s));

Environment

  • OS: Windows 10, WPF
  • Version 11.5.6

This behavior works as expected, i. e. The bound value can be null when using OneWayBind in version 11.4.17

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions