Skip to content

Commit 265b6e8

Browse files
committed
Updated code to latest MAUI changes
Fixed up nullable calls
1 parent aa4d633 commit 265b6e8

31 files changed

+917
-268
lines changed

sample/MauiSample/App.xaml.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using CoreBTS.Maui.ShieldMVVM.Navigation;
2-
using MauiSample.Features.Main;
2+
using MauiSample.Features.Splash;
33

44
namespace MauiSample;
55

@@ -12,15 +12,17 @@ public App(INavigationService navigation)
1212
_navigationService = navigation;
1313

1414
InitializeComponent();
15+
}
1516

16-
MainPage = new AppShell();
17+
protected override Window CreateWindow(IActivationState? activationState)
18+
{
19+
return new Window(new AppShell());
1720
}
1821

1922
protected override async void OnStart()
2023
{
2124
base.OnStart();
2225

23-
await _navigationService.NavigateToAsync<MainPageViewModel, MainPageArgs>(
24-
new MainPageArgs(new Random().Next(1, 10)), mustClearNavigationStack: true);
26+
await _navigationService.NavigateToAsync<SplashPageViewModel>(mustClearNavigationStack: true);
2527
}
2628
}

sample/MauiSample/AppShell.xaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
55
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
66
xmlns:local="clr-namespace:MauiSample"
7-
Shell.FlyoutBehavior="Disabled">
7+
Shell.FlyoutBehavior="Disabled"
8+
NavigationPage.HasNavigationBar="False"
9+
NavigationPage.HasBackButton="False"
10+
>
811

912
<ShellContent>
1013

14+
<Shell.BackButtonBehavior>
15+
<BackButtonBehavior IsVisible="False" IsEnabled="False" />
16+
</Shell.BackButtonBehavior>
17+
1118
<ContentPage>
1219
</ContentPage>
1320

sample/MauiSample/Features/About/AboutPage.xaml.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33

44
namespace MauiSample.Features.About;
55

6-
public partial class AboutPage : ContentPageBase<AboutPageViewModel>
6+
public partial class AboutPage(AboutPageViewModel viewModel) : ContentPageBase<AboutPageViewModel>(viewModel)
77
{
8-
public AboutPage(AboutPageViewModel viewModel) : base(viewModel)
9-
{
10-
}
11-
128
protected override void SetupBindings()
139
{
1410
Binder.WithControl(Counter)
@@ -25,7 +21,7 @@ protected override void SetupBindings()
2521
.For(c => c.BindCommand(), vm => vm.AddCommand);
2622

2723
Binder.WithControl(List)
28-
.ForTemplate(vm => vm.AboutItems, AboutCell.ItemTemplate)
24+
.ForTemplate(vm => vm.AboutItems!, AboutCell.ItemTemplate)
2925
.ForSingleSelection(vm => vm.SelectedCommand);
3026
}
3127
}

sample/MauiSample/Features/About/AboutPageViewModel.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ public AboutPageViewModel(INavigationService navigationService) : base(navigatio
1818

1919
public int Counter { get; protected set; }
2020

21-
[ObservableProperty]
22-
private ObservableCollection<AboutItem> _aboutItems;
21+
private ObservableCollection<AboutItem>? _aboutItems;
22+
public ObservableCollection<AboutItem>? AboutItems
23+
{
24+
get => _aboutItems;
25+
set => SetProperty(ref _aboutItems, value);
26+
}
2327

2428
public override void Prepare(AboutPageArgs parameters)
2529
{
@@ -28,13 +32,13 @@ public override void Prepare(AboutPageArgs parameters)
2832

2933
public override Task InitializeAsync(CancellationToken token = default)
3034
{
31-
AboutItems = new ObservableCollection<AboutItem>
32-
{
35+
AboutItems =
36+
[
3337
new() { Name = "Test1", Description = "Desc 1" },
3438
new() { Name = "Test2", Description = "Desc 2" },
3539
new() { Name = "Test3", Description = "Desc 3" },
3640
new() { Name = "Test4", Description = "Desc 4" },
37-
};
41+
];
3842

3943
return Task.CompletedTask;
4044
}
@@ -44,9 +48,9 @@ private async Task DoDoneCommand() =>
4448

4549
[RelayCommand]
4650
private void Add() =>
47-
AboutItems.Add(new() { Name = Guid.NewGuid().ToString(), Description = "Test" });
51+
AboutItems?.Add(new() { Name = Guid.NewGuid().ToString(), Description = "Test" });
4852

4953
[RelayCommand]
5054
private void Selected(AboutItem item) =>
51-
AboutItems.Add(item);
55+
AboutItems?.Add(item);
5256
}

sample/MauiSample/Features/About/Cells/AboutCell.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ public partial class AboutCell : ViewCellBase<AboutItem, AboutCell>
77
protected override void SetupBindings()
88
{
99
Binder.WithControls(Name)
10-
.For(c => c.BindText(), vm => vm.Name);
10+
.For(c => c.BindText(), vm => vm.Name, vm => vm.ConvertToNonNullString());
1111

1212
Binder.WithControls(Description)
13-
.For(c => c.BindText(), vm => vm.Description);
13+
.For(c => c.BindText(), vm => vm.Description, vm => vm.ConvertToNonNullString());
1414
}
1515
}

sample/MauiSample/Features/About/Cells/AboutItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
public class AboutItem
44
{
5-
public string Name { get; set; }
6-
public string Description { get; set; }
5+
public string? Name { get; set; }
6+
public string? Description { get; set; }
77
}

sample/MauiSample/Features/Main/Dialog/DialogPage.xaml.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
namespace MauiSample.Features.Main.Dialog;
22

33
[XamlCompilation(XamlCompilationOptions.Compile)]
4-
public partial class DialogPage : DialogPageBase<DialogPageViewModel>
4+
public partial class DialogPage(DialogPageViewModel viewModel) : DialogPageBase<DialogPageViewModel>(viewModel)
55
{
6-
public DialogPage(DialogPageViewModel viewModel) : base(viewModel)
7-
{
8-
}
9-
106
protected override void SetupBindings()
117
{
128
Binder.WithControl(MyLabel)

sample/MauiSample/Features/Main/Dialog/DialogPromptPageViewModel.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
using CommunityToolkit.Mvvm.ComponentModel;
2-
using CoreBTS.Maui.ShieldMVVM.Navigation;
1+
using CoreBTS.Maui.ShieldMVVM.Navigation;
32
using CoreBTS.Maui.ShieldMVVM.ViewModel;
43

54
namespace MauiSample.Features.Main.Dialog;
65

7-
public partial class DialogPromptPageViewModel : DialogViewModelBase<DialogPromptPageArg, DialogPromptPageResult>
6+
public partial class DialogPromptPageViewModel(INavigationService navigationService) : DialogViewModelBase<DialogPromptPageArg, DialogPromptPageResult>(navigationService)
87
{
9-
public DialogPromptPageViewModel(INavigationService navigationService) : base(navigationService)
8+
private int _counter;
9+
public int Counter
1010
{
11+
get => _counter;
12+
set => SetProperty(ref _counter, value);
1113
}
1214

13-
[ObservableProperty]
14-
private int _counter;
15-
1615
public virtual string MyLabel => "Counter Value";
1716

1817
public override Task SetResultAsync(CancellationToken token = default)

sample/MauiSample/Features/Main/MainPage.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
x:DataType="vm:MainPageViewModel"
99
>
1010

11-
<ScrollView>
12-
11+
<ScrollView VerticalOptions="Fill">
12+
1313
<VerticalStackLayout
1414
Spacing="25"
1515
Padding="30,0"
@@ -55,7 +55,7 @@
5555
x:Name="SecondaryLabel"
5656
/>
5757

58-
<HorizontalStackLayout>
58+
<HorizontalStackLayout >
5959

6060
<Button
6161
x:Name="AboutPageButton"
@@ -64,7 +64,7 @@
6464

6565
<Button
6666
x:Name="AboutAlternatePageButton"
67-
Text="About Alternate"
67+
Text="About Alt"
6868
/>
6969

7070
<Button

sample/MauiSample/Features/Main/MainPage.xaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ public partial class MainPage : ContentPageBase<MainPageViewModel>
44
{
55
public MainPage(MainPageViewModel viewModel) : base(viewModel)
66
{
7+
NavigationPage.SetHasBackButton(this, false);
8+
NavigationPage.SetHasNavigationBar(this, false);
79
}
810

911
protected override void SetupBindings()
@@ -16,7 +18,7 @@ protected override void SetupBindings()
1618
.For(c => c.BindText(), vm => vm.Counter, c => c.ConvertToString());
1719

1820
Binder.WithControl(SecondaryLabel)
19-
.For(c => c.BindText(), vm => vm.Secondary.MyLabel);
21+
.For(c => c.BindText(), vm => vm.Secondary.MyLabel, vm => vm.ConvertToNonNullString());
2022

2123
Binder.WithControl(AboutPageButton)
2224
.Once(c => c.BindClick(), vm => vm.AboutPageCommand);

0 commit comments

Comments
 (0)