Custom page and Collection definiton from xaml

Max25Max25 FRMember ✭✭

Hi,

I am trying to add some element to an ObservableCollection property from xaml.
In a page class "CustomPage" inheriting from ContentPage, I defined a property:

public ObservableCollection<CustomItem> Items { get; set; }

And in xaml I want to add item to this collection:

<nsp:CustomPage.Items>
    <nsp:CustomItem Description="!Desc" />
</nsp:CustomPage.Items>

I'm getting this error: "The given key was not present in the dictionary".

What is the correct syntax to achieve that? I've also tried surrounding it with x:array, or replacing ObservableCollection with List<>...
It seems possible when I look at ContentPage.ToolbarItems which is an ObservableCollection

Thanks.

Posts

  • Max25Max25 FRMember ✭✭

    OK I just figured it out. My class CustomItem was missing...... the default (empty) ctor.

Sign In or Register to comment.