1
我有這個文本框在Input.xaml:TextBox中的TextProperty在輸入文本後未被更新;
<TextBox Name="input"
IsEnabled = "{Binding ElementName = control, Path = InputEnabled}"
Text = "{Binding Input, ElementName = control, UpdateSourceTrigger = PropertyChanged}"
/>
在Input.xaml.cs
:
public static readonly DependencyProperty InputProperty = DependencyProperty.Register(
"Input",
typeof(string),
typeof(InputPanel),
new FrameworkPropertyMetadata("")
);
public static readonly DependencyProperty InputEnabledProperty = DependencyProperty.Register(
"InputEnabled",
typeof(bool),
typeof(InputPanel),
new FrameworkPropertyMetadata(true)
);
public string Input
{
get { return (string)GetValue(InputProperty); }
set { SetValue(InputProperty, value); }
}
public bool InputEnabled
{
get { return (bool)GetValue(InputEnabledProperty); }
set { SetValue(InputEnabledProperty, value); }
}
//...
我更新從Windows.xaml屬性輸入如下:
<local:Input Input = "{Binding Path = Selected.ETA, Mode = OneWay}"/>
完美地工作,但是當我更改文本屬性窗體的GUI,綁定將不再工作。從GUI輸入文本後,仍然有辦法使用綁定。
你是什麼意思_change文本屬性形式的GUI_? – dkozl
將'mode = OneWay'改爲'mode = TwoWay' –
我的意思是當你從文本框中的視覺插入文本,而不是通過數據綁定。 –