question

vanKraster-4073 avatar image
0 Votes"
vanKraster-4073 asked vanKraster-4073 answered

DataTemplate inside DataTemplate

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
<CollectionView.ItemTemplate>
<DataTemplate>

with inside a

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

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>
</StackLayout>
</ControlTemplate>


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...
Thanks

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

vanKraster-4073 avatar image
0 Votes"
vanKraster-4073 answered

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....



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.