Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: single project changes #2325

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 64 additions & 20 deletions doc/Learn/Maui/ThirdParty-MauiCommunityToolkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,64 @@ The controls from MauiCommunityToolkit can be used in an Uno Platform applicatio

An existing sample app that showcases the controls is available [here](https://github.com/unoplatform/Uno.Samples/tree/master/UI/MauiEmbedding/MauiCommunityToolkitApp).

> [!NOTE]
> MauiCommunityToolkitApp SDK for .NET is currently only compatible with Windows, Android, iOS, and Mac Catalyst when used with Uno Platform.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> MauiCommunityToolkitApp SDK for .NET is currently only compatible with Windows, Android, iOS, and Mac Catalyst when used with Uno Platform.
> .NET Maui Community Toolkit is currently only compatible with Windows, Android, iOS, and Mac Catalyst when used with the Uno Platform.


## Getting Started

1. Create a new application using the `unoapp` template, enabling .NET MAUI Embedding. In this case, we're going to use the Blank template (`-preset blank`) and include .NET MAUI Embedding support (`-maui`).

```dotnetcli
dotnet new unoapp -preset blank -maui -o MauiEmbeddingApp
dotnet new unoapp -preset blank -maui -o MauiCommunityToolkitApp
```
### [Visual Studio](#tab/vs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> [!NOTE]
> If you don't have the **Uno Platform Extension for Visual Studio** installed, follow [these instructions](xref:Uno.GetStarted.vs2022).

- Launch **Visual Studio** and click on **Create new project** on the Start Window. Alternatively, if you're already in Visual Studio, click **New, Project** from the **File** menu.

- Type `Uno Platform` in the search box

- Click **Uno Platform App**, then **Next**

- Name the project `MauiCommunityToolkitApp` and click **Create**

At this point you'll enter the **Uno Platform Template Wizard**, giving you options to customize the generated application.

- Select **Blank** in **Presets** selection

- Select the **Platforms** tab and unselect **Desktop** and **Web Assembly** platforms

- Select the **Features** tab and click on **.NET MAUI Embedding**

Click **Create** to complete the wizard

1. Add a reference to the [CommunityToolkit.Maui NuGet package](https://www.nuget.org/packages/CommunityToolkit.Maui) to the MauiEmbeddingApp.MauiControls project.
The template will create a solution with a single cross-platform project, named `MauiCommunityToolkitApp`, ready to run.

1. In the `AppBuilderExtensions` class, on `MauiEmbeddingApp.MauiControls` project, update the `UseMauiControls` extension method to call the `UseMauiCommunityToolkit` method.
For more information on all the template options, see [Using the Uno Platform Template](xref:Uno.GettingStarted.UsingWizard).

### [Command Line](#tab/cli)

> [!NOTE]
> If you don't have the **Uno Platform dotnet new templates** installed, follow [dotnet new templates for Uno Platform](xref:Uno.GetStarted.dotnet-new).
Kunal22shah marked this conversation as resolved.
Show resolved Hide resolved
Create a new application using the `unoapp` template, enabling .NET MAUI Embedding. In this case, we're going to use the Blank template (`-preset blank`) and include .NET MAUI Embedding support (`-maui`).

```bash
dotnet new unoapp -preset blank -maui -platforms "android" -platforms "ios" -platforms "maccatalyst" -platforms "windows" -o MauiCommunityToolkitApp
```

This will create a new folder called **MauiCommunityToolkitApp** containing the new application.

---

1. Add a reference to the [CommunityToolkitApp.Maui NuGet package](https://www.nuget.org/packages/CommunityToolkit.Maui) to the MauiCommunityToolkitApp.MauiControls project.

1. In the `AppBuilderExtensions` class, on `MauiCommunityToolkitApp.MauiControls` project, update the `UseMauiControls` extension method to call the `UseMauiCommunityToolkit` method.

```cs
using CommunityToolkit.Maui;

namespace MauiEmbeddingApp;
namespace MauiCommunityToolkitApp;

public static class AppBuilderExtensions
{
Expand All @@ -33,22 +75,22 @@ An existing sample app that showcases the controls is available [here](https://g
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
fonts.AddFont("MauiEmbeddingApp/Assets/Fonts/OpenSansRegular.ttf", "OpenSansRegular");
fonts.AddFont("MauiEmbeddingApp/Assets/Fonts/OpenSansSemibold.ttf", "OpenSansSemibold");
fonts.AddFont("Assets/Fonts/OpenSansRegular.ttf", "OpenSansRegular");
fonts.AddFont("Assets/Fonts/OpenSansSemibold.ttf", "OpenSansSemibold");
});
}
```
Kunal22shah marked this conversation as resolved.
Show resolved Hide resolved

## Adding DrawingView

1. Update the EmbeddedControl.xaml in the `MauiEmbedding.MauiControls` project with the following XAML that includes the `DrawingView` control
1. Update the EmbeddedControl.xaml in the `MauiCommunityToolkitApp.MauiControls` project with the following XAML that includes the `DrawingView` control

```xml
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Class="MauiEmbeddingApp.MauiControls.EmbeddedControl"
x:Class="MauiCommunityToolkitApp.MauiControls.EmbeddedControl"
HorizontalOptions="Fill"
VerticalOptions="Fill">
<toolkit:DrawingView IsMultiLineModeEnabled="{Binding IsMultiLineModeEnabled}"
Expand All @@ -64,7 +106,7 @@ An existing sample app that showcases the controls is available [here](https://g
1. Update the EmbeddedControl.xaml.cs with the following code.

```cs
namespace MauiEmbeddingApp.MauiControls;
namespace MauiCommunityToolkitApp.MauiControls;

public partial class EmbeddedControl : ContentView
{
Expand All @@ -75,10 +117,10 @@ An existing sample app that showcases the controls is available [here](https://g
}
```

1. Now let's create the controls that will control the `DrawingView.IsMultiLineModeEnabled` and `DrawingView.ShouldClearOnFinish` properties. Update the MainPage.xaml in the `MauiEmbeddingApp` project with the following xaml:
1. Now let's create the controls that will control the `DrawingView.IsMultiLineModeEnabled` and `DrawingView.ShouldClearOnFinish` properties. Update the MainPage.xaml in the `MauiCommunityToolkitApp` project with the following xaml:

```xml
<Page x:Class="MauiEmbeddingApp.MainPage"
<Page x:Class="MauiCommunityToolkitApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -99,18 +141,18 @@ An existing sample app that showcases the controls is available [here](https://g
IsOn="{Binding IsMultiLineModeEnabled, Mode=TwoWay}" />
</StackPanel>

<embed:MauiHost xmlns:controls="using:MauiEmbeddingApp.MauiControls"
<embed:MauiHost xmlns:controls="using:MauiCommunityToolkitApp.MauiControls"
xmlns:embed="using:Uno.Extensions.Maui"
Grid.Row="1"
Source="controls:EmbeddedControl" />
</Grid>
</Page>
```

1. It's time to create the ViewModel that will hold the properties that will be data bound to the `DrawingView` control. On `MauiEmbeddingApp` project, create a new folder called `ViewModels` and add a new class called `MainViewModel`. This class will have the following code:
1. It's time to create the ViewModel that will hold the properties that will be data bound to the `DrawingView` control. On `MauiCommunityToolkitApp` project, create a new folder called `ViewModels` and add a new class called `MainViewModel`. This class will have the following code:

```cs
namespace MauiEmbeddingApp.ViewModels;
```cs
namespace MauiCommunityToolkitApp.ViewModels;

partial class MainViewModel : ObservableObject
{
Expand All @@ -122,15 +164,15 @@ An existing sample app that showcases the controls is available [here](https://g
}
```

1. The `MainViewModel` uses the `ObservableObject` base class that comes from the `CommunityToolkit.MVVM` NuGet package. This significantly reduces the amount of boilerplate code required. Add a reference to the [CommunityToolkit.Mvvm NuGet package](https://www.nuget.org/packages/CommunityToolkit.Mvvm) to the MauiEmbeddingApp project.
1. The `MainViewModel` uses the `ObservableObject` base class that comes from the `CommunityToolkit.MVVM` NuGet package. This significantly reduces the amount of boilerplate code required. Add a reference to the [CommunityToolkit.Mvvm NuGet package](https://www.nuget.org/packages/CommunityToolkit.Mvvm) to the MauiCommunityToolkitApp project.

1. The final step is to add the `MainViewModel` as the `DataContext` of the `Page` in the `MainPage.xaml` file. Here's how the final xaml should look.

```xml
<Page x:Class="MauiEmbeddingApp.MainPage"
<Page x:Class="MauiCommunityToolkitApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MauiEmbeddingApp.ViewModels"
xmlns:local="using:MauiCommunityToolkitApp.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Expand All @@ -152,7 +194,7 @@ An existing sample app that showcases the controls is available [here](https://g
IsOn="{Binding IsMultiLineModeEnabled, Mode=TwoWay}" />
</StackPanel>

<embed:MauiHost xmlns:controls="using:MauiEmbeddingApp.MauiControls"
<embed:MauiHost xmlns:controls="using:MauiCommunityToolkitApp.MauiControls"
xmlns:embed="using:Uno.Extensions.Maui"
Grid.Row="1"
Source="controls:EmbeddedControl" />
Expand All @@ -162,7 +204,9 @@ An existing sample app that showcases the controls is available [here](https://g

1. Now the project is good to go! Press F5 and you should see the `DrawingView` control working as expected. And tweaking the `ToggleSwitch` controls should change the `DrawingView` behavior.

## App Render Output
For more detailed instructions specific to each platform, refer to the [Debug the App](xref:Uno.GettingStarted.CreateAnApp.VS2022#debug-the-app) documentation.

**App Render Output**

- **Android:**
- ![Android CommunityToolkit](Assets/Screenshots/Android/CommunityToolkit.png)
Expand Down
Loading