再做类似于QQ聊天窗口的时候,ApplicationBarIconButton点击后清空textbox的text值,而textbox的lostFocus事件设置为隐藏ApplicationBar,然后就出了这个问题, "Invalid cross-thread access."如果去掉textbox的lostFocus事件就不会出现异常,请问这是怎么回事
------解决方案--------------------
你调什么异步的调用了吗
------解决方案--------------------
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
//to do
}
);
试试
------解决方案--------------------
public MainPage()
{
InitializeComponent();
// Windows.Networking.Connectivity.DataUsage;
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
ab = (ApplicationBar)this.ApplicationBar;
}
private ApplicationBar ab;
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
ab.IsVisible = false;
}
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
if (ab.IsVisible)
{
return;
}
ab.IsVisible = true;
}
private void appbarClear_Click(object sender, EventArgs e)
{
txt.Text = string.Empty;
}
是这样么,我试了下,没你那问题啊