Articles in this section
Category / Section

How to align Xamarin.Android DataGrid in the center of its parent?

1 min read

The SfDataGrid can be aligned to the center of its parent, by setting the gravity of its parent to center and by setting appropriate layout parameters to the grid.

Refer the below code example in which the gravity of the grid’s parent is set as “center” and its layout parameters is set as wrap_content to display the grid in the center of its parent.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"    
    android:layout_gravity="center"
    android:id="@+id/frameLayout"
    > 
</FrameLayout>

 

The below code illustrates setting width and height constraints to a SfDataGrid.

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);
    SetContentView(Resource.Layout.Main);
    viewModel = new ViewModel();           
    var dataGrid = new SfDataGrid(this);
    dataGrid.ItemsSource = viewModel.Collection;
    dataGrid.LayoutParameters.Height = 1000;
    dataGrid.LayoutParameters.Width = 800;          
    var frameLayout = FindViewById<FrameLayout>(Resource.Id.frameLayout);
    frameLayout.AddView(dataGrid);
}

 

Screenshot:

 

C:\Users\suhasini.suresh\AppData\Local\Microsoft\Windows\INetCacheContent.Word\Screenshot_2017-01-19-15-58-26_CenterAlignGrid.CenterAlignGrid.png

Sample Link:

How to align SfDataGrid in the center of its parent

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied