我有一个具有以下结构的ListPicker:
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>
每当我尝试运行时都会出现以下消息:
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)
它说该元素已经是另一个元素的孩子了。
但是如果我删除最后一项并且只在选择器中保留五个项目,那么它可以正常工作。我错了什么?
答案 0 :(得分:9)
将ListPicker的 ItemCountThreshold 属性设置为大于6的值(默认情况下,它列出五个或更少的项)。你需要类似的东西:
<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类型的依赖项属性。它指定将在Expanded模式下显示的最大项目数。默认情况下,具有五个或更少项目的列表就地扩展,而具有更多项目的列表切换到全屏选择界面。它也可以设置为0以切换完全模式或非常大的数字来切换扩展模式。
答案 1 :(得分:4)
我无法使用ListPickerItem使ListPicker工作并设置ItemCountThreshold =“0”。其文档指示何时将值设置为零,完整模式应自动发生。不要相信它。这是行不通的。
使用列表绑定后面的代码切换后,它终于有效了。为什么可以使用声明性XAML简单地解决它的困难方式(代码隐藏)?希望ListPickerItem很快得到修复。
答案 2 :(得分:3)
ItemCountThreshold现在是最新版本工具包中的只读属性。没有简单的方法可以切换到超过5个项目的内联扩展。