我正在使用Silverlight & MVVM模式。當輸入鍵被按下時數據沒有被綁定
<TextBox Name="UserNameText" Text="{Binding Path=Username, Mode=TwoWay}" HorizontalContentAlignment="Stretch"/>
在這個我已經綁定文本框屬性名,當按下Enter鍵時,我在執行視圖模型的LoginCommand。
private void LayoutRoot_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
this._viewModel.LoginCommand.Execute(null);
}
}
當在文本框輸入用戶名和輸入鍵,從用戶名文本框中按下時,LoginCommand叫,但價值並不在屬性格式用戶名更新。它仍然包含null。
如果只有焦點丟失,則值被綁定。如何解決這個問題?
對不起。它沒有在Silverlight中工作。無論你在WPF中提出什麼建議,但不在SL中。 – jaks
@Jai下面是在Silverlight中創建「AttachedProperty」來實現此行爲的人的示例:http://marlongrech.wordpress.com/2010/12/27/updatesourcetrigger-propertychanged-for-silverlight-4-binding/ – Rachel