首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ListPicker崩溃

ListPicker崩溃
EN

Stack Overflow用户
提问于 2011-05-05 21:18:21
回答 3查看 3.5K关注 0票数 4

我有一个结构如下的ListPicker:

代码语言:javascript
复制
toolkit:ListPicker x:Name="mListPicker" HorizontalAlignment="Right" Margin="0,75,43,0" Width="100" VerticalAlignment="Top">
< toolkit:ListPickerItem Content="5"/>
< toolkit:ListPickerItem Content="10"/>
< toolkit:ListPickerItem Content="15"/>
< toolkit:ListPickerItem Content="20"/>
< toolkit:ListPickerItem Content="25"/>
< toolkit:ListPickerItem Content="30"/>
< /toolkit:ListPicker>

每当我尝试运行此命令时,都会出现以下消息:

代码语言:javascript
复制
System.Windows.Markup.XamlParseException occurred
  Message= [Line: 0 Position: 0]
   --- Inner Exception ---
The parameter is incorrect. 

  LineNumber=0
  LinePosition=0
  StackTrace:
       at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
       at MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)
       at MS.Internal.XcpImports.FrameworkElement_ApplyTemplate(FrameworkElement frameworkElement)
       at System.Windows.FrameworkElement.ApplyTemplateInternal()
       at System.Windows.Controls.ScrollContentPresenter.HookupScrollingComponents()
       at System.Windows.Controls.ScrollContentPresenter.OnApplyTemplate()
       at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)
       at MS.Internal.XcpImports.MeasureNative(IntPtr element, Single inWidth, Single inHeight)
       at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
       at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
       at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
       at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
       at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
  InnerException: System.ArgumentException
       Message=The parameter is incorrect. 
       StackTrace:
            at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
            at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, DependencyObject doh)
            at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper doh, DependencyProperty property, Object obj)
            at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
            at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason)
            at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
            at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
            at System.Windows.Controls.ContentControl.set_Content(Object value)
            at System.Windows.Controls.ItemsControl.PrepareContainerForItemOverride(DependencyObject element, Object item)
            at System.Windows.Controls.Primitives.Selector.PrepareContainerForItemOverride(DependencyObject element, Object item)
            at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item)
            at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
            at System.Windows.Controls.ItemsControl.AddVisualChild(Int32 index, DependencyObject container, Boolean needPrepareContainer)
            at System.Windows.Controls.ItemsControl.AddContainers()
            at System.Windows.Controls.ItemsControl.RecreateVisualChildren(IntPtr unmanagedObj)
            at MS.Internal.XcpImports.MethodExNative(IntPtr context, IntPtr element, UInt32 cString, String name, UInt32 cParams, IntPtr pParams, CValue& outval, Int32& typeIndex)
            at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
            at MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)
            at MS.Internal.XcpImports.FrameworkElement_ApplyTemplate(FrameworkElement frameworkElement)
            at System.Windows.FrameworkElement.ApplyTemplateInternal()
            at System.Windows.Controls.ScrollContentPresenter.HookupScrollingComponents()
            at System.Windows.Controls.ScrollContentPresenter.OnApplyTemplate()
            at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)
            at MS.Internal.XcpImports.MeasureNative(IntPtr element, Single inWidth, Single inHeight)
            at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
            at System.Windows.UIElement.Measure(Size availableSize)
            at System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
            at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
            at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
            at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
            at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
            at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)

它说明该元素已经是另一个元素的子元素。

但如果我删除最后一项,并在选择器中只保留五项,它就可以正常工作。我到底搞错了什么?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-05-05 23:27:20

将ListPicker的ItemCountThreshold属性设置为大于6的值(默认情况下,它列出five或更少的items)。您需要类似于以下内容的内容:

代码语言:javascript
复制
 <toolkit:ListPicker ItemCountThreshold="10">
                <toolkit:ListPickerItem Content="1" />
                <toolkit:ListPickerItem Content="2"/>
                <toolkit:ListPickerItem Content="3"/>
                <toolkit:ListPickerItem Content="4"/>
                <toolkit:ListPickerItem Content="5"/>
                <toolkit:ListPickerItem Content="6"/>
            </toolkit:ListPicker>

ItemCountThreshold:ItemCountThreshold是int类型的依赖属性。它指定将在展开模式下显示的最大项目数。默认情况下,包含五个或更少项目的列表就地展开,而包含更多项目的列表切换到全屏选择界面。也可以将其设置为0以切换全模式,或设置为非常大的数字以切换扩展模式。

票数 9
EN

Stack Overflow用户

发布于 2011-05-19 12:52:11

我永远不能使用ListPickerItem让ListPicker工作,也不能将ItemCountThreshold=设置为0。其文档表明,当值设置为零时,full模式应自动发生。不要相信它。它不起作用。

在切换到使用列表绑定的代码后,它终于可以工作了。当它可以使用声明性XAML简单地解决时,为什么要采取困难的方式(代码隐藏)呢?希望ListPickerItem能尽快修好。

票数 4
EN

Stack Overflow用户

发布于 2012-02-25 16:42:18

在最新版本的工具包中,ItemCountThreshold现在是一个只读属性。没有简单的方法来切换到超过5个项目的内联扩展。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5898333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档