在使用 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

相关文章:

  • 2021-10-03
  • 2021-12-31
  • 2022-12-23
  • 2022-01-02
  • 2021-06-24
  • 2021-06-15
  • 2022-12-23
猜你喜欢
  • 2021-08-14
  • 2021-12-27
  • 2022-12-23
  • 2021-07-22
  • 2021-05-30
  • 2021-12-23
  • 2022-12-23
相关资源
相似解决方案