Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
vniehues committed Jul 27, 2022
2 parents 5c7ba9c + 8716091 commit fa8a472
Show file tree
Hide file tree
Showing 35 changed files with 605 additions and 69 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.x'
include-prerelease: false
dotnet-version: '6.0.300'
include-prerelease: true

- name: Install workload
run: dotnet workload install maui
Expand All @@ -25,7 +25,7 @@ jobs:
# Publish
- name: publish on version change
id: publish_nuget
uses: rohith/publish-nuget@v2
uses: alirezanet/publish-nuget@v3.0.4
with:
# Filepath of the project to be packaged, relative to root of repository
PROJECT_FILE_PATH: src/mavvm/mavvm.csproj
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ As you can see from the tables below, the configuration is minimal.
1. ShellContent does not need a route property anymore. It only needs the corresponding ViewModel and will create the Route and BindingContext by itself.
2. In `MauiProgram.cs` you need to change `builder.Build();` to `builder.BuildWithContainer();` to make sure that the container is registered and can be used by mavvm.
3. Also in `MauiProgram.cs` you need to add every Page in your App with the corresponding ViewModel using the `.AddRoute<TView, TViewModel>()` extension.
4. When your AppShell contains a tabbar you should add a route to the tabbar and register said route in your ViewModel with a custom attribute like this:
```
[SectionRoute("start")]
public class MainPageViewModel : ObservableObject
```




Expand Down Expand Up @@ -58,7 +64,7 @@ As you can see from the tables below, the configuration is minimal.
</TabBar>
</Shell>
```

</td>
<td>

Expand All @@ -72,11 +78,11 @@ As you can see from the tables below, the configuration is minimal.
Shell.FlyoutBehavior="Disabled"
x:Class="mavvmApp.AppShell">
<ShellItem>
<ShellItem Route="start">
<mavvm:MavvmShellContent ViewModel="{x:Type viewmodels:MainPageViewModel}">
</mavvm:MavvmShellContent>
</ShellItem>
<TabBar>
<TabBar Route="main">
<Tab Title="Second">
<mavvm:MavvmShellContent ViewModel="{x:Type viewmodels:SecondPageViewModel}">
</mavvm:MavvmShellContent>
Expand Down
6 changes: 4 additions & 2 deletions samples/mavvmApp/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using mavvmApp.ViewModels;
using System.Drawing;
using mavvmApp.ViewModels;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;
using Microsoft.Maui.Graphics;
using Application = Microsoft.Maui.Controls.Application;

namespace mavvmApp
Expand Down
16 changes: 6 additions & 10 deletions samples/mavvmApp/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@
<Shell
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:viewmodels="clr-namespace:mavvmApp.ViewModels" xmlns:mavvm="clr-namespace:mavvm;assembly=mavvm"
Shell.FlyoutBehavior="Disabled"

x:Class="mavvmApp.AppShell">
<ShellItem>
<mavvm:MavvmShellContent ViewModel="{x:Type viewmodels:MainPageViewModel}">
</mavvm:MavvmShellContent>
<ShellItem Route="start">
<mavvm:MavvmShellContent ViewModel="{x:Type viewmodels:MainPageViewModel}">
</mavvm:MavvmShellContent>
</ShellItem>
<TabBar>
<Tab Title="Second">
<TabBar x:Name="MainTabbar" Route="main">
<mavvm:MavvmShellContent ViewModel="{x:Type viewmodels:SecondPageViewModel}">
</mavvm:MavvmShellContent>
</Tab>
<Tab Title="Second 2">
<mavvm:MavvmShellContent ViewModel="{x:Type viewmodels:SecondTabPageViewModel}">
</mavvm:MavvmShellContent>
</Tab>
</TabBar>

<!--<Tab Title="Library" Icon="library.png">
<!--<Tab Title="Library" Icon="library.png">
<ShellContent ContentTemplate="{DataTemplate pages:LibraryPage}"/>
</Tab>
<Tab Title="Contact" Icon="contact.png">
Expand Down
13 changes: 9 additions & 4 deletions samples/mavvmApp/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
using Microsoft.Extensions.DependencyInjection;
using mavvm.Interfaces;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;

namespace mavvmApp
{
public partial class AppShell : Shell
public partial class AppShell : IShellWithTabBar
{
public AppShell()
{
InitializeComponent();
}
InitializeComponent();

TabBar = MainTabbar;
}

public TabBar TabBar { get; }
}
}
2 changes: 2 additions & 0 deletions samples/mavvmApp/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static MauiApp CreateMauiApp()
})
.AddRoute<MainPage, MainPageViewModel>()
.AddRoute<SecondPage, SecondPageViewModel>()
.AddRoute<ThirdPage, ThirdPageViewModel>()
.AddRoute<LastPage, LastPageViewModel>()
.AddRoute<SecondTabPage, SecondTabPageViewModel>();

builder.Services.AddSingleton<IConsoleService, ConsoleService>();
Expand Down
32 changes: 32 additions & 0 deletions samples/mavvmApp/ViewModels/LastPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using CommunityToolkit.Mvvm.Input;
using mavvm;

namespace mavvmApp.ViewModels
{
public partial class LastPageViewModel : BindableBase, INavigateToAware
{

[ICommand]
async void GoBack()
{
await BaseMethods.GoBack(parameters: new NavigationParameters {{"testKey3","testValue3" }});
}

[ICommand]
async void GoToSecondTabPage()
{
await BaseMethods.GoToViewModel<SecondTabPageViewModel>(parameters: new NavigationParameters { { "testKey4", "testValue4" } });
}

public void NavigatedTo(NavigationParameters parameters)
{
Console.WriteLine(parameters);
}

public LastPageViewModel()
{
}
}
}

11 changes: 7 additions & 4 deletions samples/mavvmApp/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
using mavvm;
using mavvm.Attibutes;
using Microsoft.Maui.Controls;

namespace mavvmApp.ViewModels
{
public class MainPageViewModel : BindableBase
[SectionRoute("start")]
public class MainPageViewModel : ObservableObject
{
string _title;
public string Title
Expand All @@ -17,15 +20,15 @@ public string Title
}
set
{
SetPropertyValue(ref _title, value);
SetProperty(ref _title, value);
}
}

private int _count;
public int Count
{
get { return this._count; }
set { this.SetPropertyValue(ref this._count, value); }
set { this.SetProperty(ref this._count, value); }
}

public Command CountUpCommand { get; set; }
Expand All @@ -45,7 +48,7 @@ void CountUp()

async void Navigate()
{
await BaseMethods.GoToViewModel<SecondPageViewModel>(true, new Dictionary<string, object>{ { "countParam", Count } });
await BaseMethods.GoToViewModel<LastPageViewModel>(intermediates: new []{typeof(SecondPageViewModel), typeof(ThirdPageViewModel)}, new NavigationParameters{ { "countParam", Count } });
}
}
}
Expand Down
32 changes: 28 additions & 4 deletions samples/mavvmApp/ViewModels/SecondPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Hosting;
using mavvm;
using mavvm.Interfaces;
using CommunityToolkit.Mvvm.Input;
using mavvm.Attibutes;

namespace mavvmApp.ViewModels
{
[SectionRoute("main")]
[QueryProperty(nameof(Count), "countParam")]
public class SecondPageViewModel : BindableBase, IPageAware
public partial class SecondPageViewModel : BindableBase, IPageAware, INavigationAware
{
[ICommand]
async void GoBack()
{
await BaseMethods.GoToViewModel<MainPageViewModel>();
}

[ICommand]
async void GoToThirdPage()
{
await BaseMethods.GoToViewModel<ThirdPageViewModel>(parameters: new NavigationParameters { { "testKey2", "testValue2" } });
}

string _title;
public string Title
{
Expand Down Expand Up @@ -58,12 +72,22 @@ async void LogCount()

public void Appearing()
{
_consoleService.Log("Appearing");
_consoleService.Log("SecondPage Appearing");
}

public void Disappearing()
{
_consoleService.Log("Disappearing");
_consoleService.Log("SecondPage Disappearing");
}

public void NavigatedBackTo(NavigationParameters parameters)
{
Console.WriteLine(parameters);
}

public void NavigatedTo(NavigationParameters parameters)
{
Console.WriteLine(parameters);
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion samples/mavvmApp/ViewModels/SecondTabPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using mavvm;
using mavvm.Attibutes;

namespace mavvmApp.ViewModels
{
public class SecondTabPageViewModel : BindableBase
[SectionRoute("main")]
public class SecondTabPageViewModel : BindableBase, INavigationAware
{
string _title;
public string Title
Expand All @@ -22,6 +24,14 @@ public SecondTabPageViewModel()
{
Title = "Second Tab";
}

public void NavigatedTo(NavigationParameters parameters)
{
}

public void NavigatedBackTo(NavigationParameters parameters)
{
}
}
}

32 changes: 32 additions & 0 deletions samples/mavvmApp/ViewModels/ThirdPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using CommunityToolkit.Mvvm.Input;
using mavvm;

namespace mavvmApp.ViewModels
{
public partial class ThirdPageViewModel : BindableBase, INavigateToAware
{

[ICommand]
async void GoBack()
{
await BaseMethods.GoBack();
}

[ICommand]
async void GoToLastPage()
{
await BaseMethods.GoToViewModel<LastPageViewModel>(parameters: new NavigationParameters { { "testKey2", "testValue2" } });
}

public void NavigatedTo(NavigationParameters parameters)
{
Console.WriteLine(parameters);
}

public ThirdPageViewModel()
{
}
}
}

43 changes: 43 additions & 0 deletions samples/mavvmApp/Views/LastPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewmodels="clr-namespace:mavvmApp.ViewModels"
x:Class="mavvmApp.Views.LastPage"
Title="{Binding Title}"
BackgroundColor="{DynamicResource SecondaryColor}"
Shell.PresentationMode="ModalAnimated">


<ScrollView>
<Grid RowSpacing="25" RowDefinitions="Auto,Auto,Auto,Auto,*"
Padding="{OnPlatform iOS='30,60,30,30', Default='30'}">

<Label
Text="Hello, World!"
Grid.Row="0"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="Center" />

<Label
Text="Welcome to .NET Multi-platform App UI"
Grid.Row="1"
SemanticProperties.HeadingLevel="Level1"
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
FontSize="18"
HorizontalOptions="Center" />

<Label
Text="{Binding Count, StringFormat='Current count: {0}'}"
Grid.Row="2"
FontSize="18"
FontAttributes="Bold"
HorizontalOptions="Center" />

<Button Text="GoBack"
Grid.Row="3" Command="{Binding GoBackCommand}"/>
<Button Text="Go to SecondTab"
Grid.Row="4" Command="{Binding GoToSecondTabPageCommand}"/>

</Grid>
</ScrollView>
</ContentPage>
14 changes: 14 additions & 0 deletions samples/mavvmApp/Views/LastPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using mavvmApp.ViewModels;
using Microsoft.Maui.Controls;

namespace mavvmApp.Views
{
public partial class LastPage : ContentPage
{
public LastPage()
{
InitializeComponent();
}
}
}
5 changes: 3 additions & 2 deletions samples/mavvmApp/Views/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewmodels="clr-namespace:mavvmApp.ViewModels"
x:Class="mavvmApp.Views.MainPage"
Title="{Binding Title}"
BackgroundColor="{DynamicResource SecondaryColor}">
BackgroundColor="{DynamicResource SecondaryColor}"
Shell.PresentationMode="Animated">

<ScrollView>
<Grid HorizontalOptions="FillAndExpand" RowSpacing="25" RowDefinitions="Auto,Auto,Auto,Auto,*"
Expand Down
Loading

0 comments on commit fa8a472

Please sign in to comment.