4

次の構造の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)

その要素はすでに別の要素の子であると書かれています。

しかし、最後のアイテムを削除して、ピッカーに5つのアイテムだけを保持すると、正常に機能します。何が間違っているのですか?

4

3 に答える 3

9

ListPickerのItemCountThresholdプロパティを 6 より大きい値に設定します (既定では、5 つ以下の項目がリストされます)。たとえば、次のようなものが必要です。

 <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 型の依存関係プロパティです。拡張モードで表示されるアイテムの最大数を指定します。デフォルトでは、項目が 5 つ以下のリストはその場で展開されますが、それ以上の項目があるリストは全画面選択インターフェイスに切り替わります。0 に設定してフル モードに切り替えることも、非常に大きな数に設定して拡張モードに切り替えることもできます。

于 2011-05-05T15:27:19.983 に答える
4

ListPickerItem を使用して ListPicker を動作させ、ItemCountThreshold="0" を設定することはできませんでした。そのドキュメントは、値がゼロに設定されると、フルモードが自動的に発生することを示しています。それを信じるな。それは動作しません。

リストバインディングでコードビハインドを使用して切り替えた後、最終的に機能しました。宣言型 XAML を使用して簡単に解決できるのに、なぜ難しい方法 (コード ビハインド) を行うのでしょうか? ListPickerItem がすぐに修正されることを願っています。

于 2011-05-19T04:52:10.587 に答える
3

ツールキットの最新バージョンでは、ItemCountThreshold が読み取り専用プロパティになりました。5 つ以上のアイテムをインライン展開に切り替える簡単な方法はありません。

于 2012-02-25T08:42:17.827 に答える