2011-05-05 53 views
4

我有以下結構的ListPicker: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) 

它說,該元素已經是另一個的孩子一。

但是,如果我刪除最後一個項目,並只保留五個項目在選取器中,它工作正常。我錯了什麼?

回答

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類型的依賴屬性。它指定了將在擴展模式下顯示的項目的最大數量。默認情況下,具有五個或更少項目的列表就地展開,而具有更多項目的列表則切換到全屏選擇界面。它也可以設置爲0來切換Full模式或者一個非常大的數字來切換Expanded模式。

+0

從2011年8月起版本不再適用版本 – AndreaCi 2012-07-10 19:10:36

+0

在2011年8月版本的工具包ItemCountThreshold是隻讀的。它指定了將在擴展模式下顯示的項目的最大數量。默認值是5。包含五個或更少項目的列表就地展開,而具有更多項目的列表則切換到全屏選擇界面。 (這是默認設置) – 2012-07-11 20:20:42

+0

從2011年8月起,這不再是對這個問題的解決方案沒有吸盤屬性起作用,因此拾取器崩潰。更何況編譯時錯誤,如果使用該屬性... – 2013-01-03 16:28:46

4

我不能永遠不讓ListPicker使用ListPickerItem並設置ItemCountThreshold =「0」。它的文檔指示值何時設置爲零,完整模式應該自動發生。不要相信它。這是行不通的。

切換後使用列表綁定後的代碼,它終於奏效。爲什麼使用聲明式XAML可以簡單解決這個難題(後面的代碼)?希望ListPickerItem儘快修復。

3

ItemCountThreshold現在是最新版本工具包中的只讀屬性。沒有簡單的方法切換到超過5項的內聯擴展。

+0

微軟失敗了...... – 2013-01-03 16:23:48