Sime0647
Topic Author
Posts: 3
Joined: 07 Jul 2022, 04:26

C++ ItemControl

10 Aug 2022, 03:58

Hi, how can I add items to a ItemControl or any control derived from it in C++? I followed this C# WFP documentation: https://docs.microsoft.com/en-us/dotnet ... esktop-6.0
 Ptr<ItemsControl> pItemsControl = *new ItemsControl();
 Ptr<Binding> pBinding = *new Binding();
 Ptr<BaseComponent> pBoxed = Boxing::Box("FirstItem");
 pBinding->SetSource(pBoxed);
 pItemsControl->SetBinding(pItemsControl->ItemsSourceProperty, pBinding);
and also tried to only use the SetItemsSource() function
 Ptr<ItemsControl> pItemsControl = *new ItemsControl();
 Ptr<Binding> pBinding = *new Binding();
 Ptr<BaseComponent> pBoxed = Boxing::Box("FirstItem");
 pItemsControl->SetItemsSource(pBoxed);
But none of them worked...
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: C++ ItemControl

10 Aug 2022, 18:59

An ItemsControl can be populated with items in 2 ways:
  • By adding items to its Items collection
    itemsControl->GetItems()->Add(Boxing::Box("First"));
    itemsControl->GetItems()->Add(Boxing::Box("Second"));
    itemsControl->GetItems()->Add(Boxing::Box("Third"));
  • By setting a collection as its ItemsSource
    Ptr<ObservableCollection<BaseComponent>> items = MakePtr<ObservableCollection<BaseComponent>>();
    items->Add(Boxing::Box("First"));
    items->Add(Boxing::Box("Second"));
    items->Add(Boxing::Box("Third"));
    itemsControl->SetItemsSource(items);
Hope this helps.

Who is online

Users browsing this forum: Google [Bot] and 69 guests