diff --git a/README.md b/README.md index 6bb1bf3..374ff79 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,100 @@ -# How-to-set-multiple-selection-background-in-.NET-MAUI-DataGrid -How to set multiple selection background in .NET MAUI DataGrid +# How to set multiple selection background in .NET MAUI DataGrid + +In this article, we will show you how to set multiple selection background in [.NET MAUI DataGrid](https://www.syncfusion.com/maui-controls/maui-datagrid). + +**XAML** +``` + + + + + + + + + + ``` + +C# +The below code illustrates how to set multiple selection background with custom Cell renderer. +``` + public partial class MainPage : ContentPage + { + public MainPage() + { + InitializeComponent(); + sfGrid.CellRenderers.Remove("Text"); + sfGrid.CellRenderers.Add("Text", new CustomRenderer()); + sfGrid.CellRenderers.Remove("Numeric"); + sfGrid.CellRenderers.Add("Numeric", new CustomRenderer()); + sfGrid.CellRenderers.Remove("CheckBox"); + sfGrid.CellRenderers.Add("CheckBox", new CustomRenderer()); + sfGrid.CellRenderers.Remove("Template"); + sfGrid.CellRenderers.Add("Template", new CustomRenderer()); + sfGrid.CellRenderers.Remove("Image"); + sfGrid.CellRenderers.Add("Image", new CustomRenderer()); + sfGrid.CellRenderers.Remove("DateTime"); + sfGrid.CellRenderers.Add("DateTime", new CustomRenderer()); + sfGrid.CellRenderers.Remove("ComboBox"); + sfGrid.CellRenderers.Add("ComboBox", new CustomRenderer()); + } + } + + public class CustomRenderer : DataGridCellRenderer + { + protected override void OnSetCellStyle(DataColumnBase dataColumn) + { + base.OnSetCellStyle(dataColumn); + + if (dataColumn != null) + { + + var gridStyle = this.DataGrid?.DefaultStyle; + DataGridCell? gridCell = dataColumn.ColumnElement; + var dataRow = dataColumn.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name.Equals("DataRow"))!.GetValue(dataColumn); + + if (DataGrid!.SelectionController.SelectedRows.Any(row => row.RowData == dataColumn.RowData && (dataRow as DataRow)!.IsSelectedRow)) + { + var rowData = (dataRow as DataRow).RowData as Employee; + if(rowData.Title.Equals("Assistant")) + (gridCell as DataGridCell).Background = Color.FromRgba("caf0f8"); + else if (rowData.Title.Equals("Engineering")) + (gridCell as DataGridCell).Background = Color.FromRgba("00b4d8"); + else if (rowData.Title.Equals("Designer")) + (gridCell as DataGridCell).Background = Color.FromRgba("ff99c8"); + else if (rowData.Title.Equals("Manager")) + (gridCell as DataGridCell).Background = Color.FromRgba("fb6f92"); + } + + gridStyle = null; + gridCell = null; + } + } + } +``` + + + ![MultipleSelection.gif](https://support.syncfusion.com/kb/agent/attachment/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjI1MDEzIiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5zeW5jZnVzaW9uLmNvbSJ9.bdYMSSL6gTiS4GiH7uL_It73U76jwrG1nXPYB_qW6RI) + +[View sample in GitHub](https://github.com/SyncfusionExamples/How-to-set-multiple-selection-background-in-.NET-MAUI-DataGrid) + +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). + +##### Conclusion + +I hope you enjoyed learning about how to set multiple selection background in .NET MAUI DataGrid. + +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](https://help.syncfusion.com/maui/datagrid/getting-started) 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/sales/teamlicense) page. If you are new to Syncfusion, you can try our 30-day [free trial](https://www.syncfusion.com/downloads/maui) 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/create) or [feedback portal](https://www.syncfusion.com/feedback/maui?control=sfdatagrid), or the feedback portal. 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/MainPage.xaml b/SfDataGridSample/MainPage.xaml new file mode 100644 index 0000000..568a2e4 --- /dev/null +++ b/SfDataGridSample/MainPage.xaml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + diff --git a/SfDataGridSample/MainPage.xaml.cs b/SfDataGridSample/MainPage.xaml.cs new file mode 100644 index 0000000..3564f31 --- /dev/null +++ b/SfDataGridSample/MainPage.xaml.cs @@ -0,0 +1,62 @@ +using Syncfusion.Maui.DataGrid; +using Syncfusion.Maui.GridCommon.ScrollAxis; +using Syncfusion.Maui.Inputs; +using System.Collections.Specialized; +using System.Reflection; + +namespace SfDataGridSample +{ + public partial class MainPage : ContentPage + { + public MainPage() + { + InitializeComponent(); + sfGrid.CellRenderers.Remove("Text"); + sfGrid.CellRenderers.Add("Text", new CustomRenderer()); + sfGrid.CellRenderers.Remove("Numeric"); + sfGrid.CellRenderers.Add("Numeric", new CustomRenderer()); + sfGrid.CellRenderers.Remove("CheckBox"); + sfGrid.CellRenderers.Add("CheckBox", new CustomRenderer()); + sfGrid.CellRenderers.Remove("Template"); + sfGrid.CellRenderers.Add("Template", new CustomRenderer()); + sfGrid.CellRenderers.Remove("Image"); + sfGrid.CellRenderers.Add("Image", new CustomRenderer()); + sfGrid.CellRenderers.Remove("DateTime"); + sfGrid.CellRenderers.Add("DateTime", new CustomRenderer()); + sfGrid.CellRenderers.Remove("ComboBox"); + sfGrid.CellRenderers.Add("ComboBox", new CustomRenderer()); + } + } + + public class CustomRenderer : DataGridCellRenderer + { + protected override void OnSetCellStyle(DataColumnBase dataColumn) + { + base.OnSetCellStyle(dataColumn); + + if (dataColumn != null) + { + + var gridStyle = this.DataGrid?.DefaultStyle; + DataGridCell? gridCell = dataColumn.ColumnElement; + var dataRow = dataColumn.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name.Equals("DataRow"))!.GetValue(dataColumn); + + if (DataGrid!.SelectionController.SelectedRows.Any(row => row.RowData == dataColumn.RowData && (dataRow as DataRow)!.IsSelectedRow)) + { + var rowData = (dataRow as DataRow).RowData as Employee; + if(rowData.Title.Equals("Assistant")) + (gridCell as DataGridCell).Background = Color.FromRgba("caf0f8"); + else if (rowData.Title.Equals("Engineering")) + (gridCell as DataGridCell).Background = Color.FromRgba("00b4d8"); + else if (rowData.Title.Equals("Designer")) + (gridCell as DataGridCell).Background = Color.FromRgba("ff99c8"); + else if (rowData.Title.Equals("Manager")) + (gridCell as DataGridCell).Background = Color.FromRgba("fb6f92"); + } + + gridStyle = null; + gridCell = null; + } + } + } +} diff --git a/SfDataGridSample/MauiProgram.cs b/SfDataGridSample/MauiProgram.cs new file mode 100644 index 0000000..5dde646 --- /dev/null +++ b/SfDataGridSample/MauiProgram.cs @@ -0,0 +1,27 @@ +using Microsoft.Extensions.Logging; +using Syncfusion.Maui.Core; +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/Employee.cs b/SfDataGridSample/Model/Employee.cs new file mode 100644 index 0000000..0c5fce0 --- /dev/null +++ b/SfDataGridSample/Model/Employee.cs @@ -0,0 +1,167 @@ +using System.ComponentModel; + +namespace SfDataGridSample +{ + public class Employee : INotifyPropertyChanged + { + private int? _employeeID; + private string? _name; + private long _iDNumber; + private int _contactID; + private string? _loginID; + private int _managerID; + private string? _title; + private DateTime _birthDate; + private string? _maritalStatus; + private string? _gender; + private DateTime _hireDate; + private int _sickLeaveHours; + private double _salary; + private bool _employeeStatus; + private int _rating; + + public int? EmployeeID + { + get { return _employeeID; } + set + { + _employeeID = value; + OnPropertyChanged(nameof(EmployeeID)); + } + } + public string? Name + { + get { return _name; } + set + { + _name = value; + OnPropertyChanged(nameof(Name)); + } + } + public long IDNumber + { + get { return _iDNumber; } + set + { + _iDNumber = value; + OnPropertyChanged(nameof(IDNumber)); + } + } + public string? Title + { + get { return _title; } + set + { + _title = value; + OnPropertyChanged(nameof(Title)); + } + } + public int ContactID + { + get { return _contactID; } + set + { + _contactID = value; + OnPropertyChanged(nameof(ContactID)); + } + } + public DateTime BirthDate + { + get { return _birthDate; } + set + { + _birthDate = value; + OnPropertyChanged(nameof(BirthDate)); + } + } + public string? MaritalStatus + { + get { return _maritalStatus; } + set + { + _maritalStatus = value; + OnPropertyChanged(nameof(MaritalStatus)); + } + } + public string? Gender + { + get { return _gender; } + set + { + _gender = value; + OnPropertyChanged(nameof(Gender)); + } + } + public DateTime HireDate + { + get { return _hireDate; } + set + { + _hireDate = value; + OnPropertyChanged(nameof(HireDate)); + } + } + public int SickLeaveHours + { + get { return _sickLeaveHours; } + set + { + _sickLeaveHours = value; + OnPropertyChanged(nameof(SickLeaveHours)); + } + } + public double Salary + { + get { return _salary; } + set + { + _salary = value; + OnPropertyChanged(nameof(Salary)); + } + } + public string? LoginID + { + get { return _loginID; } + set + { + _loginID = value; + OnPropertyChanged(nameof(LoginID)); + } + } + public int ManagerID + { + get { return _managerID; } + set + { + _managerID = value; + OnPropertyChanged(nameof(ManagerID)); + } + } + public bool EmployeeStatus + { + get { return _employeeStatus; } + set + { + _employeeStatus = value; + OnPropertyChanged(nameof(EmployeeStatus)); + } + } + public int Rating + { + get { return _rating; } + set + { + _rating = value; + OnPropertyChanged(nameof(Rating)); + } + } + + public event PropertyChangedEventHandler? PropertyChanged; + + public void OnPropertyChanged(string name) + { + if (this.PropertyChanged != null) + this.PropertyChanged(this, new PropertyChangedEventArgs(name)); + } + } +} 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..8d76f7d --- /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..2d1edf0 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..fe13d06 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..b65a675 --- /dev/null +++ b/SfDataGridSample/SfDataGridSample.csproj @@ -0,0 +1,66 @@ + + + + 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..891593c --- /dev/null +++ b/SfDataGridSample/SfDataGridSample.csproj.user @@ -0,0 +1,31 @@ + + + + False + net8.0-windows10.0.19041.0 + Windows Machine + + + + 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..ca0dd41 --- /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.34902.65 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SfDataGridSample", "SfDataGridSample.csproj", "{70A2D61D-060E-4E7C-B957-29A9B4D6E9F8}" +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 + {70A2D61D-060E-4E7C-B957-29A9B4D6E9F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {70A2D61D-060E-4E7C-B957-29A9B4D6E9F8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {70A2D61D-060E-4E7C-B957-29A9B4D6E9F8}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {70A2D61D-060E-4E7C-B957-29A9B4D6E9F8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {70A2D61D-060E-4E7C-B957-29A9B4D6E9F8}.Release|Any CPU.Build.0 = Release|Any CPU + {70A2D61D-060E-4E7C-B957-29A9B4D6E9F8}.Release|Any CPU.Deploy.0 = Release|Any CPU + {70A2D61D-060E-4E7C-B957-29A9B4D6E9F8}.Release-Xml|Any CPU.ActiveCfg = Release|Any CPU + {70A2D61D-060E-4E7C-B957-29A9B4D6E9F8}.Release-Xml|Any CPU.Build.0 = Release|Any CPU + {70A2D61D-060E-4E7C-B957-29A9B4D6E9F8}.Release-Xml|Any CPU.Deploy.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C11F7952-D5C7-4382-AD36-178BA5C70A8A} + EndGlobalSection +EndGlobal diff --git a/SfDataGridSample/ViewModel/EmployeeViewModel.cs b/SfDataGridSample/ViewModel/EmployeeViewModel.cs new file mode 100644 index 0000000..b705fea --- /dev/null +++ b/SfDataGridSample/ViewModel/EmployeeViewModel.cs @@ -0,0 +1,259 @@ +using System.Collections.ObjectModel; +using System.ComponentModel; + +namespace SfDataGridSample +{ + public class EmployeeViewModel : IDisposable, INotifyPropertyChanged + { + public event PropertyChangedEventHandler? PropertyChanged; + private void NotifyPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + + public EmployeeViewModel() + { + PopulateData(); + employees = this.GetEmployeeDetails(50); + } + private ObservableCollection employees; + public ObservableCollection Employees + { + get + { + return employees; + } + set + { + this.employees = value; + NotifyPropertyChanged(nameof(Employees)); + } + } + + Random r = new Random(); + Dictionary loginID = new Dictionary(); + Dictionary gender = new Dictionary(); + + /// + /// Get the EmployeeDetails + /// + /// + /// + public ObservableCollection GetEmployeeDetails(int count) + { + employees = new ObservableCollection(); + + for (int i = 1; i < count; i++) + { + var name = employeeName[r.Next(employeeName.Length - 1)]; + employees.Add(new Employee() + { + EmployeeID = 1000 + i, + Name = name, + IDNumber = r.Next(14417807, 112457891), + ContactID = r.Next(1001, 2000), + LoginID = loginID[name], + ManagerID = r.Next(3, 70), + Gender = gender[name], + Title = title[r.Next(title.Length - 1)], + MaritalStatus = r.Next(10, 60) % 2 == 0 ? "Single" : "Married", + HireDate = new DateTime(r.Next(1995, 2005), r.Next(1, 12), r.Next(1, 28)), + BirthDate = new DateTime(r.Next(1975, 1985), r.Next(1, 12), r.Next(1, 28)), + SickLeaveHours = r.Next(15, 70), + Salary = Math.Round(r.NextDouble() * 6000.5, 2), + EmployeeStatus = r.Next() % 2 == 0 ? true : false, + Rating = r.Next(1, 11) + }); + } + + return employees; + } + + /// + /// Populate the data for Gender + /// + private void PopulateData() + { + gender.Add("Sean Jacobson", "Male"); + gender.Add("Phyllis Allen", "Male"); + gender.Add("Marvin Allen", "Male"); + gender.Add("Michael Allen", "Male"); + gender.Add("Cecil Allison", "Male"); + gender.Add("Oscar Alpuerto", "Male"); + gender.Add("Sandra Altamirano", "Female"); + gender.Add("Selena Alvarad", "Female"); + gender.Add("Emilio Alvaro", "Female"); + gender.Add("Maxwell Amland", "Male"); + gender.Add("Mae Anderson", "Male"); + gender.Add("Ramona Antrim", "Female"); + gender.Add("Sabria Appelbaum", "Male"); + gender.Add("Hannah Arakawa", "Male"); + gender.Add("Kyley Arbelaez", "Male"); + gender.Add("Tom Johnston", "Female"); + gender.Add("Thomas Armstrong", "Female"); + gender.Add("John Arthur", "Male"); + gender.Add("Chris Ashton", "Female"); + gender.Add("Teresa Atkinson", "Male"); + gender.Add("John Ault", "Male"); + gender.Add("Robert Avalos", "Male"); + gender.Add("Stephen Ayers", "Male"); + gender.Add("Phillip Bacalzo", "Male"); + gender.Add("Gustavo Achong", "Male"); + gender.Add("Catherine Abel", "Male"); + gender.Add("Kim Abercrombie", "Male"); + gender.Add("Humberto Acevedo", "Male"); + gender.Add("Pilar Ackerman", "Male"); + gender.Add("Frances Adams", "Female"); + gender.Add("Margar Smith", "Male"); + gender.Add("Carla Adams", "Male"); + gender.Add("Jay Adams", "Male"); + gender.Add("Ronald Adina", "Female"); + gender.Add("Samuel Agcaoili", "Male"); + gender.Add("James Aguilar", "Female"); + gender.Add("Robert Ahlering", "Male"); + gender.Add("Francois Ferrier", "Male"); + gender.Add("Kim Akers", "Male"); + gender.Add("Lili Alameda", "Female"); + gender.Add("Amy Alberts", "Male"); + gender.Add("Anna Albright", "Female"); + gender.Add("Milton Albury", "Male"); + gender.Add("Paul Alcorn", "Male"); + gender.Add("Gregory Alderson", "Male"); + gender.Add("J. Phillip Alexander", "Male"); + gender.Add("Michelle Alexander", "Male"); + gender.Add("Daniel Blanco", "Male"); + gender.Add("Cory Booth", "Male"); + gender.Add("James Bailey", "Female"); + + loginID.Add("Sean Jacobson", "sean2"); + loginID.Add("Phyllis Allen", "phyllis0"); + loginID.Add("Marvin Allen", "marvin0"); + loginID.Add("Michael Allen", "michael10"); + loginID.Add("Cecil Allison", "cecil0"); + loginID.Add("Oscar Alpuerto", "oscar0"); + loginID.Add("Sandra Altamirano", "sandra1"); + loginID.Add("Selena Alvarad", "selena0"); + loginID.Add("Emilio Alvaro", "emilio0"); + loginID.Add("Maxwell Amland", "maxwell0"); + loginID.Add("Mae Anderson", "mae0"); + loginID.Add("Ramona Antrim", "ramona0"); + loginID.Add("Sabria Appelbaum", "sabria0"); + loginID.Add("Hannah Arakawa", "hannah0"); + loginID.Add("Kyley Arbelaez", "kyley0"); + loginID.Add("Tom Johnston", "tom1"); + loginID.Add("Thomas Armstrong", "thomas1"); + loginID.Add("John Arthur", "john6"); + loginID.Add("Chris Ashton", "chris3"); + loginID.Add("Teresa Atkinson", "teresa0"); + loginID.Add("John Ault", "john7"); + loginID.Add("Robert Avalos", "robert2"); + loginID.Add("Stephen Ayers", "stephen1"); + loginID.Add("Phillip Bacalzo", "phillip0"); + loginID.Add("Gustavo Achong", "gustavo0"); + loginID.Add("Catherine Abel", "catherine0"); + loginID.Add("Kim Abercrombie", "kim2"); + loginID.Add("Humberto Acevedo", "humberto0"); + loginID.Add("Pilar Ackerman", "pilar1"); + loginID.Add("Frances Adams", "frances0"); + loginID.Add("Margar Smith", "margaret0"); + loginID.Add("Carla Adams", "carla0"); + loginID.Add("Jay Adams", "jay1"); + loginID.Add("Ronald Adina", "ronald0"); + loginID.Add("Samuel Agcaoili", "samuel0"); + loginID.Add("James Aguilar", "james2"); + loginID.Add("Robert Ahlering", "robert1"); + loginID.Add("Francois Ferrier", "françois1"); + loginID.Add("Kim Akers", "kim3"); + loginID.Add("Lili Alameda", "lili0"); + loginID.Add("Amy Alberts", "amy1"); + loginID.Add("Anna Albright", "anna0"); + loginID.Add("Milton Albury", "milton0"); + loginID.Add("Paul Alcorn", "paul2"); + loginID.Add("Gregory Alderson", "gregory0"); + loginID.Add("J. Phillip Alexander", "jphillip0"); + loginID.Add("Michelle Alexander", "michelle0"); + loginID.Add("Daniel Blanco", "daniel0"); + loginID.Add("Cory Booth", "cory0"); + loginID.Add("James Bailey", "james3"); + + } + + string[] title = new string[] + { + "Assistant", + "Engineering", + "Designer", + "Manager", + + }; + + string[] employeeName = new string[] + { + "Sean Jacobson", + "Phyllis Allen", + "Marvin Allen", + "Michael Allen", + "Cecil Allison", + "Oscar Alpuerto", + "Sandra Altamirano", + "Selena Alvarad", + "Emilio Alvaro", + "Maxwell Amland", + "Mae Anderson", + "Ramona Antrim", + "Sabria Appelbaum", + "Hannah Arakawa", + "Kyley Arbelaez", + "Tom Johnston", + "Thomas Armstrong", + "John Arthur", + "Chris Ashton", + "Teresa Atkinson", + "John Ault", + "Robert Avalos", + "Stephen Ayers", + "Phillip Bacalzo", + "Gustavo Achong", + "Catherine Abel", + "Kim Abercrombie", + "Humberto Acevedo", + "Pilar Ackerman", + "Frances Adams", + "Margar Smith", + "Carla Adams", + "Jay Adams", + "Ronald Adina", + "Samuel Agcaoili", + "James Aguilar", + "Robert Ahlering", + "Francois Ferrier", + "Kim Akers", + "Lili Alameda", + "Amy Alberts", + "Anna Albright", + "Milton Albury", + "Paul Alcorn", + "Gregory Alderson", + "J. Phillip Alexander", + "Michelle Alexander", + "Daniel Blanco", + "Cory Booth", + "James Bailey" + }; + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool isdisposable) + { + if (Employees != null) + { + Employees.Clear(); + } + } + } +}