DataTemplate inside DataTemplate

vanKraster 181 Reputation points

I have a custom control that has a CollectionView with some builtin features like, multiselection with animations, drag & drop and SwipeItems so I created a contentView with a collectionview that has a

with inside a

 <TemplatedView HorizontalOptions="FillAndExpand" 
                                                           ControlTemplate="{Binding Source={x:Reference this}, Path=CustomDataTemplate}" 

When I call my custom list I use

<ControlTemplate x:Key="ctrlRoot">
<StackLayout Orientation="Vertical">
<Label Grid.Column="0" Text="{TemplateBinding Parent.BindingContext.UniqueId}"></Label>
<Label Grid.Column="0" Text="{TemplateBinding Parent.BindingContext.Text}"></Label>

It works but as you can see I must bind data with TemplateBinding and I want to use the {Binding command... it is possible to achieve this somehow ?
I neet to pass a DataTemplate not a ControlTemplate but I don't know how to refactor this...

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,253 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. vanKraster 181 Reputation points

    I have found a way by myself:

    1. add BindingContext={Binding .} to TemplatedView '
    2. Add BindingContext={TemplateBinding BindingContext} to container (let's say grid or stacklayout) of ControlTemplate
    3. Add x:DataType to the same container as 2
    4. You can now Use {Binding <PropertyName>} with intellisense

    This could be a way....

    0 comments No comments