Skip to content

Commit

Permalink
Merge pull request #99 from egvijayanand/working
Browse files Browse the repository at this point in the history
Partial Properties - MVVM Toolkit
  • Loading branch information
egvijayanand authored Nov 8, 2024
2 parents 04cca83 + 19177fe commit 8ffcb5e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Made available in the `src\NET_8\` directory:
|`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|
|`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|
|`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|
|`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>|
|`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>|
|`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>|

### .NET MAUI 9 Samples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>

<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>DateCalculator</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.*" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.*-*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel;
#define FIELDS
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DateCalculator.Extensions;
using DateCalculator.Helpers;
Expand All @@ -10,6 +11,7 @@ namespace DateCalculator.ViewModels
{
public partial class DateViewModel : BaseViewModel
{
#if FIELDS
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(StartDate1))]
//[TypeConverter(typeof(DateTimeOffsetConverter))]
Expand Down Expand Up @@ -53,6 +55,51 @@ public partial class DateViewModel : BaseViewModel

[ObservableProperty]
private bool addMode = true;
#else
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(StartDate1))]
//[TypeConverter(typeof(DateTimeOffsetConverter))]
public partial DateTimeOffset StartDate { get; set; } = DateTime.Today;

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(EndDate1))]
//[TypeConverter(typeof(DateTimeOffsetConverter))]
public partial DateTimeOffset EndDate { get; set; } = DateTime.Today;

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(DiffModeInverse))]
public partial bool DiffMode { get; set; } = true;

[ObservableProperty]
public partial int SelectedYear { get; set; }

[ObservableProperty]
public partial int SelectedMonth { get; set; }

[ObservableProperty]
public partial int SelectedWeek { get; set; }

[ObservableProperty]
public partial int SelectedDay { get; set; }

[ObservableProperty]
public partial string ResultCaption { get; set; } = "Difference";

[ObservableProperty]
public partial string DiffResult { get; set; } = string.Empty;

[ObservableProperty]
public partial string DiffInDays { get; set; } = string.Empty;

[ObservableProperty]
public partial int SelectedOption { get; set; }

[ObservableProperty]
public partial string? SelectedMode { get; set; }

[ObservableProperty]
public partial bool AddMode { get; set; } = true;
#endif

public DateViewModel()
{
Expand Down Expand Up @@ -88,7 +135,7 @@ public DateTime EndDate1

public bool DiffModeInverse => !DiffMode;

// While using classic MVVM
#region Classic-MVVM
/*
public DateTimeOffset StartDate
{
Expand Down Expand Up @@ -189,6 +236,7 @@ public string DiffInDays
public ICommand DiffCommand => new Command(FindTheDate);
*/
#endregion

partial void OnDiffModeChanged(bool value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RootNamespace>DateCalculator.WinUI</RootNamespace>

<!-- App Options -->
Expand Down

0 comments on commit 8ffcb5e

Please sign in to comment.