Skip to content

Commit 405dc13

Browse files
Merge pull request #1 from SyncfusionExamples/860344-ConverterInDataForm
860344-Programmatic converter in the .NET MAUI DataForm
2 parents daeb9cd + 95c6d97 commit 405dc13

39 files changed

+1146
-2
lines changed
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.0.31611.283
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProgrammaticConverter", "ProgrammaticConverter\ProgrammaticConverter.csproj", "{1C336B8F-1BF4-4887-A67B-1516E1BC1CD0}"
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+
{1C336B8F-1BF4-4887-A67B-1516E1BC1CD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{1C336B8F-1BF4-4887-A67B-1516E1BC1CD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{1C336B8F-1BF4-4887-A67B-1516E1BC1CD0}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{1C336B8F-1BF4-4887-A67B-1516E1BC1CD0}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{1C336B8F-1BF4-4887-A67B-1516E1BC1CD0}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{1C336B8F-1BF4-4887-A67B-1516E1BC1CD0}.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 = {61F7FB11-1E47-470C-91E2-47F8143E1572}
26+
EndGlobalSection
27+
EndGlobal
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:ProgrammaticConverter"
5+
x:Class="ProgrammaticConverter.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>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace ProgrammaticConverter;
2+
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new MainPage();
10+
}
11+
}
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+
<Shell
3+
x:Class="ProgrammaticConverter.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:ProgrammaticConverter"
7+
Shell.FlyoutBehavior="Disabled">
8+
9+
<ShellContent
10+
Title="Home"
11+
ContentTemplate="{DataTemplate local:MainPage}"
12+
Route="MainPage" />
13+
14+
</Shell>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ProgrammaticConverter;
2+
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace ProgrammaticConverter
9+
{
10+
public class Converter : IValueConverter
11+
{
12+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
13+
{
14+
if (value == null || string.IsNullOrEmpty(value.ToString()))
15+
{
16+
return DateTime.Now;
17+
}
18+
else
19+
{
20+
DateTime dateTime;
21+
DateTime.TryParse((string)value, out dateTime);
22+
return dateTime;
23+
}
24+
}
25+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
26+
{
27+
return value.ToString();
28+
}
29+
}
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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:dataForm="clr-namespace:Syncfusion.Maui.DataForm;assembly=Syncfusion.Maui.DataForm"
5+
xmlns:local="clr-namespace:ProgrammaticConverter;assembly=ProgrammaticConverter"
6+
x:Class="ProgrammaticConverter.MainPage">
7+
8+
<ContentPage.BindingContext>
9+
<local:DataFormViewModel/>
10+
</ContentPage.BindingContext>
11+
<dataForm:SfDataForm x:Name="dataForm"
12+
DataObject="{Binding DataFormModel}"/>
13+
</ContentPage>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ProgrammaticConverter;
2+
3+
public partial class MainPage : ContentPage
4+
{
5+
public MainPage()
6+
{
7+
InitializeComponent();
8+
}
9+
}
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 ProgrammaticConverter;
5+
6+
public static class MauiProgram
7+
{
8+
public static MauiApp CreateMauiApp()
9+
{
10+
var builder = MauiApp.CreateBuilder();
11+
builder
12+
.UseMauiApp<App>()
13+
.ConfigureSyncfusionCore()
14+
.ConfigureFonts(fonts =>
15+
{
16+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
17+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
18+
});
19+
20+
#if DEBUG
21+
builder.Logging.AddDebug();
22+
#endif
23+
24+
return builder.Build();
25+
}
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Syncfusion.Maui.DataForm;
2+
using System.ComponentModel.DataAnnotations;
3+
4+
namespace ProgrammaticConverter
5+
{
6+
public class DataFormModel
7+
{
8+
public string FirstName { get; set; }
9+
public string LastName { get; set; }
10+
11+
[DataFormValueConverter(typeof(Converter))]
12+
[DataType(DataType.Date)]
13+
public string DateTime { get; set; }
14+
public string Email { get; set; }
15+
public string CourseCompleted { get; set; }
16+
}
17+
}

0 commit comments

Comments
 (0)