Using a TemplatedView within the SfListView.ItemTemplate DataTemplate

I'm prototyping a TreeView using a contained SfListView. 

I have a data model that maps a Tree hierarchy to an ObservableCollection and inserts/removes items as node's are expanded and collapsed.  SfListView.ItemsSource is set to the ObservableCollection.

NOTE: The attached zip file contains code and xaml excerpts referenced below.

SfListView.ItemTemplate is set to a DataTemplate. (ItemTemplate.original.xaml)

At this point, everything works expected, items are populated and removed when nodes are expanded/collapsed and SelectedItem is being tracked accordingly. 

Next I want to support a ContentPresenter for the node's value instead of displaying a simple text label.

Here's the steps I took:

  • Created a TreeViewItemCell TemplatedView and moved the DataTemplate from the ItemTemplate.original.xaml into the ControlTemplate for the templated view. (TreeViewItemCell.xaml and TreeViewItem.cs)
  • Defined an ItemsTemplate property on my TreeView to accept the item template.
  • Created a derived ItemsGenerator to return a ListViewItemsExt instance for ItemType.Record (TreeViewItemsGenerator.cs).
  • In  ListViewItemsExt, override ListViewItem.OnContentChanged, create the View from the TreeView.ItemTemplate, set it's BindingContext to the associated TreeItem and set the TreeViewItemCell's Content property.

I've debugged down to the OnContentChanged and confirmed I receive a TreeViewItemCell and created its Content but no items are displayed in the SfListView.   When I view the SfListView in the LiveVisualTree, I see the VisualContainer populated with a list of my ListViewItemsExt displayed as [TreeViewItemsGenerator+ListViewItemExt]

Is this the right approach?  If so, what am I missing.  If not, what's the proper way to accomplish this?


Attachment: Excerpts_670e6e7.zip

3 Replies

RM RiyasHameed MohamedAbdulKhader Syncfusion Team July 31, 2023 01:35 PM UTC

Hi Daniel Travison,
Thank you for reporting your query, and we were able to understand your scenario. We attempted to implement the code for your requirement using the code changes you provided; however, we encountered difficulty in understanding the purpose of the TreeView and TreeItem classes.

To assist you better, could you please provide us with the code changes you made for TreeView and TreeItem classed? Additionally, it would be helpful if you could share the initialization code for SfListView and where you set the ItemTemplate for the ListView.

Here, we have attached a sample of what we tried so far in an attempt to meet your requirements. Please share the requested details or if possible, please modify the attached sample with missed code customizations. It would be very helpful for us to analyze the query further.
Regards,
Riyas Hameed M



Attachment: TreeViewListView_67cc8c06.zip


DT Daniel Travison August 1, 2023 12:45 AM UTC

I think it will be easier to put together a stand-alone sample that incorporates the tree components and illustrates the DataItem/ContentPresenter issues.  I should have it ready sometime tomorrow and will reply with a repo.


I won't be able to publically share parts of the code so let me know how I can share it (e.g., a private repro, zip, etc.)


Thanks,.



RM RiyasHameed MohamedAbdulKhader Syncfusion Team August 1, 2023 07:06 AM UTC

Daniel Travison,

We have created a new ticket for further follow-up. Please follow the ticket created in your account for further assistance. As always, we will gladly assist you.


Loader.
Up arrow icon