Skip to content

Commit 6c7a3ca

Browse files
authored
Merge pull request #79 from egvijayanand/working
Using .NET MAUI Community Toolkit Maps in WinUI 3 App
2 parents b4ddfc2 + f15e92c commit 6c7a3ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+850
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ _Note: Samples are in the process of migrating to the latest framework version,
99
Made available in the `src\NET_8\` directory:
1010
* `EmbeddedWindows` - .NET MAUI Page embedded in a Native WinUI 3 App, targeting .NET 8 (`net8.0-windows10.0.19041.0`)
1111
- Refer to this [article](https://egvijayanand.in/2024/02/29/dotnet-maui-native-embedding/) for working with this sample
12+
* `MapsApp` - .NET MAUI Maps embedded in a Native WinUI 3 App, targeting .NET 8 (`net8.0-windows10.0.19041.0`)
13+
- Refer to this [article](https://egvijayanand.in/2024/03/07/dotnet-maui-community-toolkit-maps-in-winui-3-app/) for working with this sample
1214

1315
Made available in the `src\NET_9\` directory:
1416
* `EmbeddedWindows` - .NET MAUI Page embedded in a Native WinUI 3 App, targeting .NET 9 (`net9.0-windows10.0.19041.0`)
1517
- Refer to this [article](https://egvijayanand.in/2024/02/29/dotnet-maui-native-embedding/) for working with this sample
18+
* `MapsApp` - .NET MAUI Maps embedded in a Native WinUI 3 App, targeting .NET 9 (`net9.0-windows10.0.19041.0`)
19+
- Refer to this [article](https://egvijayanand.in/2024/03/07/dotnet-maui-community-toolkit-maps-in-winui-3-app/) for working with this sample
1620

1721
Made available in the the `src\` directory:
1822

src/NET_8/MapsApp/App.xaml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Application
3+
x:Class="MapsApp.App"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="using:MapsApp"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d">
10+
<Application.Resources>
11+
<ResourceDictionary>
12+
<ResourceDictionary.MergedDictionaries>
13+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
14+
<!-- Other merged dictionaries here -->
15+
</ResourceDictionary.MergedDictionaries>
16+
<!-- Other app resources here -->
17+
<Color x:Key="Primary">#512BD4</Color>
18+
19+
<SolidColorBrush x:Key="PrimaryBrush" Color="{StaticResource Primary}" />
20+
<SolidColorBrush x:Key="WhiteBrush" Color="White" />
21+
<SolidColorBrush x:Key="BlackBrush" Color="Black" />
22+
23+
<x:Double x:Key="AppFontSize">14</x:Double>
24+
25+
<Style x:Key="MyLabel" TargetType="TextBlock">
26+
<Setter Property="Foreground"
27+
Value="{StaticResource PrimaryBrush}" />
28+
</Style>
29+
30+
<Style x:Key="Action" TargetType="Button">
31+
<Setter Property="FontSize"
32+
Value="{StaticResource AppFontSize}" />
33+
<Setter Property="Padding"
34+
Value="14,10" />
35+
</Style>
36+
37+
<Style x:Key="PrimaryAction"
38+
TargetType="Button"
39+
BasedOn="{StaticResource Action}">
40+
<Setter Property="Background"
41+
Value="{StaticResource PrimaryBrush}" />
42+
<Setter Property="CornerRadius"
43+
Value="8" />
44+
<Setter Property="Foreground"
45+
Value="{StaticResource WhiteBrush}" />
46+
</Style>
47+
</ResourceDictionary>
48+
</Application.Resources>
49+
</Application>

src/NET_8/MapsApp/App.xaml.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace MapsApp
2+
{
3+
/// <summary>
4+
/// Provides application-specific behavior to supplement the default Application class.
5+
/// </summary>
6+
public partial class App : Application
7+
{
8+
/// <summary>
9+
/// Initializes the singleton application object. This is the first line of authored code
10+
/// executed, and as such is the logical equivalent of main() or WinMain().
11+
/// </summary>
12+
public App()
13+
{
14+
this.InitializeComponent();
15+
}
16+
17+
/// <summary>
18+
/// Invoked when the application is launched normally by the end user. Other entry points
19+
/// will be used such as when the application is launched to open a specific file.
20+
/// </summary>
21+
/// <param name="args">Details about the launch request and process.</param>
22+
protected override void OnLaunched(LaunchActivatedEventArgs args)
23+
{
24+
m_window = new MainWindow();
25+
m_window?.Activate();
26+
}
27+
28+
private Window? m_window;
29+
}
30+
}
Loading
Loading
Loading
Loading
Loading
456 Bytes
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using CommunityToolkit.Maui.Maps.Handlers;
2+
using Microsoft.Maui.Controls.Maps;
3+
using Microsoft.Maui.Hosting;
4+
using System.Reflection;
5+
6+
namespace MapsApp.Extensions;
7+
8+
public static class AppBuilderExtensions
9+
{
10+
public static MauiAppBuilder UseMauiToolkitMaps(this MauiAppBuilder builder, string key)
11+
{
12+
SetMapsKey(key);
13+
builder.ConfigureMauiHandlers(handlers => handlers.AddHandler<Map, MapHandlerWindows>());
14+
return builder;
15+
16+
static void SetMapsKey(string key)
17+
{
18+
var mapsKey = typeof(MapHandlerWindows).GetField("MapsKey", BindingFlags.NonPublic | BindingFlags.Static);
19+
mapsKey?.SetValue(null, key);
20+
}
21+
}
22+
}

src/NET_8/MapsApp/Imports.cs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
global using Microsoft.UI.Xaml;
2+
3+
global using MapsApp;
4+
global using MapsApp.Views;

src/NET_8/MapsApp/MapsApp.csproj

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
5+
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
6+
<OutputType>WinExe</OutputType>
7+
8+
<!-- WinUI 3 -->
9+
<UseWinUI>true</UseWinUI>
10+
<EnableMsixTooling>true</EnableMsixTooling>
11+
<WindowsPackageType>None</WindowsPackageType>
12+
13+
<!-- Project Options -->
14+
<Nullable>enable</Nullable>
15+
<!-- <ImplicitUsings>enable</ImplicitUsings> -->
16+
<RootNamespace>MapsApp</RootNamespace>
17+
<EnableDefaultXamlItems>false</EnableDefaultXamlItems>
18+
19+
<!-- App Options -->
20+
<UseRidGraph>true</UseRidGraph>
21+
<Platforms>x86;x64;arm64</Platforms>
22+
<ApplicationManifest>app.manifest</ApplicationManifest>
23+
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
24+
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
25+
</PropertyGroup>
26+
27+
<ItemGroup>
28+
<Content Include="Assets\SplashScreen.scale-200.png" />
29+
<Content Include="Assets\LockScreenLogo.scale-200.png" />
30+
<Content Include="Assets\Square150x150Logo.scale-200.png" />
31+
<Content Include="Assets\Square44x44Logo.scale-200.png" />
32+
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
33+
<Content Include="Assets\StoreLogo.png" />
34+
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
35+
</ItemGroup>
36+
37+
<ItemGroup>
38+
<PackageReference Include="CommunityToolkit.Maui.Maps" Version="2.0.0" />
39+
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.7" />
40+
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.7" />
41+
<PackageReference Include="Microsoft.Maui.Controls.Maps" Version="8.0.7" />
42+
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.*" />
43+
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.*" />
44+
<Manifest Include="$(ApplicationManifest)" />
45+
</ItemGroup>
46+
47+
<!--
48+
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
49+
Tools extension to be activated for this project even if the Windows App SDK Nuget
50+
package has not yet been restored.
51+
-->
52+
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
53+
<ProjectCapability Include="Msix" />
54+
</ItemGroup>
55+
56+
<!--
57+
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
58+
Explorer "Package and Publish" context menu entry to be enabled for this project even if
59+
the Windows App SDK Nuget package has not yet been restored.
60+
-->
61+
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
62+
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
63+
</PropertyGroup>
64+
</Project>

src/NET_8/MapsApp/MapsApp.sln

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.33103.201
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{F96C4E64-BE43-4154-A47D-AB08A79065BB}") = "MapsApp", "MapsApp.csproj", "{5264FDB3-5545-4109-9B71-08DD9FADB4D0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|arm64 = Debug|arm64
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|arm64 = Release|arm64
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|arm64.ActiveCfg = Debug|arm64
19+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|arm64.Build.0 = Debug|arm64
20+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|arm64.Deploy.0 = Debug|arm64
21+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|x64.ActiveCfg = Debug|x64
22+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|x64.Build.0 = Debug|x64
23+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|x64.Deploy.0 = Debug|x64
24+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|x86.ActiveCfg = Debug|x86
25+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|x86.Build.0 = Debug|x86
26+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|x86.Deploy.0 = Debug|x86
27+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|arm64.ActiveCfg = Release|arm64
28+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|arm64.Build.0 = Release|arm64
29+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|arm64.Deploy.0 = Release|arm64
30+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|x64.ActiveCfg = Release|x64
31+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|x64.Build.0 = Release|x64
32+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|x64.Deploy.0 = Release|x64
33+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|x86.ActiveCfg = Release|x86
34+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|x86.Build.0 = Release|x86
35+
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|x86.Deploy.0 = Release|x86
36+
EndGlobalSection
37+
GlobalSection(SolutionProperties) = preSolution
38+
HideSolutionNode = FALSE
39+
EndGlobalSection
40+
GlobalSection(ExtensibilityGlobals) = postSolution
41+
SolutionGuid = {35FE2F82-41AC-40AC-B3A1-A496E1DB3D9B}
42+
EndGlobalSection
43+
EndGlobal

src/NET_8/MapsApp/MyApp.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using MauiApplication = Microsoft.Maui.Controls.Application;
2+
3+
namespace MapsApp
4+
{
5+
public partial class MyApp : MauiApplication
6+
{
7+
public MyApp()
8+
{
9+
10+
}
11+
}
12+
}
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<Package
4+
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
5+
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
6+
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
7+
IgnorableNamespaces="uap rescap">
8+
9+
<Identity
10+
Name="4b915f98-c95c-41a2-83dd-8ca3df60e938"
11+
Publisher="CN=User Name"
12+
Version="1.0.0.0" />
13+
14+
<Properties>
15+
<DisplayName>MapsApp</DisplayName>
16+
<PublisherDisplayName>User Name</PublisherDisplayName>
17+
<Logo>Assets\StoreLogo.png</Logo>
18+
</Properties>
19+
20+
<Dependencies>
21+
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
22+
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
23+
</Dependencies>
24+
25+
<Resources>
26+
<Resource Language="x-generate"/>
27+
</Resources>
28+
29+
<Applications>
30+
<Application Id="App"
31+
Executable="$targetnametoken$.exe"
32+
EntryPoint="$targetentrypoint$">
33+
<uap:VisualElements
34+
DisplayName="MapsApp"
35+
Description="MapsApp"
36+
BackgroundColor="transparent"
37+
Square150x150Logo="Assets\Square150x150Logo.png"
38+
Square44x44Logo="Assets\Square44x44Logo.png">
39+
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
40+
<uap:SplashScreen Image="Assets\SplashScreen.png" />
41+
</uap:VisualElements>
42+
</Application>
43+
</Applications>
44+
45+
<Capabilities>
46+
<rescap:Capability Name="runFullTrust" />
47+
</Capabilities>
48+
</Package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
6+
<PropertyGroup>
7+
<PublishProtocol>FileSystem</PublishProtocol>
8+
<Platform>arm64</Platform>
9+
<RuntimeIdentifier>win10-arm64</RuntimeIdentifier>
10+
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
11+
<SelfContained>true</SelfContained>
12+
<PublishSingleFile>False</PublishSingleFile>
13+
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
14+
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
15+
<!--
16+
See https://github.com/microsoft/CsWinRT/issues/373
17+
<PublishTrimmed>True</PublishTrimmed>
18+
-->
19+
</PropertyGroup>
20+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
6+
<PropertyGroup>
7+
<PublishProtocol>FileSystem</PublishProtocol>
8+
<Platform>x64</Platform>
9+
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
10+
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
11+
<SelfContained>true</SelfContained>
12+
<PublishSingleFile>False</PublishSingleFile>
13+
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
14+
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
15+
<!--
16+
See https://github.com/microsoft/CsWinRT/issues/373
17+
<PublishTrimmed>True</PublishTrimmed>
18+
-->
19+
</PropertyGroup>
20+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
6+
<PropertyGroup>
7+
<PublishProtocol>FileSystem</PublishProtocol>
8+
<Platform>x86</Platform>
9+
<RuntimeIdentifier>win10-x86</RuntimeIdentifier>
10+
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
11+
<SelfContained>true</SelfContained>
12+
<PublishSingleFile>False</PublishSingleFile>
13+
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
14+
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
15+
<!--
16+
See https://github.com/microsoft/CsWinRT/issues/373
17+
<PublishTrimmed>True</PublishTrimmed>
18+
-->
19+
</PropertyGroup>
20+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"profiles": {
3+
"MapsApp (Package)": {
4+
"commandName": "MsixPackage"
5+
},
6+
"MapsApp (Unpackaged)": {
7+
"commandName": "Project"
8+
}
9+
}
10+
}

src/NET_8/MapsApp/Views/HomePage.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.Maui.Controls;
2+
using Microsoft.Maui.Controls.Maps;
3+
using Microsoft.Maui.Devices.Sensors;
4+
using Microsoft.Maui.Maps;
5+
6+
namespace MapsApp.Views;
7+
8+
public class HomePage : ContentPage
9+
{
10+
public HomePage()
11+
{
12+
Content = new Map(new MapSpan(new Location(47.643543, -122.130821), 0.01, 0.01));
13+
}
14+
}

0 commit comments

Comments
 (0)