2014-03-01 55 views
0

我得到这个例外,每当我试图交通前往M列表选择控件在我的应用程序中。System.Exception的{System.ArgumentException}值不在预期范围

+  this {App_name.App} App_name.App 
+  sender {App_name.App} object {App_name.App} 
-  e {System.Windows.ApplicationUnhandledExceptionEventArgs} System.Windows.ApplicationUnhandledExceptionEventArgs 
+  base {System.Windows.ApplicationUnhandledExceptionEventArgs} System.EventArgs {System.Windows.ApplicationUnhandledExceptionEventArgs} 
+  ExceptionObject {System.ArgumentException: Value does not fall within the expected range.} System.Exception {System.ArgumentException} 
     Handled false bool 
+  Non-Public members  

代码为我的列表选择器是

<ListBox Margin="0,417,0,0"> 
      <ListBoxItem> 
       <toolkit:ListPicker Name="LearnerFileChooser" Width="431" > 
        <toolkit:ListPickerItem Content="A" /> 
        <toolkit:ListPickerItem Content="B" /> 
        <toolkit:ListPickerItem Content="C" /> 
        <toolkit:ListPickerItem Content="E" /> 
        <toolkit:ListPickerItem Content="F" /> 
        <toolkit:ListPickerItem Content="G" /> 
        <toolkit:ListPickerItem Content="H" /> 
       </toolkit:ListPicker> 
      </ListBoxItem> 

如果我减少了没有。的项目为4,那么它可以正常工作,但会在多于4个项目上崩溃。

我试图创建字母从中用户可以选择列表。

+1

可能重复的[Windows Phone的工具包ListPicker抛出未处理的异常(http://stackoverflow.com/questions/17065970/windows-phone-toolkit-listpicker-throws-an-unhandled-exception) –

回答

3

这是一个众所周知的问题。

您必须绑定的物品,以便能够使用超过5

Explanation on Codeplex

ListPicker作为一个ItemsControl,获得其项目属性设置为你的榜样ListPickerItems列表 。 ListPickerItems是UIElements, 和ListPicker将其呈现在其演示者中。当有5个或者更少的项目时,扩展模式在当前页面上打开,并且您可以在演示者中看到所有项目。 。

但是,当6个或更多的项目存在,打开列表选择器去 这将打开一个新页面完整模式。这个新页面有一个列表框,其中 将其项目属性设置为listpicker的项目。这是其中 它破裂。通过设置列表框的到listpicker的项目 项目(在这种情况下listpickeritems的列表),列表框中就会把这些 UI元素进入其视图。现在,单个listboxitem包含在可视树上的两个 位置中。

由于此问题,ListPicker只支持数据绑定和模板 。不要将ListPicker的项目设置为特定的UIElements。的

+0

感谢。现在明白了。 :) – Arpit

相关问题