
我已经通过一个未升级的新WP8应用程序再现了这个问题,它也被隔离到数据绑定控件.如果我静态添加PanoramaItems,SelectionChanged事件将被触发.
我错过了什么,还是这只是一个直截了当的WP8中的BUG?任何推荐的解决方法?
我有一个GitHub repo与一个静态样本和一个数据绑定的样本,以显示什么工作和什么不起作用. https://github.com/bthubbard/DatabindingIssues
解决方法 WP8中的Panorama控件有一个已知的数据绑定错误. BUG的症状是SelectionChanged不启动,Selectedindex& SelectedItem不可靠,并且将Panorama导航到具有“全景”选项的全景照片.例如,以下代码示例将永远不会触发MessageBox和Selectedindex& SelectedItem不会指示正确的预期值.
<phone:Panorama x:name="panorama" ItemsSource="{Binding}" SelectionChanged="Panorama_SelectionChanged_1"> <phone:Panorama.headerTemplate> <DataTemplate> <ContentControl Content="{Binding name}" /> </DataTemplate> </phone:Panorama.headerTemplate> <phone:Panorama.ItemTemplate> <DataTemplate> <ContentControl Content="{Binding name}" /> </DataTemplate> </phone:Panorama.ItemTemplate></phone:Panorama> private voID MainPage_Loaded(object sender,RoutedEventArgs e){ this.DataContext = new ObservableCollection<Cow>() { new Cow("Foo"),new Cow("bar"),new Cow("Baz") };}private voID Panorama_SelectionChanged_1(object sender,SelectionChangedEventArgs e){ MessageBox.Show("Panorama_SelectionChanged_1: " + panorama.Selectedindex);}public class Cow{ public Cow(string name) { name = name; } public string name { get; set; }} 一个明显的修复将是在代码隐藏中手动初始化PanoramaItems.
另一个解决方案是将我们的集合从类型更改为无类型,并将以下代码片段添加到有限数据类中.所以我们来从ObservableCollection< Cow>到ObservableCollection< object>并在Cow类中添加一些代码:
private voID MainPage_Loaded(object sender,RoutedEventArgs e){ this.DataContext = new ObservableCollection<object>() { new Cow("Foo"),new Cow("Baz") };}public class Cow{ public Cow(string name) { name = name; } public string name { get; set; } public overrIDe bool Equals(object obj) { if ((obj != null) && (obj.GetType() == typeof(PanoramaItem))) { var thePanoItem = (PanoramaItem)obj; return base.Equals(thePanoItem.header); } else { return base.Equals(obj); } } public overrIDe int GetHashCode() { return base.GetHashCode(); }} 现在,当我们运行这个代码片段时,我们可以看到SelectionChanged触发,如预期的那样,使用正确的Selectedindex值:
总结以上是内存溢出为你收集整理的silverlight – Windows Phone 8 Panorama SelectionChanged&Databinding全部内容,希望文章能够帮你解决silverlight – Windows Phone 8 Panorama SelectionChanged&Databinding所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)