看起来ViewModel会更新条目的聚焦状态(基于用户交互),但在ViewModel中的绑定属性上设置值没有效果。
我认为:
<Entry IsFocused="{Binding Focused, Mode=TwoWay}"/>
在我的ViewModel中:
public bool Focused { get { return _focused; } set { _focused = value; // This gets invoked on user interaction with UI, but setting it programatically has no effect on the Entry's focus. OnPropertyChanged(nameof(Focused)); } }
为什么上面这些对我不起作用?
是因为 IsFocussed 是只读的吗?如果是这样,为什么我甚至可以指定 Mode=TwoWay ?
IsFocussed
Mode=TwoWay
public bool IsFocused { get { return (bool)GetValue(IsFocusedProperty); } }
你猜对了 IsFocused 属性确实是只读的。
IsFocused
它们确实可以在setter中抛出一个异常,但设计决策是困难的,必须在所有ui元素之间保持一致。