-2

我有一个 TimeSpan 类型的 DependencyProperty 控件。当我尝试绑定到该属性时,该值没有被更新。

控件的使用:

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

当我更改控件中的时间值时,更改不会在 SomeTimeSpanProperty 中更新。但是,如果我将{Binding SomeTimeSpanProperty}更改为{Binding SomeTimeSpanProperty,Mode=OneWayToSource},它就会更新。

4

1 回答 1

0

我找到了解决方案。如果将来有人读到这篇文章想知道它是什么:

我必须将绑定模式显式设置为 TwoWay,因为 TimeSpan 类型属性的默认绑定模式是 OneWay。

由此:

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

对此:

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

现在它起作用了

于 2016-07-15T21:07:41.387 回答