locked
How to binding items colletion into Listbox with C++?

    Question

  • Hi MSFT,

    I encounter a problem to binding a items collection to listbox with C++.

    I could binding a single object to listbox itemtemplate, just like following:

                Vector<String^>^ collection = ref new Vector<String^>;

                collection->Append("test name");

               listBox->ItemsSource = collection.

    But i could not binding items collection into listbox, just like following:

              Item^ item = ref new Item;//item is created by myself.

             item->title = "test title";

             item->name = "name";           

              Vector<Item^>^ collection = ref new Vector<Item^>;

             listBoxt->ItemsSource = collection;

    Maybe there is a special definition for Item managed class.

    Please give me some help for this.

    Thanks,

    Kevin.

    Wednesday, March 21, 2012 10:23 AM

Answers

  • Hello Mr. Wang.

    You should be define a Binding Path in the ListView.ItemTemplate like belows sample XAML code.

    <ListView.ItemTemplate>

        <StackPanel>

            <TextBlock Text="{Binding Path=title}" />

            <TextBlock Text="{Binding Path=name}" />

        </StackPanel>

    </ListView.ItemTemplate>

    Good luck.

    • Proposed as answer by Jesse Jiang Tuesday, April 03, 2012 9:25 AM
    • Marked as answer by Jesse Jiang Monday, April 09, 2012 1:38 AM
    Thursday, March 22, 2012 12:08 AM