Skip to content

Commit 5025940

Browse files
committed
Bind to Data Examples added
1 parent 0812088 commit 5025940

File tree

100 files changed

+4533
-0
lines changed

Some content is hidden

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

100 files changed

+4533
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<None Remove="Microsoft.EntityFrameworkCore.InMemory" />
11+
<None Remove="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" />
12+
<None Remove="Models\" />
13+
<None Remove="Data\" />
14+
<None Remove="Microsoft.EntityFrameworkCore.SqlServer" />
15+
</ItemGroup>
16+
<ItemGroup>
17+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.0" />
18+
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="7.0.0" />
19+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
20+
</ItemGroup>
21+
<ItemGroup>
22+
<Folder Include="Models\" />
23+
<Folder Include="Data\" />
24+
</ItemGroup>
25+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using System;
4+
using System.Linq;
5+
using ASPDataBaseServer.Model;
6+
using ASPDataBaseServer.Data;
7+
using System.Diagnostics;
8+
using System.Collections.ObjectModel;
9+
using System.Text.Json;
10+
11+
namespace ASPDataBaseServer.Model;
12+
public class CustomerData
13+
{
14+
public CustomerData()
15+
{
16+
GenerateEmployees();
17+
}
18+
public ObservableCollection<Customer> CustomerList { get; private set; }
19+
public static void GenerateEmployees()
20+
{
21+
var context = new CustomersContext();
22+
List<Customer> result = new List<Customer>();
23+
24+
string fileName = "Data/customers.json";
25+
string jsonString = File.ReadAllText(fileName);
26+
result = JsonSerializer.Deserialize<List<Customer>>(jsonString);
27+
context.Customers.AddRange(result);
28+
context.SaveChanges();
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore;
3+
using ASPDataBaseServer.Model;
4+
5+
namespace ASPDataBaseServer.Data
6+
{
7+
public class CustomersContext : DbContext
8+
{
9+
static readonly DbContextOptions<CustomersContext> options = new DbContextOptionsBuilder<CustomersContext>()
10+
.UseInMemoryDatabase(databaseName: "Test")
11+
.Options;
12+
13+
public CustomersContext() : base(options) { }
14+
15+
public DbSet<Customer> Customers => Set<Customer>();
16+
}
17+
}
18+

CS/ASPDataBaseServer/ASPDataBaseServer/Data/customers.json

+1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.ComponentModel.DataAnnotations.Schema;
3+
using System.Text.Json.Serialization;
4+
5+
namespace ASPDataBaseServer.Model {
6+
public class Customer {
7+
[JsonPropertyName("id")] public int ID { get; set; }
8+
[JsonPropertyName("name")] public string Name { get; set; }
9+
[JsonPropertyName("birthDate")] public DateTime BirthDate { get; set; }
10+
[JsonPropertyName("favoriteStore")] public string FavoriteStore { get; set; }
11+
[JsonPropertyName("phone")] public string Phone { get; set; }
12+
[JsonPropertyName("registered")] public bool Registered { get; set; }
13+
[JsonPropertyName("photo")] public string Photo { get; set; }
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Text.Json;
3+
using ASPDataBaseServer;
4+
using ASPDataBaseServer.Data;
5+
using ASPDataBaseServer.Model;
6+
using Microsoft.EntityFrameworkCore;
7+
8+
static void GenerateEmployees() {
9+
var context = new CustomersContext();
10+
List<Customer> result = new List<Customer>();
11+
12+
string fileName = "Data/customers.json";
13+
string jsonString = File.ReadAllText(fileName);
14+
result = JsonSerializer.Deserialize<List<Customer>>(jsonString);
15+
context.Customers.AddRange(result);
16+
context.SaveChanges();
17+
}
18+
19+
var builder = WebApplication.CreateBuilder(args);
20+
builder.Services.AddDbContext<CustomersContext>(opt => opt.UseInMemoryDatabase("Customers"));
21+
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
22+
23+
CustomersContext _Context;
24+
_Context = new CustomersContext();
25+
var app = builder.Build();
26+
GenerateEmployees();
27+
28+
app.MapGet("/customers", async (CustomersContext db) => {
29+
return await _Context.Customers.ToListAsync();
30+
});
31+
32+
app.Run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 25.0.1705.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASPDataBaseServer", "ASPDataBaseServer\ASPDataBaseServer.csproj", "{A1465CEA-07FE-416E-B048-522DB267C3F7}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MauiDataGridView_GetFromASPServer", "MauiDataGridView_GetFromASPServer\MauiDataGridView_GetFromASPServer.csproj", "{AFEE5FEE-A90E-422A-B06F-624C074909F3}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{A1465CEA-07FE-416E-B048-522DB267C3F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{A1465CEA-07FE-416E-B048-522DB267C3F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{A1465CEA-07FE-416E-B048-522DB267C3F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{A1465CEA-07FE-416E-B048-522DB267C3F7}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{AFEE5FEE-A90E-422A-B06F-624C074909F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{AFEE5FEE-A90E-422A-B06F-624C074909F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{AFEE5FEE-A90E-422A-B06F-624C074909F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{AFEE5FEE-A90E-422A-B06F-624C074909F3}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {66880371-BB41-4853-9526-C157C72AFC56}
30+
EndGlobalSection
31+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
3+
xmlns:windows="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;assembly=Microsoft.Maui.Controls"
4+
xmlns:local="clr-namespace:MauiDataGridView_GetFromASPServer"
5+
x:Class="MauiDataGridView_GetFromASPServer.App"
6+
windows:Application.ImageDirectory="Assets">
7+
<Application.Resources>
8+
<ResourceDictionary>
9+
10+
<Color x:Key="Primary">#512BD4</Color>
11+
<Color x:Key="PrimaryLight">#deedff</Color>
12+
<Color x:Key="NormalText">Black</Color>
13+
<Color x:Key="NormalHeaderText">#404144</Color>
14+
<Color x:Key="NormalLightText">Black</Color>
15+
<Color x:Key="DrawerTitleTextColor">White</Color>
16+
<Style TargetType="NavigationPage">
17+
<Setter Property="BarBackgroundColor" Value="{StaticResource Primary}"/>
18+
<Setter Property="BarTextColor" Value="{StaticResource DrawerTitleTextColor}"/>
19+
</Style>
20+
<Style x:Key="PrimaryButton" TargetType="Button">
21+
<Setter Property="BackgroundColor" Value="{StaticResource Primary}"/>
22+
<Setter Property="TextColor" Value="White"/>
23+
</Style>
24+
<Style TargetType="Label">
25+
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource NormalText}, Dark={StaticResource DrawerTitleTextColor}}" />
26+
</Style>
27+
28+
</ResourceDictionary>
29+
</Application.Resources>
30+
</Application>
31+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace MauiDataGridView_GetFromASPServer;
2+
3+
public partial class App : Application {
4+
public App() {
5+
InitializeComponent();
6+
7+
MainPage = new MainPage();
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Welcome to DevExpress Components for .NET MAUI! Here are a few tips to help you get started with your new application.
2+
3+
DevExpress NuGet Feed
4+
---------------------
5+
6+
DevExpress Components for .NET MAUI are free-of-charge. To learn more about our free offer and reserve your free copy,
7+
please visit the following webpage: https://www.devexpress.com/xamarin-free/
8+
9+
IMPORTANT: You MUST register your personal NuGet package source for the solution to build correctly.
10+
After you reserved your free copy, you can use the following page to obtain a NuGet Feed URL: https://nuget.devexpress.com/
11+
12+
If you are unfamiliar with NuGet packages, please review the following
13+
help topic (Install DevExpress Controls Using NuGet Packages): https://docs.devexpress.com/GeneralInformation/115912/
14+
15+
QuickStart Guide
16+
----------------
17+
18+
See the following topic to learn more about DevExpress Components for .NET MAUI: https://docs.devexpress.com/MAUI
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
3+
xmlns:dxg="clr-namespace:DevExpress.Maui.DataGrid;assembly=DevExpress.Maui.DataGrid"
4+
xmlns:dxe="clr-namespace:DevExpress.Maui.Editors;assembly=DevExpress.Maui.Editors"
5+
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
6+
ios:Page.UseSafeArea="False"
7+
x:Class="MauiDataGridView_GetFromASPServer.MainPage">
8+
<Grid>
9+
<dxg:DataGridView x:Name="datagrid"
10+
EditorShowMode="Never" IsReadOnly="False" VerticalLineThickness="1" ShowGroupedColumns="True">
11+
<dxg:DataGridView.CellAppearance>
12+
<dxg:CellAppearance BorderColor="Transparent" HorizontalLineThickness="0"/>
13+
</dxg:DataGridView.CellAppearance>
14+
<dxg:DataGridView.GroupRowAppearance>
15+
<dxg:GroupRowAppearance BackgroundColor="Transparent"/>
16+
</dxg:DataGridView.GroupRowAppearance>
17+
<dxg:DataGridView.Columns>
18+
<dxg:TemplateColumn MinWidth="310" Caption="Customers" FieldName="Name" IsGrouped="true" GroupInterval="Alphabetical" SortOrder="Ascending">
19+
<dxg:TemplateColumn.DisplayTemplate>
20+
<DataTemplate>
21+
<Grid VerticalOptions="Center" Padding="15, 5, 0, 10" RowDefinitions="*" ColumnDefinitions="Auto, 3*, *">
22+
<Border
23+
x:Name="photoContainer"
24+
WidthRequest="60"
25+
HeightRequest="60"
26+
Margin="0,0,15,0"
27+
Grid.Column="0"
28+
VerticalOptions="Center">
29+
<Border.Clip>
30+
<EllipseGeometry RadiusX="30" RadiusY="30" Center="30,30"/>
31+
</Border.Clip>
32+
<Image Source="{Binding Item.Image}" Grid.Column="0" WidthRequest="92" HeightRequest="92" Margin="0,0,5,0" HorizontalOptions="Center" VerticalOptions="Start"/>
33+
</Border>
34+
<VerticalStackLayout Grid.Row="0" Grid.Column="1" Padding="0" Margin="0" Opacity="0.7">
35+
<Label Text="{Binding Item.Name}" FontSize="16" FontAttributes="Bold"/>
36+
<HorizontalStackLayout Margin="0,4,0,0" >
37+
<Label Text="📞" Padding="0,0,5,0" FontSize="10" VerticalTextAlignment="Center" />
38+
<Label Text="{Binding Item.Phone}" FontSize="14"/>
39+
</HorizontalStackLayout>
40+
<HorizontalStackLayout>
41+
<Label Text="📆" Padding="0,0,5,0" FontSize="10" VerticalTextAlignment="Center" />
42+
<Label Text="{Binding Item.BirthDate, StringFormat='{0:MMMM dd, yyyy}'}" FontSize="14" Margin="0,0,0,0"/>
43+
</HorizontalStackLayout>
44+
<HorizontalStackLayout>
45+
<Label Text="🏢" Padding="0,0,5,0" FontSize="10" VerticalTextAlignment="Center" />
46+
<Label Text="{Binding Item.FavoriteStore}" FontSize="12" Margin="0,0,0,0"/>
47+
</HorizontalStackLayout>
48+
</VerticalStackLayout>
49+
</Grid>
50+
</DataTemplate>
51+
</dxg:TemplateColumn.DisplayTemplate>
52+
</dxg:TemplateColumn>
53+
</dxg:DataGridView.Columns>
54+
</dxg:DataGridView>
55+
</Grid>
56+
57+
58+
</ContentPage>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Text.Json;
2+
using MauiDataGridView_GetFromASPServer.Model;
3+
4+
namespace MauiDataGridView_GetFromASPServer;
5+
6+
public partial class MainPage : ContentPage
7+
{
8+
public static string BaseAddress = DeviceInfo.Platform == DevicePlatform.Android ? "https://10.0.2.2:7208" : "https://localhost:7208";
9+
public MainPage()
10+
{
11+
InitializeComponent();
12+
LoadDataAsync();
13+
}
14+
15+
async void LoadDataAsync() {
16+
datagrid.ItemsSource = await GetCustomers();
17+
}
18+
async Task<List<Customer>> GetCustomers()
19+
{
20+
HttpClientHandler insecureHandler = GetInsecureHandler();
21+
HttpClient httpClient = new HttpClient(insecureHandler);
22+
var result = await httpClient.GetAsync($"{BaseAddress}/customers");
23+
var json = await result.Content.ReadAsStringAsync();
24+
return JsonSerializer.Deserialize<List<Customer>>(json);
25+
}
26+
HttpClientHandler GetInsecureHandler()
27+
{
28+
HttpClientHandler handler = new HttpClientHandler();
29+
handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
30+
{
31+
if (cert.Issuer.Equals("CN=localhost"))
32+
return true;
33+
return errors == System.Net.Security.SslPolicyErrors.None;
34+
};
35+
return handler;
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net7.0-android;net7.0-ios</TargetFrameworks>
5+
<OutputType>Exe</OutputType>
6+
<UseMaui>true</UseMaui>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<SingleProject>true</SingleProject>
9+
<RootNamespace>MauiDataGridView_GetFromASPServer</RootNamespace>
10+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
11+
12+
<!-- Display name -->
13+
<ApplicationTitle>Local Server Data Grid</ApplicationTitle>
14+
15+
<!-- App Identifier -->
16+
<ApplicationId>com.companyname.MauiDataGridView_GetFromASPServer12</ApplicationId>
17+
<ApplicationIdGuid>EA902676-FBB4-4AC2-B556-A47C8DC7651E</ApplicationIdGuid>
18+
<!-- Versions -->
19+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
20+
<ApplicationVersion>1</ApplicationVersion>
21+
22+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
23+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">23.0</SupportedOSPlatformVersion>
24+
</PropertyGroup>
25+
26+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-ios|AnyCPU'">
27+
<CreatePackage>false</CreatePackage>
28+
</PropertyGroup>
29+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0-ios|AnyCPU'">
30+
<CreatePackage>false</CreatePackage>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<!-- App Icon -->
34+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#6750A4" />
35+
36+
<!-- Splash Screen -->
37+
38+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#6750A4" BaseSize="128,128" />
39+
40+
<!-- Images -->
41+
<MauiImage Include="Resources\Images\*" />
42+
43+
<!-- Custom Fonts -->
44+
<MauiFont Include="Resources\Fonts\*" />
45+
</ItemGroup>
46+
47+
<ItemGroup>
48+
<PackageReference Include="DevExpress.Maui.Editors" Version="22.2.3" />
49+
<PackageReference Include="DevExpress.Maui.Core" Version="22.2.3" />
50+
<PackageReference Include="DevExpress.Maui.DataGrid" Version="22.2.3" />
51+
</ItemGroup>
52+
</Project>

0 commit comments

Comments
 (0)