I have a Xamarin Forms ListView with a DataTemplateSelector, so that I can display different cell types (see the image link below). The reason for using a DataTemplateSelector basically was because of multiple subcomments as well as an Entry field for additional subcomments, that should be displayed under a main comment.
My problem: I would like to put a frame around a maincomment, its subcomments and the entry field as to indicate that these elements belong together. What would be the best way to do this? (see the right side of the linked image below).
Thanks for the help in advance!
Edit: Some code. This is my listview:
<ListView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
x:Name="commentListView" HasUnevenRows="True" SeparatorVisibility="None"
ItemsSource="{Binding AllComments}"
ItemTemplate="{StaticResource MessageTemplateSelector}" >
</ListView>
This is my DataTemplateSelector:
public class CommentDataTemplateSelector : Xamarin.Forms.DataTemplateSelector
{
public CommentDataTemplateSelector()
{
this.parentDataTemplate = new DataTemplate(typeof(ParentCommentViewCell));
this.childDataTemplate = new DataTemplate(typeof(ChildCommentViewCell));
this.entryDataTemplate = new DataTemplate(typeof(EntryCommentViewCell));
this.dateDataTemplate = new DataTemplate(typeof(DateCommentViewCell));
this.separatorDataTemplate = new DataTemplate(typeof(SeparatorCommentViewCell));
}
private readonly DataTemplate dateDataTemplate;
private readonly DataTemplate parentDataTemplate;
private readonly DataTemplate childDataTemplate;
private readonly DataTemplate entryDataTemplate;
private readonly DataTemplate separatorDataTemplate;
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
var messageVM = item as CommentBaseViewModel;
if (messageVM == null)
{
return null;
}
switch (messageVM.CommentType)
{
case CommentBaseTypeEnum.Child:
return this.childDataTemplate;
case CommentBaseTypeEnum.Parent:
return this.parentDataTemplate;
case CommentBaseTypeEnum.Entry:
return this.entryDataTemplate;
case CommentBaseTypeEnum.Date:
return this.dateDataTemplate;
case CommentBaseTypeEnum.Separator:
return this.separatorDataTemplate;
default:
Debug.WriteLine("### Is there a Comment ViewCell missing?");
return null;
}
}
}
As one can see, there are 5 different viewcells. Now when filling the ItemSource of the ListView above, I stack different types on each other like 1. Date 2. Parent 3. Multiple Childs 4. An Entry 5. A Separator
and then I start over.
What I want, is to have a single frame that spans the elements 1 to 4 and I don't know if and how I can do this as I have a multitude of different ViewCells.