Skip to content

Commit

Permalink
Merge pull request #39 from egvijayanand/working
Browse files Browse the repository at this point in the history
Updated MVVM NuGet package to latest preview version (v8.0.0-preview4)
  • Loading branch information
egvijayanand authored Jun 7, 2022
2 parents c5d4b97 + 633177b commit e353cac
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>DateCalculator</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview3" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview4" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace VijayAnand.Toolkit.ObjectModel
public partial class BaseViewModel : ObservableValidator, IDisposable
{
[ObservableProperty]
[AlsoNotifyChangeFor(nameof(IsNotBusy))]
[NotifyPropertyChangedFor(nameof(IsNotBusy))]
private bool isBusy;

[ObservableProperty]
Expand All @@ -32,7 +32,7 @@ public partial class BaseViewModel : ObservableValidator, IDisposable
private bool isValid = true;

[ObservableProperty]
private List<string?> errors = new();
private List<string> errors = new();

public BaseViewModel()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class DateViewModel : BaseViewModel
private DateTime endDate;

[ObservableProperty]
[AlsoNotifyChangeFor(nameof(DiffModeInverse))]
[NotifyPropertyChangedFor(nameof(DiffModeInverse))]
private bool diffMode;

[ObservableProperty]
Expand Down Expand Up @@ -177,7 +177,7 @@ partial void OnDiffModeChanged(bool value)

partial void OnSelectedDayChanged(int value) => FindTheDate();

[ICommand]
[RelayCommand]
private void DateDiff() => FindTheDate();

private void FindTheDate()
Expand Down
7 changes: 4 additions & 3 deletions src/MauiAppCS/MauiAppCS/App.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
namespace MauiAppCS
using VijayAnand.MauiToolkit.Services;

namespace MauiAppCS
{
public partial class App : Application
{
public App()
{
Build();

MainPage = new MainPage();
MainPage = AppService.GetService<MainPage>();
}

private void Build()
Expand Down
2 changes: 1 addition & 1 deletion src/MauiAppCS/MauiAppCS/Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
global using static CommunityToolkit.Maui.Markup.GridRowsColumns;
// Static
global using static Microsoft.Maui.Graphics.Colors;
global using static VijayAnand.MauiToolkit.Markup.Utility;
global using static VijayAnand.MauiToolkit.Markup.Utility;
39 changes: 20 additions & 19 deletions src/MauiAppCS/MauiAppCS/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
{
public partial class MainPage : ContentPage
{
int count;
Label counter;

public MainPage()
public MainPage(MainViewModel viewModel)
{
Build();
BindingContext = viewModel;
}

private void Build()
Expand All @@ -23,38 +21,41 @@ private void Build()
{
Style = AppResource<Style>("MauiLabel"),
Text = "Hello, World!",
}.FontSize(32).CenterHorizontal().SemanticHeading(SemanticHeadingLevel.Level1),
}.FontSize(32)
.CenterHorizontal()
.SemanticHeading(SemanticHeadingLevel.Level1),
new Label()
{
Style = AppResource<Style>("MauiLabel"),
Text = "Welcome to .NET Multi-platform App UI",
}.FontSize(18).CenterHorizontal().SemanticDesc("Welcome to dot net Multi platform App U I").SemanticHeading(SemanticHeadingLevel.Level1),
}.FontSize(18)
.CenterHorizontal()
.SemanticDesc("Welcome to dot net Multi platform App U I")
.SemanticHeading(SemanticHeadingLevel.Level1),
new Label()
{
FontAttributes = FontAttributes.Bold,
Style = AppResource<Style>("MauiLabel"),
Text = "Current count: 0",
}.FontSize(18).CenterHorizontal().Assign(out counter),
}.FontSize(18)
.CenterHorizontal()
.Bind(nameof(MainViewModel.Counter)),
new Button()
{
Style = AppResource<Style>("PrimaryAction"),
Text = "Click me",
}.CenterHorizontal().Invoke(btn => btn.Clicked += OnCounterClicked).SemanticHint("Counts the number of times you click"),
Text = "Click Me",
}.CenterHorizontal()
.BindCommand(nameof(MainViewModel.ClickCommand))
.SemanticHint("Counts the number of times you click"),
new Image()
{
Source = "dotnet_bot.png",
}.Height(310).Width(250).CenterHorizontal().SemanticDesc("Cute dot net bot waving hi to you!"),
}.Height(310)
.Width(250)
.CenterHorizontal()
.SemanticDesc("Cute dot net bot waving hi to you!"),
}
}.Padding(30)
};
}

private void OnCounterClicked(object? sender, EventArgs e)
{
count++;
counter.Text = $"Current count: {count}";

SemanticScreenReader.Announce(counter.Text);
}
}
}
27 changes: 27 additions & 0 deletions src/MauiAppCS/MauiAppCS/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace MauiAppCS
{
public partial class MainViewModel : ObservableObject
{
private int count;
private readonly ISemanticScreenReader semanticScreenReader;

public MainViewModel(ISemanticScreenReader semanticScreenReader)
{
this.semanticScreenReader = semanticScreenReader;
}

[ObservableProperty]
private string counter = "Current count: 0";

[RelayCommand]
private void OnClick()
{
count++;
Counter = $"Current count: {count}";
semanticScreenReader.Announce(Counter);
}
}
}
2 changes: 1 addition & 1 deletion src/MauiAppCS/MauiAppCS/MauiAppCS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="1.0.0"/>
<PackageReference Include="VijayAnand.MauiToolkit" Version="1.0.0"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview3"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview4"/>
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion src/MauiAppCS/MauiAppCS/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public static MauiApp CreateMauiApp()
fonts.AddFont("OpenSans-SemiBold.ttf", "OpenSansSemiBold");
});

builder.Services.AddSingleton<MainPage>();
builder.Services.AddSingleton<MainViewModel>();
builder.Services.AddSingleton(SemanticScreenReader.Default);
return builder.Build();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview3" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview4" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace VijayAnand.Toolkit.ObjectModel
public partial class BaseViewModel : ObservableValidator, IDisposable
{
[ObservableProperty]
[AlsoNotifyChangeFor(nameof(IsNotBusy))]
[NotifyPropertyChangedFor(nameof(IsNotBusy))]
private bool isBusy;

[ObservableProperty]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class DateViewModel : BaseViewModel
private DateTime endDate;

[ObservableProperty]
[AlsoNotifyChangeFor(nameof(DiffModeInverse))]
[NotifyPropertyChangedFor(nameof(DiffModeInverse))]
private bool diffMode;

[ObservableProperty]
Expand Down Expand Up @@ -177,7 +177,7 @@ partial void OnDiffModeChanged(bool value)

partial void OnSelectedDayChanged(int value) => FindTheDate();

[ICommand]
[RelayCommand]
private void DateDiff() => FindTheDate();

private void FindTheDate()
Expand Down

0 comments on commit e353cac

Please sign in to comment.