System.Exception {System.ArgumentException}值不在预期范围内 [英] System.Exception {System.ArgumentException} Value does not fall within the expected range

查看:822
本文介绍了System.Exception {System.ArgumentException}值不在预期范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试在应用程序中访问m列表选择器控件时,都会收到此异常.

I'm getting this exception whenever i try to access m list picker control in my app.

+       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      

我的列表选择器的代码是

Code for my list picker is

<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个项目上崩溃.

If i reduce the no. of items to 4 then it works properly but it crashes on more then 4 items.

我正在尝试创建一个可供用户选择的字母列表.

I'm trying to create a list of alphabets from which user can choose.

推荐答案

这是一个已知问题.

您必须绑定项目才能使用超过5个.

You must bind the items to be able to use more than 5.

对Codeplex的解释:

ListPicker作为ItemsControl,将其Items属性设置为列表 您的示例中的ListPickerItems. ListPickerItems是UIElement, 然后ListPicker在其演示者中呈现它们.当有5或 较少的项目,展开模式会在当前页面上打开,您可以 查看演示者中的所有项目.

ListPicker as an ItemsControl, gets its Items property set to a list of ListPickerItems in your example. ListPickerItems are UIElements, and the ListPicker renders them in its presenter. When there are 5 or less items, the expanded mode opens on the current page, and you can see all the items in the presenter.

但是,如果有6个或更多项目,则打开列表选择器 完整模式会打开一个新页面.这个新页面有一个列表框, 将其项属性设置为列表选择器的项.这是哪里 坏了通过将列表框的项目设置为列表选择器的项目 (在这种情况下为listpickeritems的列表),该列表框会将那些 UIElements进入其视图.现在,两个中包含一个listboxitem 放置在视觉树上.

But when 6 or more items are present, opening the list picker goes to full mode which opens a new page. This new page has a listbox, which gets its items property set to the listpicker's items. This is where it breaks. By setting the listbox's items to the listpicker's items (in this case a list of listpickeritems), the listbox will put those UIElements into its view. Now a single listboxitem is included in two places on the visual tree.

由于此问题,ListPicker仅支持数据绑定和 模板化.不要将ListPicker的项目设置为特定的UIElement.

Because of this issue, ListPicker only supports databinding and templating. DO NOT set the ListPicker's items to specific UIElements.

这篇关于System.Exception {System.ArgumentException}值不在预期范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆