|
[XAML]
….. <RelativeLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"> <syncfusion:SfDataGrid
x:Name="dataGrid"
ItemsSource="{Binding OrderInfoCollection}"
AutoGenerateColumns="True"
RelativeLayout.WidthConstraint="{ConstraintExpression
Type=RelativeToParent,Property=Width,Constant=0}"
RelativeLayout.HeightConstraint="{ConstraintExpression
Type=RelativeToParent,Property=Height,Constant=0}"
ColumnSizer="Auto">
</syncfusion:SfDataGrid>
<local:CustomStackLayout x:Name="stack" BackgroundColor="Red" RelativeLayout.XConstraint="0" d:RelativeLayout.YConstraint="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"></local:CustomStackLayout>
</RelativeLayout>
…. [C#] //MainPage.cs private SfPopupLayout popupLayout; public MainPage()
{
InitializeComponent();
stack.RightButtonPressed += RightButtonPressed1;
popupLayout = new SfPopupLayout();
this.dataGrid.GridLoaded += DataGrid_GridLoaded;
}
private void DataGrid_GridLoaded(object sender, GridLoadedEventArgs e)
{
this.dataGrid.WidthRequest = this.dataGrid.GetVisualContainer().ExtentWidth;
this.dataGrid.HeightRequest = this.dataGrid.GetVisualContainer().ExtentHeight;
this.stack.WidthRequest = this.dataGrid.GetVisualContainer().ExtentWidth;
this.stack.HeightRequest = this.dataGrid.GetVisualContainer().ExtentHeight;
}
private void RightButtonPressed1(object sender, EventArgs e)
{
popupLayout.Show(Helper.PositionX, Helper.PositionY);
}
//CustomStackLayout public class CustomStackLayout : StackLayout {
public EventHandler RightButtonPressed;
public CustomStackLayout()
{
}
protected override void LayoutChildren(double x, double y, double width, double height)
{
base.LayoutChildren(x, y, width, height);
}
public void RaiseEventHandler(double x, double y)
{
if (this.RightButtonPressed != null)
{
Helper.PositionX = x;
Helper.PositionY = y;
this.RightButtonPressed(this,EventArgs.Empty);
}
}
}
//Helder.cs public static class Helper {
public static double PositionX;
public static double PositionY;
}
//Renderer class for CustomStackLayout public class StackRenderer : VisualElementRenderer<CustomStackLayout, Control> {
public StackRenderer()
{
this.PointerPressed += StackRenderer_PointerPressed;
}
private void StackRenderer_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
Windows.UI.Input.PointerPoint ptrPt = e.GetCurrentPoint((sender as Button));
if (ptrPt.Properties.IsRightButtonPressed)
{
this.Element.RaiseEventHandler(ptrPt.Position.X, ptrPt.Position.Y);
}
}
} |