Skip to content
This repository has been archived by the owner on Apr 10, 2020. It is now read-only.

BindingExpression path error when binding PickerBox ItemsSource to a collection with 20 or more items and using FullModeDisplayMemberPath #25

Closed
P2SH opened this issue Nov 11, 2014 · 1 comment

Comments

@P2SH
Copy link

P2SH commented Nov 11, 2014

Enter full mode and scroll, these outputs are shown:

System.Windows.Data Error: BindingExpression path error: 'Key' property not found on 'System.Collections.Generic.List`1[System.Object]' 'System.Collections.Generic.List`1[System.Object]' (HashCode=66629291). BindingExpression: Path='Key' DataItem='System.Collections.Generic.List`1[System.Object]' (HashCode=66629291); target element is 'Microsoft.Phone.Controls.Primitives.PickerBoxListItem' (Name=''); target property is 'Content' (type 'System.Object')..
System.Windows.Data Error: BindingExpression path error: 'Property1' property not found on 'System.Collections.Generic.List`1[System.Object]' 'System.Collections.Generic.List`1[System.Object]' (HashCode=43330072). BindingExpression: Path='Property1' DataItem='System.Collections.Generic.List`1[System.Object]' (HashCode=43330072); target element is 'Microsoft.Phone.Controls.Primitives.PickerBoxListItem' (Name=''); target property is 'Content' (type 'System.Object')..

Items are displayed correctly though. No error is shown when the collection has less than 20 items.

XAML

<phone:PhoneApplicationPage
    x:Class="PhoneApp1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    DataContext="{Binding RelativeSource={RelativeSource Self}}">

    <StackPanel>
        <toolkit:PickerBox ItemsSource="{Binding DictSrc}" FullModeDisplayMemberPath="Key"/>
        <toolkit:PickerBox ItemsSource="{Binding ListSrc}" FullModeDisplayMemberPath="Property1"/>
    </StackPanel>
</phone:PhoneApplicationPage>

C#

using System.Collections.Generic;
using Microsoft.Phone.Controls;

namespace PhoneApp1
{
    public partial class MainPage : PhoneApplicationPage
    {
        Dictionary<string, string> dictSrc = new Dictionary<string, string>
        {
            {"0", ""}, {"1", ""}, {"2", ""}, {"3", ""}, {"4", ""},
            {"5", ""}, {"6", ""}, {"7", ""}, {"8", ""}, {"9", ""},
            {"10", ""}, {"11", ""}, {"12", ""}, {"13", ""}, {"14", ""},
            {"15", ""}, {"16", ""}, {"17", ""}, {"18", ""}, {"19", ""}
        };

        public Dictionary<string, string> DictSrc { get { return dictSrc; } }

        List<ListItem> listSrc = new List<ListItem>
        {
            new ListItem("0", ""), new ListItem("1", ""), new ListItem("2", ""), new ListItem("3", ""), new ListItem("4", ""),
            new ListItem("5", ""), new ListItem("6", ""), new ListItem("7", ""), new ListItem("8", ""), new ListItem("9", ""),
            new ListItem("10", ""), new ListItem("11", ""), new ListItem("12", ""), new ListItem("13", ""), new ListItem("14", ""),
            new ListItem("15", ""), new ListItem("16", ""), new ListItem("17", ""), new ListItem("18", ""), new ListItem("19", ""),
        };

        public List<ListItem> ListSrc { get { return listSrc; } }

        public MainPage()
        {
            InitializeComponent();
        }
    }

    public class ListItem
    {
        public string Property1 { get; set; }
        public string Property2 { get; set; }

        public ListItem(string prop1, string prop2)
        {
            Property1 = prop1;
            Property2 = prop2;
        }
    }
}
@Kinnara
Copy link
Owner

Kinnara commented Nov 11, 2014

Should be fixed now. Thank you for reporting!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants