Skip to content

Commit

Permalink
docs: Updating navigation docs to match latest template
Browse files Browse the repository at this point in the history
  • Loading branch information
eriklimakc committed May 31, 2024
1 parent d7caf86 commit 64bc9f4
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 143 deletions.
2 changes: 1 addition & 1 deletion doc/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This tutorial will walk you through how to create an Uno application with Uno.Ex

![Visual Studio - Configure project name and location](./Learn/images/configure-new-unoplatform-app.png)

* Choose a template preset to build your application
* Choose the **Recommended** preset to build your application

![Visual Studio - Configure your new project](./Learn/images/intro.png)

Expand Down
2 changes: 1 addition & 1 deletion doc/Learn/Authentication/HowTo-Authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ uid: Uno.Extensions.Authentication.HowToAuthentication
}
```

- Update the "Second" route in `App.xaml.host.cs` to specify that it depends on the "Main" route. This will make sure that even if the app navigates directly to the SecondPage, the MainPage will be added to the backstack.
- Update the "Second" route in `App.xaml.cs` to specify that it depends on the "Main" route. This will make sure that even if the app navigates directly to the SecondPage, the MainPage will be added to the backstack.

```csharp
routes
Expand Down
14 changes: 11 additions & 3 deletions doc/Learn/Navigation/Advanced/HowTo-AdvancedPageNavigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ When using navigation, you may not want to allow the current page to remain in t

Using backward/forward navigation in your app requires a degree of extra consideration. Users always expect the back/forward button to take them to a page that is still relevant, yet logically related to the current page and direction. This page contains several concise tutorials about how to implement navigation techniques that address these more advanced problems.

## Step-by-steps

> [!IMPORTANT]
> This guide assumes you used the template wizard or `dotnet new unoapp` to create your solution. If not, it is recommended that you follow the [Creating an application with Uno.Extensions article](xref:Uno.Extensions.HowToGettingStarted) for creating an application from the template.
> [!NOTE]
> This guide uses predefined code created by the Uno Template using the `Recommended` preset, however it uses the `Mvvm` approach for the examples instead of `MVUX` defined in the `Recommended` preset.
## Techniques

### Navigating to a Page and Clearing Back Stack
Expand Down Expand Up @@ -57,7 +65,7 @@ It is possible to navigate to a page and clear the back stack from codebehind us
```csharp
public async Task GoToSecondPage()
{
await _navigator.NavigateViewModelAsync<SecondViewModel>(this, qualifier: Qualifiers.ClearBackStack);
await _navigator.NavigateViewModelAsync<SecondViewModel>(this, qualifier: Qualifiers.ClearBackStack);
}
```

Expand All @@ -69,7 +77,7 @@ Another common scenario is to navigate to a page and then remove the current pag

#### From XAML

- Add a new `Page` to navigate to, `SamplePage.xaml`, in the UI (shared) project
- Add a new `Page` to navigate to, `SamplePage.xaml`

- In `SecondPage.xaml` add a `Button` with the following XAML, which does _not_ include a handler for the Click event

Expand All @@ -90,7 +98,7 @@ Another common scenario is to navigate to a page and then remove the current pag

#### From codebehind

- Add a new `Page` to navigate to, `SamplePage.xaml`, in the UI (shared) project
- Add a new `Page` to navigate to, `SamplePage.xaml`
- In `SecondPage.xaml` add a `Button` with the following XAML, which includes a handler for the Click event

```xml
Expand Down
22 changes: 14 additions & 8 deletions doc/Learn/Navigation/Advanced/HowTo-UseNavigationView.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Choosing the right control for your navigation needs is important, and one commo
> [!IMPORTANT]
> This guide assumes you used the template wizard or `dotnet new unoapp` to create your solution. If not, it is recommended that you follow the [Creating an application with Uno.Extensions article](xref:Uno.Extensions.HowToGettingStarted) for creating an application from the template.
> [!NOTE]
> This guide uses predefined code created by the Uno Template using the `Recommended` preset, however it uses the `Mvvm` approach for the examples instead of `MVUX` defined in the `Recommended` preset.
### 1. Add XAML namespace mapping

* Add the following namespace mapping to the root element of your XAML page:
Expand Down Expand Up @@ -218,21 +221,24 @@ Choosing the right control for your navigation needs is important, and one commo
private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
{
views.Register(
new ViewMap<ShellControl, ShellViewModel>(),
new ViewMap(ViewModel: typeof(ShellViewModel)),
new ViewMap<ProductsPage, ProductsViewModel>(),
new ViewMap<MainPage, MainViewModel>()
);

routes.Register(
new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
Nested: new RouteMap[]
{
Nested:
[
new RouteMap("Main", View: views.FindByViewModel<MainViewModel>(),
Nested: new RouteMap[]
{
new RouteMap("Products", View: views.FindByViewModel<ProductsViewModel>())
})
}));
Nested:
[
new RouteMap("Products", View: views.FindByViewModel<ProductsViewModel>())
]
)
]
)
);
}
```

Expand Down
23 changes: 16 additions & 7 deletions doc/Learn/Navigation/Advanced/HowTo-UseTabBar.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ var builder = this.CreateBuilder(args)

## Step-by-steps

> [!IMPORTANT]
> This guide assumes you used the template wizard or `dotnet new unoapp` to create your solution. If not, it is recommended that you follow the [Creating an application with Uno.Extensions article](xref:Uno.Extensions.HowToGettingStarted) for creating an application from the template.
> [!NOTE]
> This guide uses predefined code created by the Uno Template using the `Recommended` preset, however it uses the `Mvvm` approach for the examples instead of `MVUX` defined in the `Recommended` preset.
### 1. Add necessary XAML namespaces

* Update the `Page` element in `MainPage.xaml` to include XAML namespace mappings for Navigation and Uno Toolkit:
Expand Down Expand Up @@ -281,21 +287,24 @@ var builder = this.CreateBuilder(args)
private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
{
views.Register(
new ViewMap<ShellControl, ShellViewModel>(),
new ViewMap(ViewModel: typeof(ShellViewModel)),
new ViewMap<LoginPage, LoginViewModel>(),
new ViewMap<MainPage, MainViewModel>()
);
routes.Register(
new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
Nested: new RouteMap[]
{
Nested:
[
new RouteMap("Main", View: views.FindByViewModel<MainViewModel>(),
Nested: new RouteMap[]
{
Nested:
[
new RouteMap("Login", View: views.FindByViewModel<LoginViewModel>())
})
}));
]
)
]
)
);
}
```
Expand Down
60 changes: 32 additions & 28 deletions doc/Learn/Navigation/HowTo-DisplayItem.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ This topic walks through how to use Navigation to display the details of an item
> [!IMPORTANT]
> This guide assumes you used the template wizard or `dotnet new unoapp` to create your solution. If not, it is recommended that you follow the [Creating an application with Uno.Extensions article](xref:Uno.Extensions.HowToGettingStarted) for creating an application from the template.
> [!NOTE]
> This guide uses predefined code created by the Uno Template using the `Recommended` preset, however it uses the `Mvvm` approach for the examples instead of `MVUX` defined in the `Recommended` preset.
Often it is necessary to pass a data item from one page to another. This scenario will start with passing a newly created object along with the navigation request, and how the specified object can be accessed by the destination ViewModel.

### 1. Define the type of data to pass
Expand All @@ -20,10 +23,10 @@ Often it is necessary to pass a data item from one page to another. This scenari
public record Widget(string Name, double Weight);
```

- Change the `ViewMap` in `App.xaml.host.cs` that associates the `SecondPage` and `SecondViewModel`, to include a `DataMap` that references the `Widget` type.
- Change the `ViewMap` in `App.xaml.cs` that associates the `SecondPage` and `SecondViewModel`, to be a `DataViewMap` object that allows you to specify the `Widget` type.

```csharp
new ViewMap<SecondPage, SecondViewModel>(Data: new DataMap<Widget>())
new DataViewMap<SecondPage, SecondViewModel, Widget>()
```

### 2. Pass data when navigating
Expand All @@ -33,9 +36,9 @@ Often it is necessary to pass a data item from one page to another. This scenari
```csharp
public async Task GoToSecondPage()
{
var widget = new Widget("CrazySpinner", 34.0);
var widget = new Widget("CrazySpinner", 34.0);

await _navigator.NavigateViewModelAsync<SecondViewModel>(this, data: widget);
await _navigator.NavigateViewModelAsync<SecondViewModel>(this, data: widget);
}
```

Expand Down Expand Up @@ -67,7 +70,7 @@ Often it is necessary to pass a data item from one page to another. This scenari

### 4. Navigating with data

- Because there's a mapping between the `Widget` and the `SecondViewModel` (in the `ViewMap` defined in `App.xaml.host.cs`), an alternative way to navigate is by calling the `NavigateDataAsync` and specifying the data object to pass in the navigation request. The type of the data object will be used to revolve which route to navigate to
- Because there's a mapping between the `Widget` and the `SecondViewModel` (in the `ViewMap` defined in `App.xaml.cs`), an alternative way to navigate is by calling the `NavigateDataAsync` and specifying the data object to pass in the navigation request. The type of the data object will be used to revolve which route to navigate to

```csharp
await _navigator.NavigateDataAsync(this, data: widget);
Expand All @@ -80,11 +83,11 @@ A common application scenario is to present a list of items, for example present
- Add a `Widgets` property to your `MainViewModel`

```csharp
public Widget[] Widgets { get; } = new[]
{
public Widget[] Widgets { get; } =
[
new Widget("NormalSpinner", 5.0),
new Widget("HeavySpinner",50.0)
};
new Widget("HeavySpinner", 50.0)
];
```

- Update `MainPage.xaml` to replace the `Button` with a `ListView` which has the `ItemsSource` property data bound to the `Widgets` property. The `Navigation.Request` property defines the route that will be navigated to when an item in the `ListView` is selected.
Expand Down Expand Up @@ -126,11 +129,11 @@ If you have a `ListView` that has items of different types, the navigation route
- Change the `Widgets` property in `MainViewModel` to include an array of different types of widgets.

```csharp
public Widget[] Widgets { get; } = new Widget[]
{
public Widget[] Widgets { get; } =
[
new BasicWidget("NormalSpinner", 5.0),
new AdvancedWidget("HeavySpinner",50.0)
};
new AdvancedWidget("HeavySpinner", 50.0)
];
```

- Clone the `SecondPage.xaml` and `SecondPage.xaml.cs` files, and rename the files to `ThirdPage.xaml` and `ThirdPage.xaml.cs` respectively. Make sure you also change the class name in both files from `SecondPage` to `ThirdPage`, as well as the `Content` property of the `NavigationBar` to read "Third Page".
Expand Down Expand Up @@ -159,27 +162,28 @@ If you have a `ListView` that has items of different types, the navigation route
}
```

- Add a `ViewMap` and `RouteMap` for `ThirdPage` and `ThirdViewModel`, specifying the `AdvancedWidget` in the `DataMap`. Also update DataMap for `SecondViewModel` to be `BasicWidget` instead of `Widget`
- Add a `DataViewMap` and `RouteMap` for `ThirdPage` and `ThirdViewModel`, specifying the `AdvancedWidget`. Also update `DataViewMap` for `SecondViewModel` to be `BasicWidget` instead of `Widget`

```csharp
private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
{
views.Register(
new ViewMap<ShellControl, ShellViewModel>(),
new ViewMap(ViewModel: typeof(ShellViewModel)),
new ViewMap<MainPage, MainViewModel>(),
new ViewMap<SecondPage, SecondViewModel>(Data: new DataMap<BasicWidget>()),
new ViewMap<ThirdPage, ThirdViewModel>(Data: new DataMap<AdvancedWidget>())
);

routes
.Register(
new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
Nested: new RouteMap[]
{
new RouteMap("Main", View: views.FindByViewModel<MainViewModel>()),
new RouteMap("Second", View: views.FindByViewModel<SecondViewModel>()),
new RouteMap("Third", View: views.FindByViewModel<ThirdViewModel>()),
}));
new DataViewMap<SecondPage, SecondViewModel, BasicWidget>(),
new DataViewMap<ThirdPage, ThirdViewModel, AdvancedWidget>()
);

routes.Register(
new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
Nested:
[
new ("Main", View: views.FindByViewModel<MainViewModel>()),
new ("Second", View: views.FindByViewModel<SecondViewModel>()),
new ("Third", View: views.FindByViewModel<ThirdViewModel>()),
]
)
);
}
```

Expand Down
Loading

0 comments on commit 64bc9f4

Please sign in to comment.