Skip to content

Commit

Permalink
Edits.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbritch committed Oct 18, 2024
1 parent d381d84 commit 21bb43a
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions docs/platform-integration/native-embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,26 +362,11 @@ Before creating a native app that consumes .NET MAUI controls, you should add a
> [!IMPORTANT]
> Ensure you set the `$(TargetFramework)` build property, not the`$(TargetFrameworks)` build property.

01. In the `MauiProgram` class, create a `CreateMauiApp` overload that accepts an optional `Action<MauiAppBuilder>` argument:
01. In the `MauiProgram` class, modify the `CreateMauiApp` method to accept a `TApp` generic argument, and accept an optional `Action<MauiAppBuilder>` argument that's invoked before the method returns. In addition, change the call from `UseMauiApp<App>` to `UseMauiEmbeddedApp<TApp>`:

```csharp
public static class MauiProgram
{
// Create a MauiApp using the default application.
public static MauiApp CreateMauiApp(Action<MauiAppBuilder>? additional = null) =>
CreateMauiApp<App>(additional);

...
}
```

01. In the `MauiProgram` class, modify the existing `CreateMauiApp` method to accept a `TApp` generic argument, and accept an optional `Action<MauiAppBuilder>` argument that's invoked before the method returns. In addition, change the call from `UseMauiApp<App>` to `UseMauiEmbeddedApp<TApp>`:

```csharp
public static class MauiProgram
{
...

// Create a MauiApp using the specified application.
public static MauiApp CreateMauiApp<TApp>(Action<MauiAppBuilder>? additional = null) where TApp : App
{
Expand All @@ -405,6 +390,19 @@ Before creating a native app that consumes .NET MAUI controls, you should add a
}
```

01. In the `MauiProgram` class, add a `CreateMauiApp` overload that accepts an optional `Action<MauiAppBuilder>` argument:

```csharp
public static class MauiProgram
{
...

// Create a MauiApp using the default application.
public static MauiApp CreateMauiApp(Action<MauiAppBuilder>? additional = null) =>
CreateMauiApp<App>(additional);
}
```

You should then add your required .NET MAUI UI to the project, including any dependencies and resources, and ensure that the project builds correctly.

::: moniker-end
Expand Down Expand Up @@ -723,7 +721,7 @@ Embedding can be performed in an app context or a window context, but for maximu

### App context

Native embedding can be performed in an app context, where the native app has no knowledge of a parent window. With this approach, native embedding initialization requires you to:
Native embedding can be performed in an app context, where the native app has no knowledge of a window. With this approach, native embedding initialization requires you to:

- Create a <xref:Microsoft.Maui.Hosting.MauiApp> object.
- Create a <xref:Microsoft.Maui.MauiContext> object from the <xref:Microsoft.Maui.Hosting.MauiApp> object. The <xref:Microsoft.Maui.MauiContext> object will be used to obtain a native view from the .NET MAUI view.
Expand All @@ -737,7 +735,7 @@ var context = new MauiContext(mauiApp.Services); // Activity also needs passing

A .NET MAUI view can then be created and converted to a native view with the `ToPlatformEmbedded` extension method, which requires the <xref:Microsoft.Maui.MauiContext> object as an argument.

This approach is suitable for scenarios where a native app just needs to embed a simple .NET MAUI UI, and doesn't require access to all .NET MAUI features. The disadvantage of this approach is that tooling such as hot reload, and some .NET MAUI features, won't work.
This approach is suitable for scenarios where a native app needs to embed a simple .NET MAUI UI, but doesn't require access to all .NET MAUI features. The disadvantage of this approach is that tooling such as hot reload, and some .NET MAUI features, won't work.

[!INCLUDE [Create MauiApp as a shared, static instance](includes/static-mauiapp.md)]

Expand Down Expand Up @@ -908,7 +906,7 @@ In this example, the <xref:Microsoft.Maui.Hosting.MauiApp> object is created as

### Window context

Native embedding can be performed in an window context, where the native app has knowledge of a window. In some scenarios, .NET MAUI views require access to a window to work correctly. For example, adaptive triggers require access to a view's window, and if there is no window they don't work.
Native embedding can be performed in a window context, where the native app has knowledge of a window. In some scenarios, .NET MAUI views require access to a window to work correctly. For example, adaptive triggers require access to a view's window, and if there is no window they don't work.

With this approach, native embedding initialization requires you to:

Expand Down Expand Up @@ -1016,7 +1014,7 @@ public class SceneDelegate : UIResponder, IUIWindowSceneDelegate
Window.MakeKeyAndVisible();
}

/// ...
...
}
```

Expand Down

0 comments on commit 21bb43a

Please sign in to comment.