Gesture to Collection view item.
collectionView.ItemTemplate = new DataTemplate(() =>
{
var stackLayout = new StackLayout();
stackLayout.HorizontalOptions = LayoutOptions.CenterAndExpand;
stackLayout.VerticalOptions = LayoutOptions.CenterAndExpand;
stackLayout.Padding = new Thickness(5, 5, 5, 5);
var _AllocationLabel = new Label();
_AllocationLabel.SetBinding(Label.TextProperty, "OrderID");
_AllocationLabel.FontAttributes = FontAttributes.None;
_AllocationLabel.FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Button));
_AllocationLabel.TextColor = Color.Black;
_AllocationLabel.HorizontalOptions = LayoutOptions.Center;
_AllocationLabel.VerticalOptions = LayoutOptions.Center;
_AllocationLabel.BackgroundColor = Color.Red;
var frame = new Frame();
frame.Content = _AllocationLabel;
stackLayout.Children.Add(frame);
TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer() { NumberOfTapsRequired = 1 };
tapGestureRecognizer.Tapped += TapGestureRecognizer_Tapped;
stackLayout.GestureRecognizers.Add(tapGestureRecognizer);
return stackLayout;
}); |
private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
//// Selected value from
var selectedValue = ((sender as StackLayout).BindingContext as CollectionModel).OrderID;
var rowData = (sender as StackLayout).Parent.BindingContext as OrderInfo;
var rowIndex = this.dataGrid.GetRowGenerator().Items.FirstOrDefault(x => x.RowData == rowData).RowIndex;
var columnIndex = this.dataGrid.Columns.IndexOf(this.dataGrid.Columns.FirstOrDefault(x => x.MappingName == "OrderID"));
} |
public DataTemplate SetCellTemplate()
{
return new DataTemplate(() =>
{
StackLayout parentStackLayout = new StackLayout();
parentStackLayout.InputTransparent = true;
CollectionView collectionView = new CollectionView
{
ItemsLayout = LinearItemsLayout.Horizontal,
HeightRequest = 40,
Margin = new Thickness(0, 0, 0, 0),
InputTransparent = true,
};
collectionView.SetBinding(CollectionView.ItemsSourceProperty, new Binding("OrderID"));
collectionView.ItemTemplate = new DataTemplate(() =>
{
var stackLayout = new StackLayout();
stackLayout.InputTransparent = true;
stackLayout.HorizontalOptions = LayoutOptions.CenterAndExpand;
stackLayout.VerticalOptions = LayoutOptions.CenterAndExpand;
stackLayout.Padding = new Thickness(5, 5, 5, 5);
var _AllocationLabel = new Label();
_AllocationLabel.SetBinding(Label.TextProperty, "OrderID");
_AllocationLabel.FontAttributes = FontAttributes.None;
_AllocationLabel.FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Button));
_AllocationLabel.TextColor = Color.Black;
_AllocationLabel.HorizontalOptions = LayoutOptions.Center;
_AllocationLabel.VerticalOptions = LayoutOptions.Center;
_AllocationLabel.BackgroundColor = Color.Red;
_AllocationLabel.InputTransparent = true;
var frame = new Frame();
frame.Content = _AllocationLabel;
frame.InputTransparent = true;
stackLayout.Children.Add(frame);
return stackLayout;
});
//return collectionVie
parentStackLayout.Children.Add(collectionView);
return parentStackLayout;
});
}
private void DataGrid_GridTapped(object sender, GridTappedEventArgs e)
{
var rowColumnIndex = e.RowColumnIndex;
}
|