diff --git a/README.md b/README.md index 429e7b0..c92607d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,107 @@ -# How-to-populate-data-using-WebAPI-in-MAUI-DataGrid- -How to populate data using WebAPI in MAUI DataGrid? +# How to populate data using WebAPI in MAUI DataGrid? +The [.NET MAUI DataGrid](https://www.syncfusion.com/maui-controls/maui-datagrid) supports binding the item source from a Web API. + +##### C# +Create a **JSON** data model. + +**OrderInfo** +```C# +public class OrderInfo +{ + public int OrderID { get; set; } + public string? CustomerID { get; set; } + public int EmployeeID { get; set; } + public double Freight { get; set; } + public string? ShipCity { get; set; } + public bool Verified { get; set; } + public DateTime OrderDate { get; set; } + public string? ShipName { get; set; } + public string? ShipCountry { get; set; } + public DateTime ShippedDate { get; set; } + public string? ShipAddress { get; set; } +} +``` +Create a WebApiServices class within the Services folder. + +**WebApiServices** + +Utilize the webApiUrl to retrive the data using the ReadDataAsync() function. Read the response using the **ReadAsStringAsync()** method and deserialize the JSON object using the [Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json) package. + +```C# +internal class WebApiServices +{ + #region Fields + + public static string webApiUrl = "https://ej2services.syncfusion.com/production/web-services/api/Orders"; // Your Web Api here + + HttpClient client; + + #endregion + + #region Constructor + + public WebApiServices() + { + client = new HttpClient(); + } + + #endregion + + #region RefreshDataAsync + + /// + /// Retrieves data from the web service. + /// + /// Returns the ObservableCollection. + public async Task>? ReadDataAsync() + { + var uri = new Uri(webApiUrl); + try + { + //Sends request to retrieve data from the web service for the specified Uri + var response = await client.GetAsync(uri); + + if (response.IsSuccessStatusCode) + { + var content = await response.Content.ReadAsStringAsync(); //Returns the response as JSON string + return JsonConvert.DeserializeObject>(content)!; //Converts JSON string to ObservableCollection + } + } + catch (Exception ex) + { + System.Diagnostics.Debug.WriteLine(@"ERROR {0}", ex.Message); + } + + return null; + } + + #endregion +} +``` + +**OrderInfoViewModel** + +Populate the data using the ReadDataAsync() in the viewmodel. + +```C# +private async void GenerateData() +{ + OrderInfoCollection = await webApiServices.ReadDataAsync()!; +} +``` + +The following screenshot shows how to to populate data using WebAPI in MAUI DataGrid. + +![DataGrid with JSON data](SfDataGrid_WebApi.png) + +[View sample in GitHub](https://github.com/SyncfusionExamples/How-to-populate-data-using-WebAPI-in-MAUI-DataGrid) + +Take a moment to pursue this [documentation](https://help.syncfusion.com/maui/datagrid/overview), where you can find more 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). + +### Conclusion +I hope you enjoyed learning about how to populate data using WebAPI in MAUI DataGrid. + +You can refer to our [.NET MAUI DataGrid's feature tour](https://www.syncfusion.com/maui-controls/maui-datagrid) page to know 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 from 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 check out our .NET MAUI DataGrid and other .NET MAUI components. +If you have any queries or require clarifications, please let us know in 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). We are always happy to assist you! \ No newline at end of file diff --git a/SfDataGridSample/App.xaml b/SfDataGridSample/App.xaml new file mode 100644 index 0000000..17ccdfd --- /dev/null +++ b/SfDataGridSample/App.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/SfDataGridSample/App.xaml.cs b/SfDataGridSample/App.xaml.cs new file mode 100644 index 0000000..70f8033 --- /dev/null +++ b/SfDataGridSample/App.xaml.cs @@ -0,0 +1,12 @@ +namespace SfDataGridSample +{ + public partial class App : Application + { + public App() + { + InitializeComponent(); + + MainPage = new AppShell(); + } + } +} diff --git a/SfDataGridSample/AppShell.xaml b/SfDataGridSample/AppShell.xaml new file mode 100644 index 0000000..36f37ae --- /dev/null +++ b/SfDataGridSample/AppShell.xaml @@ -0,0 +1,15 @@ + + + + + + diff --git a/SfDataGridSample/AppShell.xaml.cs b/SfDataGridSample/AppShell.xaml.cs new file mode 100644 index 0000000..f5ff6e6 --- /dev/null +++ b/SfDataGridSample/AppShell.xaml.cs @@ -0,0 +1,10 @@ +namespace SfDataGridSample +{ + public partial class AppShell : Shell + { + public AppShell() + { + InitializeComponent(); + } + } +} diff --git a/SfDataGridSample/Helper/WebApiServices.cs b/SfDataGridSample/Helper/WebApiServices.cs new file mode 100644 index 0000000..5fc0ab0 --- /dev/null +++ b/SfDataGridSample/Helper/WebApiServices.cs @@ -0,0 +1,53 @@ +using Newtonsoft.Json; +using SfDataGridSample.Model; +using System.Collections.ObjectModel; + +namespace SfDataGridSample +{ + internal class WebApiServices + { + #region Fields + + public static string webApiUrl = "https://ej2services.syncfusion.com/production/web-services/api/Orders"; // Your Web Api here + + HttpClient client; + + #endregion + + #region Constructor + public WebApiServices() + { + client = new HttpClient(); + } + #endregion + + #region RefreshDataAsync + + /// + /// Retrieves data from the web service. + /// + /// Returns the ObservableCollection. + public async Task>? ReadDataAsync() + { + var uri = new Uri(webApiUrl); + try + { + //Sends request to retrieve data from the web service for the specified Uri + var response = await client.GetAsync(uri); + + if (response.IsSuccessStatusCode) + { + var content = await response.Content.ReadAsStringAsync(); //Returns the response as JSON string + return JsonConvert.DeserializeObject>(content)!; //Converts JSON string to ObservableCollection + } + } + catch (Exception ex) + { + System.Diagnostics.Debug.WriteLine(@"ERROR {0}", ex.Message); + } + + return null; + } + #endregion + } +} diff --git a/SfDataGridSample/MainPage.xaml b/SfDataGridSample/MainPage.xaml new file mode 100644 index 0000000..00c3d03 --- /dev/null +++ b/SfDataGridSample/MainPage.xaml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + diff --git a/SfDataGridSample/MainPage.xaml.cs b/SfDataGridSample/MainPage.xaml.cs new file mode 100644 index 0000000..47f465c --- /dev/null +++ b/SfDataGridSample/MainPage.xaml.cs @@ -0,0 +1,18 @@ +using Syncfusion.Maui.DataGrid; +using System; +using System.Data; +using System.Data.Common; +using System.Reflection; +namespace SfDataGridSample +{ + public partial class MainPage : ContentPage + { + public MainPage() + { + InitializeComponent(); + } + + } + + +} \ No newline at end of file diff --git a/SfDataGridSample/MauiProgram.cs b/SfDataGridSample/MauiProgram.cs new file mode 100644 index 0000000..8955998 --- /dev/null +++ b/SfDataGridSample/MauiProgram.cs @@ -0,0 +1,27 @@ +using Microsoft.Extensions.Logging; +using Syncfusion.Maui.Core.Hosting; + +namespace SfDataGridSample +{ + public static class MauiProgram + { + public static MauiApp CreateMauiApp() + { + var builder = MauiApp.CreateBuilder(); + builder + .UseMauiApp() + .ConfigureSyncfusionCore() + .ConfigureFonts(fonts => + { + fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); + fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); + }); + +#if DEBUG + builder.Logging.AddDebug(); +#endif + + return builder.Build(); + } + } +} diff --git a/SfDataGridSample/Model/OrderInfo.cs b/SfDataGridSample/Model/OrderInfo.cs new file mode 100644 index 0000000..b8050a4 --- /dev/null +++ b/SfDataGridSample/Model/OrderInfo.cs @@ -0,0 +1,17 @@ +namespace SfDataGridSample.Model +{ + public class OrderInfo + { + public int OrderID { get; set; } + public string? CustomerID { get; set; } + public int EmployeeID { get; set; } + public double Freight { get; set; } + public string? ShipCity { get; set; } + public bool Verified { get; set; } + public DateTime OrderDate { get; set; } + public string? ShipName { get; set; } + public string? ShipCountry { get; set; } + public DateTime ShippedDate { get; set; } + public string? ShipAddress { get; set; } + } +} diff --git a/SfDataGridSample/Platforms/Android/AndroidManifest.xml b/SfDataGridSample/Platforms/Android/AndroidManifest.xml new file mode 100644 index 0000000..e9937ad --- /dev/null +++ b/SfDataGridSample/Platforms/Android/AndroidManifest.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SfDataGridSample/Platforms/Android/MainActivity.cs b/SfDataGridSample/Platforms/Android/MainActivity.cs new file mode 100644 index 0000000..f22ff99 --- /dev/null +++ b/SfDataGridSample/Platforms/Android/MainActivity.cs @@ -0,0 +1,11 @@ +using Android.App; +using Android.Content.PM; +using Android.OS; + +namespace SfDataGridSample +{ + [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] + public class MainActivity : MauiAppCompatActivity + { + } +} diff --git a/SfDataGridSample/Platforms/Android/MainApplication.cs b/SfDataGridSample/Platforms/Android/MainApplication.cs new file mode 100644 index 0000000..ab00d6f --- /dev/null +++ b/SfDataGridSample/Platforms/Android/MainApplication.cs @@ -0,0 +1,16 @@ +using Android.App; +using Android.Runtime; + +namespace SfDataGridSample +{ + [Application] + public class MainApplication : MauiApplication + { + public MainApplication(IntPtr handle, JniHandleOwnership ownership) + : base(handle, ownership) + { + } + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + } +} diff --git a/SfDataGridSample/Platforms/Android/Resources/values/colors.xml b/SfDataGridSample/Platforms/Android/Resources/values/colors.xml new file mode 100644 index 0000000..c04d749 --- /dev/null +++ b/SfDataGridSample/Platforms/Android/Resources/values/colors.xml @@ -0,0 +1,6 @@ + + + #512BD4 + #2B0B98 + #2B0B98 + \ No newline at end of file diff --git a/SfDataGridSample/Platforms/MacCatalyst/AppDelegate.cs b/SfDataGridSample/Platforms/MacCatalyst/AppDelegate.cs new file mode 100644 index 0000000..a135bbc --- /dev/null +++ b/SfDataGridSample/Platforms/MacCatalyst/AppDelegate.cs @@ -0,0 +1,10 @@ +using Foundation; + +namespace SfDataGridSample +{ + [Register("AppDelegate")] + public class AppDelegate : MauiUIApplicationDelegate + { + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + } +} diff --git a/SfDataGridSample/Platforms/MacCatalyst/Entitlements.plist b/SfDataGridSample/Platforms/MacCatalyst/Entitlements.plist new file mode 100644 index 0000000..de4adc9 --- /dev/null +++ b/SfDataGridSample/Platforms/MacCatalyst/Entitlements.plist @@ -0,0 +1,14 @@ + + + + + + + com.apple.security.app-sandbox + + + com.apple.security.network.client + + + + diff --git a/SfDataGridSample/Platforms/MacCatalyst/Info.plist b/SfDataGridSample/Platforms/MacCatalyst/Info.plist new file mode 100644 index 0000000..7268977 --- /dev/null +++ b/SfDataGridSample/Platforms/MacCatalyst/Info.plist @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + UIDeviceFamily + + 2 + + UIRequiredDeviceCapabilities + + arm64 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + XSAppIconAssets + Assets.xcassets/appicon.appiconset + + diff --git a/SfDataGridSample/Platforms/MacCatalyst/Program.cs b/SfDataGridSample/Platforms/MacCatalyst/Program.cs new file mode 100644 index 0000000..b32ce4c --- /dev/null +++ b/SfDataGridSample/Platforms/MacCatalyst/Program.cs @@ -0,0 +1,16 @@ +using ObjCRuntime; +using UIKit; + +namespace SfDataGridSample +{ + public class Program + { + // This is the main entry point of the application. + static void Main(string[] args) + { + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); + } + } +} diff --git a/SfDataGridSample/Platforms/Tizen/Main.cs b/SfDataGridSample/Platforms/Tizen/Main.cs new file mode 100644 index 0000000..1ce167d --- /dev/null +++ b/SfDataGridSample/Platforms/Tizen/Main.cs @@ -0,0 +1,17 @@ +using Microsoft.Maui; +using Microsoft.Maui.Hosting; +using System; + +namespace SfDataGridSample +{ + internal class Program : MauiApplication + { + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + + static void Main(string[] args) + { + var app = new Program(); + app.Run(args); + } + } +} diff --git a/SfDataGridSample/Platforms/Tizen/tizen-manifest.xml b/SfDataGridSample/Platforms/Tizen/tizen-manifest.xml new file mode 100644 index 0000000..4590aad --- /dev/null +++ b/SfDataGridSample/Platforms/Tizen/tizen-manifest.xml @@ -0,0 +1,15 @@ + + + + + + maui-appicon-placeholder + + + + + http://tizen.org/privilege/internet + + + + \ No newline at end of file diff --git a/SfDataGridSample/Platforms/Windows/App.xaml b/SfDataGridSample/Platforms/Windows/App.xaml new file mode 100644 index 0000000..bafc97c --- /dev/null +++ b/SfDataGridSample/Platforms/Windows/App.xaml @@ -0,0 +1,8 @@ + + + diff --git a/SfDataGridSample/Platforms/Windows/App.xaml.cs b/SfDataGridSample/Platforms/Windows/App.xaml.cs new file mode 100644 index 0000000..bcfa104 --- /dev/null +++ b/SfDataGridSample/Platforms/Windows/App.xaml.cs @@ -0,0 +1,25 @@ +using Microsoft.UI.Xaml; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace SfDataGridSample.WinUI +{ + /// + /// Provides application-specific behavior to supplement the default Application class. + /// + public partial class App : MauiWinUIApplication + { + /// + /// Initializes the singleton application object. This is the first line of authored code + /// executed, and as such is the logical equivalent of main() or WinMain(). + /// + public App() + { + this.InitializeComponent(); + } + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + } + +} diff --git a/SfDataGridSample/Platforms/Windows/Package.appxmanifest b/SfDataGridSample/Platforms/Windows/Package.appxmanifest new file mode 100644 index 0000000..56d9ed1 --- /dev/null +++ b/SfDataGridSample/Platforms/Windows/Package.appxmanifest @@ -0,0 +1,46 @@ + + + + + + + + + $placeholder$ + User Name + $placeholder$.png + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SfDataGridSample/Platforms/Windows/app.manifest b/SfDataGridSample/Platforms/Windows/app.manifest new file mode 100644 index 0000000..9e025c0 --- /dev/null +++ b/SfDataGridSample/Platforms/Windows/app.manifest @@ -0,0 +1,15 @@ + + + + + + + + true/PM + PerMonitorV2, PerMonitor + + + diff --git a/SfDataGridSample/Platforms/iOS/AppDelegate.cs b/SfDataGridSample/Platforms/iOS/AppDelegate.cs new file mode 100644 index 0000000..a135bbc --- /dev/null +++ b/SfDataGridSample/Platforms/iOS/AppDelegate.cs @@ -0,0 +1,10 @@ +using Foundation; + +namespace SfDataGridSample +{ + [Register("AppDelegate")] + public class AppDelegate : MauiUIApplicationDelegate + { + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + } +} diff --git a/SfDataGridSample/Platforms/iOS/Info.plist b/SfDataGridSample/Platforms/iOS/Info.plist new file mode 100644 index 0000000..0004a4f --- /dev/null +++ b/SfDataGridSample/Platforms/iOS/Info.plist @@ -0,0 +1,32 @@ + + + + + LSRequiresIPhoneOS + + UIDeviceFamily + + 1 + 2 + + UIRequiredDeviceCapabilities + + arm64 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + XSAppIconAssets + Assets.xcassets/appicon.appiconset + + diff --git a/SfDataGridSample/Platforms/iOS/Program.cs b/SfDataGridSample/Platforms/iOS/Program.cs new file mode 100644 index 0000000..b32ce4c --- /dev/null +++ b/SfDataGridSample/Platforms/iOS/Program.cs @@ -0,0 +1,16 @@ +using ObjCRuntime; +using UIKit; + +namespace SfDataGridSample +{ + public class Program + { + // This is the main entry point of the application. + static void Main(string[] args) + { + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); + } + } +} diff --git a/SfDataGridSample/Properties/launchSettings.json b/SfDataGridSample/Properties/launchSettings.json new file mode 100644 index 0000000..edf8aad --- /dev/null +++ b/SfDataGridSample/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Windows Machine": { + "commandName": "MsixPackage", + "nativeDebugging": false + } + } +} \ No newline at end of file diff --git a/SfDataGridSample/Resources/AppIcon/appicon.svg b/SfDataGridSample/Resources/AppIcon/appicon.svg new file mode 100644 index 0000000..9d63b65 --- /dev/null +++ b/SfDataGridSample/Resources/AppIcon/appicon.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/SfDataGridSample/Resources/AppIcon/appiconfg.svg b/SfDataGridSample/Resources/AppIcon/appiconfg.svg new file mode 100644 index 0000000..21dfb25 --- /dev/null +++ b/SfDataGridSample/Resources/AppIcon/appiconfg.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/SfDataGridSample/Resources/Fonts/OpenSans-Regular.ttf b/SfDataGridSample/Resources/Fonts/OpenSans-Regular.ttf new file mode 100644 index 0000000..3b69f73 Binary files /dev/null and b/SfDataGridSample/Resources/Fonts/OpenSans-Regular.ttf differ diff --git a/SfDataGridSample/Resources/Fonts/OpenSans-Semibold.ttf b/SfDataGridSample/Resources/Fonts/OpenSans-Semibold.ttf new file mode 100644 index 0000000..0fc5a9a Binary files /dev/null and b/SfDataGridSample/Resources/Fonts/OpenSans-Semibold.ttf differ diff --git a/SfDataGridSample/Resources/Images/dotnet_bot.png b/SfDataGridSample/Resources/Images/dotnet_bot.png new file mode 100644 index 0000000..f93ce02 Binary files /dev/null and b/SfDataGridSample/Resources/Images/dotnet_bot.png differ diff --git a/SfDataGridSample/Resources/Raw/AboutAssets.txt b/SfDataGridSample/Resources/Raw/AboutAssets.txt new file mode 100644 index 0000000..15d6244 --- /dev/null +++ b/SfDataGridSample/Resources/Raw/AboutAssets.txt @@ -0,0 +1,15 @@ +Any raw assets you want to be deployed with your application can be placed in +this directory (and child directories). Deployment of the asset to your application +is automatically handled by the following `MauiAsset` Build Action within your `.csproj`. + + + +These files will be deployed with you package and will be accessible using Essentials: + + async Task LoadMauiAsset() + { + using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt"); + using var reader = new StreamReader(stream); + + var contents = reader.ReadToEnd(); + } diff --git a/SfDataGridSample/Resources/Splash/splash.svg b/SfDataGridSample/Resources/Splash/splash.svg new file mode 100644 index 0000000..21dfb25 --- /dev/null +++ b/SfDataGridSample/Resources/Splash/splash.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/SfDataGridSample/Resources/Styles/Colors.xaml b/SfDataGridSample/Resources/Styles/Colors.xaml new file mode 100644 index 0000000..30307a5 --- /dev/null +++ b/SfDataGridSample/Resources/Styles/Colors.xaml @@ -0,0 +1,45 @@ + + + + + + + #512BD4 + #ac99ea + #242424 + #DFD8F7 + #9880e5 + #2B0B98 + + White + Black + #D600AA + #190649 + #1f1f1f + + #E1E1E1 + #C8C8C8 + #ACACAC + #919191 + #6E6E6E + #404040 + #212121 + #141414 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SfDataGridSample/Resources/Styles/Styles.xaml b/SfDataGridSample/Resources/Styles/Styles.xaml new file mode 100644 index 0000000..e0d36bb --- /dev/null +++ b/SfDataGridSample/Resources/Styles/Styles.xaml @@ -0,0 +1,426 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SfDataGridSample/SfDataGridSample.csproj b/SfDataGridSample/SfDataGridSample.csproj new file mode 100644 index 0000000..8a7c51d --- /dev/null +++ b/SfDataGridSample/SfDataGridSample.csproj @@ -0,0 +1,67 @@ + + + + net8.0-android;net8.0-ios;net8.0-maccatalyst + $(TargetFrameworks);net8.0-windows10.0.19041.0 + + + + + + + Exe + SfDataGridSample + true + true + enable + enable + + + SfDataGridSample + + + com.companyname.sfdatagridsample + + + 1.0 + 1 + + 11.0 + 13.1 + 21.0 + 10.0.17763.0 + 10.0.17763.0 + 6.5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SfDataGridSample/SfDataGridSample.csproj.user b/SfDataGridSample/SfDataGridSample.csproj.user new file mode 100644 index 0000000..3afa8da --- /dev/null +++ b/SfDataGridSample/SfDataGridSample.csproj.user @@ -0,0 +1,37 @@ + + + + False + net8.0-windows10.0.19041.0 + Windows Machine + Emulator + pixel_5_-_api_34 + + + ProjectDebugger + + + + + Designer + + + Designer + + + Designer + + + Designer + + + Designer + + + Designer + + + Designer + + + \ No newline at end of file diff --git a/SfDataGridSample/SfDataGridSample.sln b/SfDataGridSample/SfDataGridSample.sln new file mode 100644 index 0000000..629b79a --- /dev/null +++ b/SfDataGridSample/SfDataGridSample.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34622.214 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SfDataGridSample", "SfDataGridSample.csproj", "{0E1A6EBF-601F-417D-B852-8A95E27C4C04}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + Release-Xml|Any CPU = Release-Xml|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0E1A6EBF-601F-417D-B852-8A95E27C4C04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0E1A6EBF-601F-417D-B852-8A95E27C4C04}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E1A6EBF-601F-417D-B852-8A95E27C4C04}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {0E1A6EBF-601F-417D-B852-8A95E27C4C04}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0E1A6EBF-601F-417D-B852-8A95E27C4C04}.Release|Any CPU.Build.0 = Release|Any CPU + {0E1A6EBF-601F-417D-B852-8A95E27C4C04}.Release|Any CPU.Deploy.0 = Release|Any CPU + {0E1A6EBF-601F-417D-B852-8A95E27C4C04}.Release-Xml|Any CPU.ActiveCfg = Release|Any CPU + {0E1A6EBF-601F-417D-B852-8A95E27C4C04}.Release-Xml|Any CPU.Build.0 = Release|Any CPU + {0E1A6EBF-601F-417D-B852-8A95E27C4C04}.Release-Xml|Any CPU.Deploy.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6BB4ECB7-0F0F-4590-AB5D-1FB95ADB56D4} + EndGlobalSection +EndGlobal diff --git a/SfDataGridSample/ViewModel/OrderInfoViewModel.cs b/SfDataGridSample/ViewModel/OrderInfoViewModel.cs new file mode 100644 index 0000000..f0862cb --- /dev/null +++ b/SfDataGridSample/ViewModel/OrderInfoViewModel.cs @@ -0,0 +1,42 @@ +using SfDataGridSample.Model; +using System.Collections.ObjectModel; +using System.ComponentModel; + +namespace SfDataGridSample +{ + internal class OrderInfoViewModel : INotifyPropertyChanged + { + + private ObservableCollection? orderInfoCollection; + + WebApiServices webApiServices; + + + public ObservableCollection? OrderInfoCollection + { + get { return orderInfoCollection; } + set { this.orderInfoCollection = value; this.OnPropertyChanged(nameof(OrderInfoCollection)); } + } + + + public OrderInfoViewModel() + { + webApiServices = new WebApiServices(); + orderInfoCollection = new ObservableCollection(); + GenerateData(); + } + + private async void GenerateData() + { + OrderInfoCollection = await webApiServices.ReadDataAsync()!; + } + + public event PropertyChangedEventHandler? PropertyChanged; + + public void OnPropertyChanged(string name) + { + if (this.PropertyChanged != null) + this.PropertyChanged(this, new PropertyChangedEventArgs(name)); + } + } +} diff --git a/SfDataGrid_WebApi.png b/SfDataGrid_WebApi.png new file mode 100644 index 0000000..5c2b11c Binary files /dev/null and b/SfDataGrid_WebApi.png differ