public partial class MainPage : ContentPage
{
private Label popupLabel;
private bool ispopupDisplayed = false;
private string currentColumnName;
public MainPage()
{
InitializeComponent();
CreateToolTip();
datagrid.GridDoubleTapped += Datagrid_GridDoubleTapped;
datagrid.GridTapped += Datagrid_GridTapped;
}
private void Datagrid_GridTapped(object sender, GridTappedEventsArgs e)
{
relativeLayout.Children.Remove(popupLabel);
ispopupDisplayed = false;
}
public void CreateToolTip()
{
popupLabel = new Label();
popupLabel.HorizontalTextAlignment = TextAlignment.Center;
popupLabel.VerticalTextAlignment = TextAlignment.Center;
popupLabel.WidthRequest = 90;
popupLabel.HeightRequest = 50;
popupLabel.BackgroundColor = Color.Gray;
popupLabel.TextColor = Color.Black;
}
private void Datagrid_GridDoubleTapped(object sender, GridDoubleTappedEventsArgs e)
{
if (!ispopupDisplayed)
{
currentColumnName = datagrid.Columns[e.RowColumnIndex.ColumnIndex].MappingName;
var point = datagrid.RowColumnIndexToPoint(e.RowColumnIndex);
relativeLayout.Children.Add(popupLabel, Constraint.Constant(point.X + 50), Constraint.Constant(point.Y + 30));
var rowData = datagrid.GetRecordAtRowIndex(e.RowColumnIndex.RowIndex);
var cellValue = datagrid.GetCellValue(rowData, currentColumnName);
popupLabel.Text = cellValue.ToString();
ispopupDisplayed = true;
}
else
{
relativeLayout.Children.Remove(popupLabel);
ispopupDisplayed = false;
}
}
} |