1 回答
TA貢獻1802條經驗 獲得超4個贊
Binding 必須是 TwoWay,或者顯式設置
<local:UserControl1 HmiField="{Binding Prop1, Mode=TwoWay}"/>
或默認情況下隱式:
public static readonly DependencyProperty HmiFieldProperty =
DependencyProperty.Register(
nameof(HmiField), typeof(double), typeof(UserControl1),
new FrameworkPropertyMetadata(
0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
TextBox 的Text屬性注冊如上所示,即帶有BindsTwoWayByDefault標志。
在TextBoxUserControl 的 XAML 中的Binding 中,您可能還想在用戶鍵入時更新源屬性(而不是僅在失去焦點時):
<TextBox Text="{Binding HmiField,
ElementName=usercontrol,
UpdateSourceTrigger=PropertyChanged}"/>
或者沒有其他無用的生成usercontrol字段:
<TextBox Text="{Binding HmiField,
RelativeSource={RelativeSource AncestorType=UserControl}
UpdateSourceTrigger=PropertyChanged}"/>
- 1 回答
- 0 關注
- 211 瀏覽
添加回答
舉報
