Skip to content

Commit

Permalink
Merge pull request #93 from egvijayanand/working
Browse files Browse the repository at this point in the history
MapsApp Embedded project updated to .NET 9 Preview 7
  • Loading branch information
egvijayanand authored Sep 4, 2024
2 parents 905ee65 + 99f6fca commit b13ba52
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 30 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ Made available in the `src\NET_9\` directory:

|Solution Title|Description|
|:---:|:---|
|`EmbeddedAndroid`|.NET MAUI Page embedded in a .NET 9 for Android App, targeting .NET 9 <br /> Refer to this [article](https://egvijayanand.in/2024/02/29/dotnet-maui-native-embedding/) for working with this sample|
|`EmbeddediOS`|.NET MAUI Page embedded in a .NET 9 for iOS App, targeting .NET 9 <br /> Refer to this [article](https://egvijayanand.in/2024/02/29/dotnet-maui-native-embedding/) for working with this sample|
|`EmbeddedWindows`|.NET MAUI Page embedded in a Native WinUI 3 App, targeting .NET 9 <br /> Refer to this [article](https://egvijayanand.in/2024/02/29/dotnet-maui-native-embedding/) for working with this sample|
|`MapsApp`|.NET MAUI Maps embedded in a Native WinUI 3 App, targeting .NET 9 <br /> Refer to this [article](https://egvijayanand.in/2024/03/07/dotnet-maui-community-toolkit-maps-in-winui-3-app/) for working with this sample|
|`MapsApp`|Using .NET MAUI [CommunityToolkit.Maui.Maps](https://www.nuget.org/packages/CommunityToolkit.Maui.Maps) embedded in a Native WinUI 3 App, targeting .NET 9 <br /> Refer to this [article](https://egvijayanand.in/2024/03/07/dotnet-maui-community-toolkit-maps-in-winui-3-app/) for working with this sample|
|`HybridWebViewApp`|A sample .NET MAUI App showcasing the features of the new [HybridWebView](https://learn.microsoft.com/en-us/dotnet/maui/whats-new/dotnet-9?view=net-maui-9.0#hybridwebview) control.|

Made available in the the `src\` directory:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public MainWindow()

// Platform-neutral - Windowless API
Content = new MauiPage().ToPlatform(mauiContext);
// Updated Window inclusive API
// Updated Window-aware API
Content = new MauiPage().ToPlatformEmbedded(mauiContext);
}
}
18 changes: 11 additions & 7 deletions src/NET_9/MapsApp/MapsApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<EnableMsixTooling>true</EnableMsixTooling>
<WindowsPackageType>None</WindowsPackageType>

<!-- .NET MAUI -->
<UseMaui>true</UseMaui>
<!-- <MauiEnablePlatformUsings>true</MauiEnablePlatformUsings> -->

<!-- Project Options -->
<Nullable>enable</Nullable>
<!-- <ImplicitUsings>enable</ImplicitUsings> -->
Expand All @@ -20,8 +24,9 @@
<UseRidGraph>true</UseRidGraph>
<Platforms>x86;x64;arm64</Platforms>
<ApplicationManifest>app.manifest</ApplicationManifest>
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 8">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &lt; 8">win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
</PropertyGroup>

<ItemGroup>
Expand All @@ -35,12 +40,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui.Maps" Version="2.0.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.0-preview.1.9973" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="9.0.0-preview.1.9973" />
<PackageReference Include="Microsoft.Maui.Controls.Maps" Version="9.0.0-preview.1.9973" />
<PackageReference Include="CommunityToolkit.Maui.Maps" Version="2.*" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Maps" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.*" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.*" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.*" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Platform>arm64</Platform>
<RuntimeIdentifier>win10-arm64</RuntimeIdentifier>
<Platform>ARM64</Platform>
<RuntimeIdentifier Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 8">win-arm64</RuntimeIdentifier>
<RuntimeIdentifier Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &lt; 8">win10-arm64</RuntimeIdentifier>
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<!--
See https://github.com/microsoft/CsWinRT/issues/373
<PublishTrimmed>True</PublishTrimmed>
-->
<PublishTrimmed Condition="'$(Configuration)' == 'Debug'">False</PublishTrimmed>
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Platform>x64</Platform>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 8">win-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &lt; 8">win10-x64</RuntimeIdentifier>
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<!--
See https://github.com/microsoft/CsWinRT/issues/373
<PublishTrimmed>True</PublishTrimmed>
-->
<PublishTrimmed Condition="'$(Configuration)' == 'Debug'">False</PublishTrimmed>
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Platform>x86</Platform>
<RuntimeIdentifier>win10-x86</RuntimeIdentifier>
<RuntimeIdentifier Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 8">win-x86</RuntimeIdentifier>
<RuntimeIdentifier Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &lt; 8">win10-x86</RuntimeIdentifier>
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<!--
See https://github.com/microsoft/CsWinRT/issues/373
<PublishTrimmed>True</PublishTrimmed>
-->
<PublishTrimmed Condition="'$(Configuration)' == 'Debug'">False</PublishTrimmed>
<PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>
</PropertyGroup>
</Project>
22 changes: 17 additions & 5 deletions src/NET_9/MapsApp/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.Maui.Hosting;
using Microsoft.Maui;
using Microsoft.Maui.Embedding;
// Note: There's a change in namespace.
using Microsoft.Maui.Controls.Embedding;
//using Microsoft.Maui.Embedding;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Platform;
using MapsApp.Extensions;
Expand All @@ -17,12 +19,22 @@ public MainWindow()
this.InitializeComponent();

var mauiApp = MauiApp.CreateBuilder()
.UseMauiEmbedding<MyApp>()
.UseMauiEmbeddedApp<MyApp>() // Note: The method name too got updated.
.UseMauiToolkitMaps("<BING_MAPS_API_KEY_HERE>") // To generate a Bing Maps API Key, visit https://www.bingmapsportal.com/
.Build();
// While doing .NET MAUI Embedding, this call is required so that the Application object instance gets resolved.
var _ = mauiApp.Services.GetRequiredService<IApplication>();
Content = new HomePage().ToPlatform(new MauiContext(mauiApp.Services));

// From .NET MAUI 9 Preview 7 onwards, the below method call is no longer required
// as the .NET MAUI Embedding process is revamped.
// While doing .NET MAUI Embedding, this call is required so that
// the Application object instance gets resolved.
//var _ = mauiApp.Services.GetRequiredService<IApplication>();

var mauiContext = new MauiContext(mauiApp.Services);

// Platform-neutral - Windowless API
Content = new HomePage().ToPlatform(mauiContext);
// Updated Window-aware API
//Content = new HomePage().ToPlatformEmbedded(mauiContext);
}
}
}

0 comments on commit b13ba52

Please sign in to comment.