报错为什么?Hold事件没有触发SELECTEDITEM!!


提示错误:Application_UnhandledException

Favorite 是一LonglistSelector

执行这两行后就开始报错了,为什么?

{
ItemViewModel cat = (ItemViewModel)Favorite.SelectedItem;
String dog= cat.LineTwo;
}

发现貌似是Hold事件没有触发SELECTEDITEM的原因!!当前Hold数据没有被选择~怎么会有这种问题的啊!

经chobit提示后修改为
c# private void wolf(object sender, System.Windows.Input.GestureEventArgs e) { FrameworkElement element = (FrameworkElement)e.OriginalSource; if (element is TextBlock) { String cat= (String)element.DataContext; var dog = cat.ToString(); }else{ ItemViewModel cat = element.DataContext as ItemViewModel; ..... } }
但新的问题是。。。。怎么页面不刷新了?

c# wp8

魔法师找妹子 10 years, 3 months ago

 ItemViewModel cat = Favorite.SelectedItem as ItemViewModel;
if(cat != null)
{
    String dog = cat.LineTwo;
}

3306178 answered 10 years, 3 months ago

Your Answer