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

Commit

Permalink
Merge pull request #9 from vniehues/develop
Browse files Browse the repository at this point in the history
update to RC3, fix for AmbiguousRouteException, new interfaces & methods for navigation, testing
  • Loading branch information
vniehues committed May 11, 2022
2 parents a59b532 + 78bee5b commit c7b910f
Show file tree
Hide file tree
Showing 22 changed files with 225 additions and 43 deletions.
6 changes: 4 additions & 2 deletions samples/mavvmApp/App.xaml.cs
@@ -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
6 changes: 3 additions & 3 deletions samples/mavvmApp/AppShell.xaml
Expand Up @@ -2,18 +2,18 @@
<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>
<TabBar>
<Tab Title="Second">
<Tab Title="Second" Route="firstTab">
<mavvm:MavvmShellContent ViewModel="{x:Type viewmodels:SecondPageViewModel}">
</mavvm:MavvmShellContent>
</Tab>
<Tab Title="Second 2">
<Tab Title="Second 2" Route="secondTab">
<mavvm:MavvmShellContent ViewModel="{x:Type viewmodels:SecondTabPageViewModel}">
</mavvm:MavvmShellContent>
</Tab>
Expand Down
1 change: 1 addition & 0 deletions samples/mavvmApp/MauiProgram.cs
Expand Up @@ -24,6 +24,7 @@ public static MauiApp CreateMauiApp()
})
.AddRoute<MainPage, MainPageViewModel>()
.AddRoute<SecondPage, SecondPageViewModel>()
.AddRoute<ThirdPage, ThirdPageViewModel>()
.AddRoute<SecondTabPage, SecondTabPageViewModel>();

builder.Services.AddSingleton<IConsoleService, ConsoleService>();
Expand Down
2 changes: 1 addition & 1 deletion samples/mavvmApp/ViewModels/MainPageViewModel.cs
Expand Up @@ -46,7 +46,7 @@ void CountUp()

async void Navigate()
{
await BaseMethods.GoToViewModel<SecondPageViewModel>(true, new Dictionary<string, object>{ { "countParam", Count } });
await BaseMethods.GoToViewModel<SecondPageViewModel>(false, new NavigationParameters{ { "countParam", Count } });
}
}
}
Expand Down
26 changes: 24 additions & 2 deletions samples/mavvmApp/ViewModels/SecondPageViewModel.cs
Expand Up @@ -3,13 +3,25 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Hosting;
using mavvm;
using mavvm.Interfaces;
using CommunityToolkit.Mvvm.Input;

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

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

string _title;
public string Title
{
Expand Down Expand Up @@ -65,6 +77,16 @@ public void Disappearing()
{
_consoleService.Log("Disappearing");
}

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

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

26 changes: 26 additions & 0 deletions samples/mavvmApp/ViewModels/ThirdPageViewModel.cs
@@ -0,0 +1,26 @@
using System;
using CommunityToolkit.Mvvm.Input;
using mavvm;

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

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

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

public ThirdPageViewModel()
{
}
}
}

5 changes: 3 additions & 2 deletions samples/mavvmApp/Views/MainPage.xaml
@@ -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
1 change: 0 additions & 1 deletion samples/mavvmApp/Views/MainPage.xaml.cs
@@ -1,6 +1,5 @@
using System;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Essentials;

namespace mavvmApp.Views
{
Expand Down
27 changes: 8 additions & 19 deletions samples/mavvmApp/Views/SecondPage.xaml
@@ -1,13 +1,14 @@
<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.SecondPage"
Title="{Binding Title}"
BackgroundColor="{DynamicResource SecondaryColor}">
BackgroundColor="{DynamicResource SecondaryColor}"
Shell.PresentationMode="Animated">


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

<Label
Expand All @@ -25,22 +26,10 @@
FontSize="18"
HorizontalOptions="Center" />

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

<Button Text="Log + Alert"
Grid.Row="2" Command="{Binding LogCountCommand}"/>

<Image Grid.Row="4"
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
WidthRequest="250"
HeightRequest="310"
HorizontalOptions="Center" />
<Button Text="GoBack"
Grid.Row="3" Command="{Binding GoBackCommand}"/>
<Button Text="Go to ThirdPage"
Grid.Row="4" Command="{Binding GoToThirdPageCommand}"/>

</Grid>
</ScrollView>
Expand Down
1 change: 0 additions & 1 deletion samples/mavvmApp/Views/SecondPage.xaml.cs
@@ -1,7 +1,6 @@
using System;
using mavvmApp.ViewModels;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Essentials;

namespace mavvmApp.Views
{
Expand Down
48 changes: 48 additions & 0 deletions samples/mavvmApp/Views/ThirdPage.xaml
@@ -0,0 +1,48 @@
<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.ThirdPage"
Title="{Binding Title}"
BackgroundColor="{DynamicResource SecondaryColor}"
Shell.PresentationMode="Animated">


<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="2" Command="{Binding GoBackCommand}"/>

<Image Grid.Row="4"
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
WidthRequest="250"
HeightRequest="310"
HorizontalOptions="Center" />

</Grid>
</ScrollView>
</ContentPage>
14 changes: 14 additions & 0 deletions samples/mavvmApp/Views/ThirdPage.xaml.cs
@@ -0,0 +1,14 @@
using System;
using mavvmApp.ViewModels;
using Microsoft.Maui.Controls;

namespace mavvmApp.Views
{
public partial class ThirdPage : ContentPage
{
public ThirdPage()
{
InitializeComponent();
}
}
}
14 changes: 13 additions & 1 deletion samples/mavvmApp/mavvmApp.csproj
Expand Up @@ -55,9 +55,21 @@
</ItemGroup>
<ItemGroup>
<None Remove="CommunityToolkit.Mvvm" />
<None Remove="Microsoft.Maui.Dependencies" />
<None Remove="Microsoft.Maui.Extensions" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview3" />
<PackageReference Include="Microsoft.Maui.Dependencies" Version="6.0.300-rc.3.5667" />
<PackageReference Include="Microsoft.Maui.Extensions" Version="6.0.300-rc.3.5667" />
</ItemGroup>
<ItemGroup>
<MauiXaml Condition=" '$(EnableDefaultXamlItems)' == 'true' " Update="Views\SecondPage %28Kopie%29.xaml">
<SubType>Designer</SubType>
</MauiXaml>
<MauiXaml Condition=" '$(EnableDefaultXamlItems)' == 'true' " Update="Views\ThirdPage.xaml">
<SubType>Designer</SubType>
</MauiXaml>
</ItemGroup>
<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
<OutputType>WinExe</OutputType>
Expand Down
7 changes: 6 additions & 1 deletion src/mavvm/Customs/MavvmShellContent.cs
Expand Up @@ -18,10 +18,15 @@ static void ViewModelChanged(BindableObject bindable, object oldValue, object ne
{
var shellcontent = bindable as MavvmShellContent;

shellcontent.Route = (newValue as Type).Name;
shellcontent.SetContentTemplate();
}

public MavvmShellContent()
{
SetContentTemplate();
}

void SetContentTemplate()
{
ContentTemplate = new DataTemplate(() => Routing.GetOrCreateContent(ViewModel.Name));
}
Expand Down
13 changes: 13 additions & 0 deletions src/mavvm/Customs/NavigationParameters.cs
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;

namespace mavvm
{
public class NavigationParameters : Dictionary<string,object>
{
public NavigationParameters()
{
}
}
}

1 change: 0 additions & 1 deletion src/mavvm/Factories/MavvmResolveRouteFactory.cs
@@ -1,6 +1,5 @@
using System;
using System.ComponentModel;
using mavvm.Interfaces;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Controls;

Expand Down
9 changes: 9 additions & 0 deletions src/mavvm/Interfaces/INavigateBackToAware.cs
@@ -0,0 +1,9 @@
using System;
namespace mavvm
{
public interface INavigateBackToAware
{
void NavigatedBackTo(NavigationParameters parameters);
}
}

9 changes: 9 additions & 0 deletions src/mavvm/Interfaces/INavigateToAware.cs
@@ -0,0 +1,9 @@
using System;
namespace mavvm
{
public interface INavigateToAware
{
void NavigatedTo(NavigationParameters parameters);
}
}

8 changes: 8 additions & 0 deletions src/mavvm/Interfaces/INavigationAware.cs
@@ -0,0 +1,8 @@
using System;
namespace mavvm
{
public interface INavigationAware : INavigateToAware, INavigateBackToAware
{
}
}

2 changes: 1 addition & 1 deletion src/mavvm/Interfaces/IPageAware.cs
@@ -1,5 +1,5 @@
using System;
namespace mavvm.Interfaces
namespace mavvm
{
public interface IPageAware
{
Expand Down

0 comments on commit c7b910f

Please sign in to comment.