Search code examples
c#wpfmvvmbindingtwo-way

WPF Binding TwoWay not working, OneWayToSource working. WHY?


I have a control with a DependencyProperty of type TimeSpan. When I try to bind to that property, the value is not being updated.

Usage of the control:

<controls:TimeControl Time={Binding SomeTimeSpanProperty} />

When I change the value of the Time in the Control, the change is not updated in the SomeTimeSpanProperty. However, if I change the {Binding SomeTimeSpanProperty} to {Binding SomeTimeSpanProperty,Mode=OneWayToSource}, it is updated.


Solution

  • I found the solution. If anyone reading this in the future wants to know what was it:

    I had to explicitly set the mode of the binding to TwoWay, because the default binding mode for the TimeSpan type property is OneWay.

    from this:

    <controls:TimeControl Time={Binding SomeTimeSpanProperty} />
    

    to this:

    <controls:TimeControl Time={Binding SomeTimeSpanProperty,Mode=TwoWay} />
    

    And now it works!