Consider this xaml.
<CollectionView
x:Name="layerColView"
x:FieldModifier="public"
SelectionMode="Single"
ItemsSource="{Binding Items}">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout
Padding="5"
x:DataType="viewModels:LayerViewModel"
>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding BindingContext.ItemTapped, Source={x:Reference layerColView}}"
CommandParameter="{Binding}"></TapGestureRecognizer>
<DropGestureRecognizer
AllowDrop="True"
DragLeaveCommand="{Binding BindingContext.ItemDragLeave, Source={x:Reference layerColView}}"
DragLeaveCommandParameter="{Binding}"
DragOverCommand="{Binding BindingContext.ItemDraggedOver, Source={x:Reference layerColView}}"
DragOverCommandParameter="{Binding}"
Drop="DropGestureRecognizer_Drop_Collection"
DropCommand="{Binding BindingContext.ItemDropped, Source={x:Reference layerColView}}"
DropCommandParameter="{Binding}" />
</StackLayout.GestureRecognizers>
<StackLayout Orientation="Horizontal"
HorizontalOptions="FillAndExpand"
Spacing="5">
<StackLayout.GestureRecognizers>
<DragGestureRecognizer
CanDrag="True"
DragStarting="DragGestureRecognizer_DragStarting_Collection"
DragStartingCommand="{Binding BindingContext.ItemDragged, Source={x:Reference layerColView}}"
DragStartingCommandParameter="{Binding}" />
</StackLayout.GestureRecognizers>
<Image Source="{Binding IconSource}"
WidthRequest="30"
HorizontalOptions="StartAndExpand"></Image>
<Label
FontSize="14"
HeightRequest="40"
TextColor="Black"
HorizontalTextAlignment="Center"
Text="{Binding LayerName}"
VerticalTextAlignment="Center"
HorizontalOptions="StartAndExpand">
</Label>
</StackLayout>
<Grid
BackgroundColor="LightYellow"
HeightRequest="50"
IsVisible="{Binding IsBeingDraggedOver}" />
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Now as you can see when i write DragStartingCommandParameter="{Binding}" DragStartingCommandParameter recognized as the binded class for this item template. My question is how can i do this in c# code?
return new DataTemplate(() =>
{
...
DropGestureRecognizer dropGR = new DropGestureRecognizer();
dropGR.AllowDrop = true;
dropGR.SetBinding(DropGestureRecognizer.DragLeaveCommandParameterProperty, new Binding("", source: this));
...
});
}
This doesnt work. Gives the error 'Error: 'path' cannot be an empty string'