2016-05-23 87 views
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輸入文本後,仍然有辦法使用綁定。

+0

你是什麼意思_change文本屬性形式的GUI_? – dkozl

+0

將'mode = OneWay'改爲'mode = TwoWay' –

+0

我的意思是當你從文本框中的視覺插入文本,而不是通過數據綁定。 –

回答

1

如下您應該改變你binding模式:

<local:Input Input = "{Binding Path = Selected.ETA, Mode = TwoWay}"/> 

,你將被允許從UI更新基本性質和基本屬性更新UI的方式。記住你還必須實現INotifyPropertyChange接口。更多關於INotifyPropertyChange的信息可以在here找到。

+0

問題是OneWay,謝謝! –

相關問題