大佬教程收集整理的这篇文章主要介绍了在Silverlight中绑定ComboBox.SelectedItem(更多),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<ComboBox x:Name="PART_CommentaryList" HorizontalAlignment="Left" Margin="3" Itemssource="{Binding Path=CurrentVideo.Commentaries}" SELEctedItem="{Binding Path=CurrentCommentary,Mode=TwoWay}">
CurrentVideo和CurrentCommentary属性都会定期更改.几次后,我收到此错误:
Category: ManagedRuntimeError message: System.Argumentexception: Value does not fall within the expected range. at Ms.Internal.XcpImports.MethodEx(IntPtr ptr,String name,CValue[] cvData) at Ms.Internal.XcpImports.MethodPack(IntPtr objectPtr,String methodName,Object[] rawData) at Ms.Internal.XcpImportS.UIElement_TransformToVisual(UIElement element,UIElement visual) at System.WindowS.UIElement.TransformToVisual(UIElement visual) at System.Windows.Controls.Primitives.SELEctor.IsOnCurrentPage( Int32 index,Rect& itemsHostRect,Rect& listBoxItemRect) at System.Windows.Controls.Primitives.SELEctor.ScrollIntoView( Int32 indeX) at System.Windows.Controls.Primitives.SELEctor.SetFocusedItem( Int32 index,Boolean scrollIntoView) at System.Windows.Controls.ComboBox.PrepareContainerForItemOverride( DependencyObject element,Object item) at System.Windows.Controls.ItemsControl.updateContainerForItem( Int32 indeX) at System.Windows.Controls.ItemsControl.RecreateVisualChildren() at System.Windows.Controls.ItemsControl.RecreateVisualChildren( IntPtr unmanagedObj)
这对我来说似乎是一个ComboBox错误.我可以在CurrentCommentary之前验证CurrentVideo是否更改,因此所选项应该始终是列表中的项.
相关,我真的不想要Mode = TwoWay,因为当Itemssource被更改时,SELEctedItem暂时为null,它在我的模型中被设置回来,我实际上并不想要.但绑定根本不起作用(这似乎是另一个错误).
1)始终将Itemssource绑定到可观察的集合,并且永远不会重置OC的指针.
<ComboBox Itemssource="{Binding MyList}" SELEctedItem="{Binding MyItem}" />
坏:
@H_217_23@myList = new ObservableCollection();
好:
@H_217_23@myList.Clear(); MyList.AddRange(...);
2)在清除MyList之前设置MyItem = null
在您的情况下,只要更改CurrentView,就会更改List的引用.因此,如果SELEctedItem不为null,则重置Itemssource的时间很短,ComboBox的内部正在尝试在新的Itemssource中找到SELEctedItem对象,但旧对象不在那里.
以上是大佬教程为你收集整理的在Silverlight中绑定ComboBox.SelectedItem(更多)全部内容,希望文章能够帮你解决在Silverlight中绑定ComboBox.SelectedItem(更多)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。