Windows Phone 系列- 使用 MVVM绑定时无法获取当前值

在使用 MVVM绑定时无法获取当前值

后来发现一个方法,就是在changed事件中更新绑定

 

如:textbox

 

private void tbsearchCard_TextChanged(object sender, TextChangedEventArgs e)
{
UpdateTextBoxSource(sender);
}

public void UpdateTextBoxSource(object sender)
{

if (sender is TextBox)
{
TextBox tb = sender as TextBox;




BindingExpression binding = tb.GetBindingExpression(TextBox.TextProperty);
if (binding != null)
binding.UpdateSource();
}

}

如:Pivot

      private void pvtSearch_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is Pivot)
{
Pivot pvt = sender as Pivot;


BindingExpression binding = pvt.GetBindingExpression(Pivot.SelectedIndexProperty);
if (binding != null)
binding.UpdateSource();
}
}

 

OK

你可能感兴趣的:(windows phone)