Skip to content

Commit 701e1a6

Browse files
Merge pull request #1 from SyncfusionExamples/860347
MAUI-860347-How to load .NET MAUI DataGrid (SfDataGrid) in a StackLayout
2 parents d6bf784 + b974e5a commit 701e1a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1370
-2
lines changed

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
1-
# How-to-load-.NET-MAUI-DataGrid-SfDataGrid-in-a-StackLayout
2-
This demo shows how to load .NET MAUI DataGrid (SfDataGrid) in a StackLayout?
1+
# How to load .NET MAUI DataGrid SfDataGrid in a StackLayout
2+
The [SfDataGrid](https://www.syncfusion.com/maui-controls/maui-datagrid) control can be incorporated into various layouts, including GridLayout and StackLayout.
3+
4+
Please consult the code example below for guidance on loading the `SfDataGrid` control within a StackLayout.
5+
6+
```XML
7+
<StackLayout>
8+
<syncfusion:SfDataGrid ColumnWidthMode="Auto"
9+
VerticalOptions="CenterAndExpand"
10+
ItemsSource="{Binding Employees}">
11+
12+
</syncfusion:SfDataGrid>
13+
</StackLayout>
14+
```
15+
16+
17+
Executing the code example above yields the following output.
18+
19+
<img src="dataGridWithStackLayout.png" width="360">
20+
21+
[View sample in GitHub](https://github.com/SyncfusionExamples/How-to-load-.NET-MAUI-DataGrid-SfDataGrid-in-a-StackLayout/pull/1)
22+
23+
Take a moment to explore this [documentation](https://help.syncfusion.com/maui/datagrid/overview), where you can find more information about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this [link](https://www.syncfusion.com/maui-controls/maui-datagrid) to learn about the essential features of Syncfusion .NET MAUI DataGrid (SfDataGrid).
24+
25+
##### Conclusion
26+
27+
I hope you enjoyed learning about how to load .NET MAUI DataGrid (SfDataGrid) in a StackLayout.
28+
29+
You can refer to our [.NET MAUI DataGrid’s feature tour](https://www.syncfusion.com/maui-controls/maui-datagrid) page to learn about its other groundbreaking feature representations. You can also explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data. For current customers, you can check out our .NET MAUI components on the [License and Downloads](https://www.syncfusion.com/account/downloads) page. If you are new to Syncfusion, you can try our 30-day free trial to explore our .NET MAUI DataGrid and other .NET MAUI components. If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our [support forums](https://www.syncfusion.com/forums), [Direct-Trac](https://support.syncfusion.com/account/login?ReturnUrl=%2Faccount%2Fconnect%2Fauthorize%2Fcallback%3Fclient_id%3Dc54e52f3eb3cde0c3f20474f1bc179ed%26redirect_uri%3Dhttps%253A%252F%252Fsupport.syncfusion.com%252Fagent%252Flogincallback%26response_type%3Dcode%26scope%3Dopenid%2520profile%2520agent.api%2520integration.api%2520offline_access%2520kb.api%26state%3D8db41f98953a4d9ba40407b150ad4cf2%26code_challenge%3DvwHoT64z2h21eP_A9g7JWtr3vp3iPrvSjfh5hN5C7IE%26code_challenge_method%3DS256%26response_mode%3Dquery) or [feedback portal](https://www.syncfusion.com/feedback/maui?control=sfdatagrid), or the feedback portal. We are always happy to assist you!

SfDataGridSample.sln

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34309.116
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SfDataGridSample", "SfDataGridSample\SfDataGridSample.csproj", "{B98BD67C-738A-4295-9C50-C99E9AF5C281}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{B98BD67C-738A-4295-9C50-C99E9AF5C281}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B98BD67C-738A-4295-9C50-C99E9AF5C281}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B98BD67C-738A-4295-9C50-C99E9AF5C281}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{B98BD67C-738A-4295-9C50-C99E9AF5C281}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{B98BD67C-738A-4295-9C50-C99E9AF5C281}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{B98BD67C-738A-4295-9C50-C99E9AF5C281}.Release|Any CPU.Deploy.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(ExtensibilityGlobals) = postSolution
25+
SolutionGuid = {B0D9A0CE-D9C3-4CC3-9746-DDFB2608D4B2}
26+
EndGlobalSection
27+
EndGlobal

SfDataGridSample/App.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:SfDataGridSample"
5+
x:Class="SfDataGridSample.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>

SfDataGridSample/App.xaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace SfDataGridSample
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
10+
}
11+
}
12+
}

SfDataGridSample/AppShell.xaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="SfDataGridSample.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:SfDataGridSample"
7+
Shell.FlyoutBehavior="Disabled"
8+
Title="SfDataGridSample">
9+
10+
<ShellContent
11+
Title="Home"
12+
ContentTemplate="{DataTemplate local:MainPage}"
13+
Route="MainPage" />
14+
15+
</Shell>

SfDataGridSample/AppShell.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace SfDataGridSample
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}

SfDataGridSample/MainPage.xaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid"
5+
xmlns:local="clr-namespace:SfDataGridSample"
6+
x:Class="SfDataGridSample.MainPage">
7+
8+
<ContentPage.BindingContext>
9+
<local:EmployeeViewModel />
10+
</ContentPage.BindingContext>
11+
12+
<StackLayout>
13+
<syncfusion:SfDataGrid ColumnWidthMode="Auto"
14+
VerticalOptions="CenterAndExpand"
15+
ItemsSource="{Binding Employees}">
16+
17+
</syncfusion:SfDataGrid>
18+
</StackLayout>
19+
20+
</ContentPage>

SfDataGridSample/MainPage.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Syncfusion.Maui.Data;
2+
using Syncfusion.Maui.DataGrid;
3+
using Syncfusion.Maui.DataGrid.Helper;
4+
5+
namespace SfDataGridSample
6+
{
7+
public partial class MainPage : ContentPage
8+
{
9+
public MainPage()
10+
{
11+
InitializeComponent();
12+
}
13+
}
14+
}

SfDataGridSample/MauiProgram.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.Extensions.Logging;
2+
using Syncfusion.Maui.Core.Hosting;
3+
4+
namespace SfDataGridSample
5+
{
6+
public static class MauiProgram
7+
{
8+
public static MauiApp CreateMauiApp()
9+
{
10+
var builder = MauiApp.CreateBuilder();
11+
builder
12+
.UseMauiApp<App>()
13+
.ConfigureFonts(fonts =>
14+
{
15+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
16+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
17+
});
18+
19+
#if DEBUG
20+
builder.Logging.AddDebug();
21+
#endif
22+
builder.ConfigureSyncfusionCore();
23+
return builder.Build();
24+
}
25+
}
26+
}

SfDataGridSample/Model/Employee.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.ComponentModel;
2+
3+
namespace SfDataGridSample
4+
{
5+
public class Employee
6+
{
7+
public string EmployeeID { get; set; }
8+
public string Name { get; set; }
9+
public long IDNumber { get; set; }
10+
public string Title { get; set; }
11+
public int ContactID { get; set; }
12+
public DateTime BirthDate { get; set; }
13+
public string MaritalStatus { get; set; }
14+
public string Gender { get; set; }
15+
public DateTime HireDate { get; set; }
16+
public int SickLeaveHours { get; set; }
17+
public double Salary { get; set; }
18+
public string LoginID { get; set; }
19+
public int ManagerID { get; set; }
20+
public bool EmployeeStatus { get; set; }
21+
public int Rating { get; set; }
22+
}
23+
24+
}

0 commit comments

Comments
 (0)