Skip to content

Commit 8ffcb5e

Browse files
authored
Merge pull request #99 from egvijayanand/working
Partial Properties - MVVM Toolkit
2 parents 04cca83 + 19177fe commit 8ffcb5e

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Made available in the `src\NET_8\` directory:
1515
|`EmbeddedWindows`|.NET MAUI Page embedded in a Native WinUI 3 App <br /> Refer to this [.NET MAUI - Native Embedding](https://egvijayanand.in/2024/02/29/dotnet-maui-native-embedding/) article for working with this sample|
1616
|`MapsApp`|.NET MAUI Maps embedded in a Native WinUI 3 App <br /> Refer to this [.NET MAUI Community Toolkit Maps in WinUI 3 App](https://egvijayanand.in/2024/03/07/dotnet-maui-community-toolkit-maps-in-winui-3-app/) article for working with this sample|
1717
|`ThemedApp`|Sample app for .NET MAUI App Theming <br /> Refer to this [.NET MAUI - App Theming](https://egvijayanand.in/2024/07/03/dotnet-maui-developer-tips-app-theming/) article for further details|
18-
|`DateCalculator`|<ul><li>MVVM Sample</li><li>Xamarin Forms and .NET MAUI in a single solution</li><li>WPF and WinUI projects to illustrate the reuse of ViewModels across UI frameworks</li><li>WinForms project to illustrate the reuse of ViewModels across non-XAML UI framework too</li><li>Shared business logic as a separate library project</li><li>ViewModels implemented with [CommunityToolkit.Mvvm](https://www.nuget.org/packages/CommunityToolkit.Mvvm) (aka Microsoft MVVM Toolkit) NuGet package</li></ul>|
18+
|`DateCalculator`|<ul><li>MVVM Sample</li><li>Xamarin Forms and .NET MAUI in a single solution</li><li>WPF and WinUI projects to illustrate the reuse of ViewModels across UI frameworks</li><li>WinForms project to illustrate the reuse of ViewModels across non-XAML UI framework too</li><li>Shared business logic as a separate library project</li><li>ViewModels implemented with [CommunityToolkit.Mvvm](https://www.nuget.org/packages/CommunityToolkit.Mvvm) (aka Microsoft MVVM Toolkit) NuGet package</li><li>Consult the [MVVM - Made Easy](https://egvijayanand.in/category/mvvm/made-easy/) series of articles for guidance on working with this sample solution.</li></ul>|
1919
|`UnifiedDateCalculator`|<ul><li>Shared class library sample</li><li>UI, ViewModel, Model, and Business logic all from shared project</li><li>Head projects serve as an app container</li><li>Both Xamarin.Forms and .NET MAUI UI definition from a single project - `DateCalculator.UI`</li><li>ViewModels implemented with [CommunityToolkit.Mvvm](https://www.nuget.org/packages/CommunityToolkit.Mvvm) (aka Microsoft MVVM Toolkit) NuGet package</li></ul>|
2020

2121
### .NET MAUI 9 Samples

src/NET_8/DateCalculator/DateCalculator.Shared/DateCalculator.Shared.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
55

66
<Nullable>enable</Nullable>
7-
<LangVersion>latest</LangVersion>
7+
<LangVersion>preview</LangVersion>
88
<ImplicitUsings>enable</ImplicitUsings>
99
<RootNamespace>DateCalculator</RootNamespace>
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.*" />
13+
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.*-*" />
1414
</ItemGroup>
1515

1616
</Project>

src/NET_8/DateCalculator/DateCalculator.Shared/ViewModels/DateViewModel.cs

+50-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CommunityToolkit.Mvvm.ComponentModel;
1+
#define FIELDS
2+
using CommunityToolkit.Mvvm.ComponentModel;
23
using CommunityToolkit.Mvvm.Input;
34
using DateCalculator.Extensions;
45
using DateCalculator.Helpers;
@@ -10,6 +11,7 @@ namespace DateCalculator.ViewModels
1011
{
1112
public partial class DateViewModel : BaseViewModel
1213
{
14+
#if FIELDS
1315
[ObservableProperty]
1416
[NotifyPropertyChangedFor(nameof(StartDate1))]
1517
//[TypeConverter(typeof(DateTimeOffsetConverter))]
@@ -53,6 +55,51 @@ public partial class DateViewModel : BaseViewModel
5355

5456
[ObservableProperty]
5557
private bool addMode = true;
58+
#else
59+
[ObservableProperty]
60+
[NotifyPropertyChangedFor(nameof(StartDate1))]
61+
//[TypeConverter(typeof(DateTimeOffsetConverter))]
62+
public partial DateTimeOffset StartDate { get; set; } = DateTime.Today;
63+
64+
[ObservableProperty]
65+
[NotifyPropertyChangedFor(nameof(EndDate1))]
66+
//[TypeConverter(typeof(DateTimeOffsetConverter))]
67+
public partial DateTimeOffset EndDate { get; set; } = DateTime.Today;
68+
69+
[ObservableProperty]
70+
[NotifyPropertyChangedFor(nameof(DiffModeInverse))]
71+
public partial bool DiffMode { get; set; } = true;
72+
73+
[ObservableProperty]
74+
public partial int SelectedYear { get; set; }
75+
76+
[ObservableProperty]
77+
public partial int SelectedMonth { get; set; }
78+
79+
[ObservableProperty]
80+
public partial int SelectedWeek { get; set; }
81+
82+
[ObservableProperty]
83+
public partial int SelectedDay { get; set; }
84+
85+
[ObservableProperty]
86+
public partial string ResultCaption { get; set; } = "Difference";
87+
88+
[ObservableProperty]
89+
public partial string DiffResult { get; set; } = string.Empty;
90+
91+
[ObservableProperty]
92+
public partial string DiffInDays { get; set; } = string.Empty;
93+
94+
[ObservableProperty]
95+
public partial int SelectedOption { get; set; }
96+
97+
[ObservableProperty]
98+
public partial string? SelectedMode { get; set; }
99+
100+
[ObservableProperty]
101+
public partial bool AddMode { get; set; } = true;
102+
#endif
56103

57104
public DateViewModel()
58105
{
@@ -88,7 +135,7 @@ public DateTime EndDate1
88135

89136
public bool DiffModeInverse => !DiffMode;
90137

91-
// While using classic MVVM
138+
#region Classic-MVVM
92139
/*
93140
public DateTimeOffset StartDate
94141
{
@@ -189,6 +236,7 @@ public string DiffInDays
189236
190237
public ICommand DiffCommand => new Command(FindTheDate);
191238
*/
239+
#endregion
192240

193241
partial void OnDiffModeChanged(bool value)
194242
{

src/NET_8/DateCalculator/DateCalculator.WinUI/DateCalculator.WinUI.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<Nullable>enable</Nullable>
1616
<LangVersion>latest</LangVersion>
1717
<ImplicitUsings>enable</ImplicitUsings>
18+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1819
<RootNamespace>DateCalculator.WinUI</RootNamespace>
1920

2021
<!-- App Options -->

0 commit comments

Comments
 (0)