Skip to content

Commit

Permalink
Merge pull request #79 from egvijayanand/working
Browse files Browse the repository at this point in the history
Using .NET MAUI Community Toolkit Maps in WinUI 3 App
  • Loading branch information
egvijayanand authored Mar 7, 2024
2 parents b4ddfc2 + f15e92c commit 6c7a3ca
Show file tree
Hide file tree
Showing 47 changed files with 850 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ _Note: Samples are in the process of migrating to the latest framework version,
Made available in the `src\NET_8\` directory:
* `EmbeddedWindows` - .NET MAUI Page embedded in a Native WinUI 3 App, targeting .NET 8 (`net8.0-windows10.0.19041.0`)
- 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 8 (`net8.0-windows10.0.19041.0`)
- Refer to this [article](https://egvijayanand.in/2024/03/07/dotnet-maui-community-toolkit-maps-in-winui-3-app/) for working with this sample

Made available in the `src\NET_9\` directory:
* `EmbeddedWindows` - .NET MAUI Page embedded in a Native WinUI 3 App, targeting .NET 9 (`net9.0-windows10.0.19041.0`)
- 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 (`net9.0-windows10.0.19041.0`)
- Refer to this [article](https://egvijayanand.in/2024/03/07/dotnet-maui-community-toolkit-maps-in-winui-3-app/) for working with this sample

Made available in the the `src\` directory:

Expand Down
49 changes: 49 additions & 0 deletions src/NET_8/MapsApp/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Application
x:Class="MapsApp.App"
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"
xmlns:local="using:MapsApp"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<!-- Other merged dictionaries here -->
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
<Color x:Key="Primary">#512BD4</Color>

<SolidColorBrush x:Key="PrimaryBrush" Color="{StaticResource Primary}" />
<SolidColorBrush x:Key="WhiteBrush" Color="White" />
<SolidColorBrush x:Key="BlackBrush" Color="Black" />

<x:Double x:Key="AppFontSize">14</x:Double>

<Style x:Key="MyLabel" TargetType="TextBlock">
<Setter Property="Foreground"
Value="{StaticResource PrimaryBrush}" />
</Style>

<Style x:Key="Action" TargetType="Button">
<Setter Property="FontSize"
Value="{StaticResource AppFontSize}" />
<Setter Property="Padding"
Value="14,10" />
</Style>

<Style x:Key="PrimaryAction"
TargetType="Button"
BasedOn="{StaticResource Action}">
<Setter Property="Background"
Value="{StaticResource PrimaryBrush}" />
<Setter Property="CornerRadius"
Value="8" />
<Setter Property="Foreground"
Value="{StaticResource WhiteBrush}" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
30 changes: 30 additions & 0 deletions src/NET_8/MapsApp/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace MapsApp
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
m_window?.Activate();
}

private Window? m_window;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/NET_8/MapsApp/Assets/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/NET_8/MapsApp/Extensions/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using CommunityToolkit.Maui.Maps.Handlers;
using Microsoft.Maui.Controls.Maps;
using Microsoft.Maui.Hosting;
using System.Reflection;

namespace MapsApp.Extensions;

public static class AppBuilderExtensions
{
public static MauiAppBuilder UseMauiToolkitMaps(this MauiAppBuilder builder, string key)
{
SetMapsKey(key);
builder.ConfigureMauiHandlers(handlers => handlers.AddHandler<Map, MapHandlerWindows>());
return builder;

static void SetMapsKey(string key)
{
var mapsKey = typeof(MapHandlerWindows).GetField("MapsKey", BindingFlags.NonPublic | BindingFlags.Static);
mapsKey?.SetValue(null, key);
}
}
}
4 changes: 4 additions & 0 deletions src/NET_8/MapsApp/Imports.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
global using Microsoft.UI.Xaml;

global using MapsApp;
global using MapsApp.Views;
64 changes: 64 additions & 0 deletions src/NET_8/MapsApp/MapsApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<OutputType>WinExe</OutputType>

<!-- WinUI 3 -->
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
<WindowsPackageType>None</WindowsPackageType>

<!-- Project Options -->
<Nullable>enable</Nullable>
<!-- <ImplicitUsings>enable</ImplicitUsings> -->
<RootNamespace>MapsApp</RootNamespace>
<EnableDefaultXamlItems>false</EnableDefaultXamlItems>

<!-- App Options -->
<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>
</PropertyGroup>

<ItemGroup>
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\Square150x150Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Assets\StoreLogo.png" />
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui.Maps" Version="2.0.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.7" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.7" />
<PackageReference Include="Microsoft.Maui.Controls.Maps" Version="8.0.7" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.*" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.*" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

<!--
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
Tools extension to be activated for this project even if the Windows App SDK Nuget
package has not yet been restored.
-->
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>

<!--
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
Explorer "Package and Publish" context menu entry to be enabled for this project even if
the Windows App SDK Nuget package has not yet been restored.
-->
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>
</Project>
43 changes: 43 additions & 0 deletions src/NET_8/MapsApp/MapsApp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33103.201
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F96C4E64-BE43-4154-A47D-AB08A79065BB}") = "MapsApp", "MapsApp.csproj", "{5264FDB3-5545-4109-9B71-08DD9FADB4D0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|arm64 = Debug|arm64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|arm64 = Release|arm64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|arm64.ActiveCfg = Debug|arm64
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|arm64.Build.0 = Debug|arm64
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|arm64.Deploy.0 = Debug|arm64
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|x64.ActiveCfg = Debug|x64
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|x64.Build.0 = Debug|x64
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|x64.Deploy.0 = Debug|x64
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|x86.ActiveCfg = Debug|x86
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|x86.Build.0 = Debug|x86
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Debug|x86.Deploy.0 = Debug|x86
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|arm64.ActiveCfg = Release|arm64
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|arm64.Build.0 = Release|arm64
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|arm64.Deploy.0 = Release|arm64
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|x64.ActiveCfg = Release|x64
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|x64.Build.0 = Release|x64
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|x64.Deploy.0 = Release|x64
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|x86.ActiveCfg = Release|x86
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|x86.Build.0 = Release|x86
{5264FDB3-5545-4109-9B71-08DD9FADB4D0}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {35FE2F82-41AC-40AC-B3A1-A496E1DB3D9B}
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions src/NET_8/MapsApp/MyApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using MauiApplication = Microsoft.Maui.Controls.Application;

namespace MapsApp
{
public partial class MyApp : MauiApplication
{
public MyApp()
{

}
}
}
48 changes: 48 additions & 0 deletions src/NET_8/MapsApp/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>

<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">

<Identity
Name="4b915f98-c95c-41a2-83dd-8ca3df60e938"
Publisher="CN=User Name"
Version="1.0.0.0" />

<Properties>
<DisplayName>MapsApp</DisplayName>
<PublisherDisplayName>User Name</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>

<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
</Dependencies>

<Resources>
<Resource Language="x-generate"/>
</Resources>

<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="MapsApp"
Description="MapsApp"
BackgroundColor="transparent"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>

<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>
20 changes: 20 additions & 0 deletions src/NET_8/MapsApp/Properties/PublishProfiles/win10-arm64.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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>
<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>
-->
</PropertyGroup>
</Project>
20 changes: 20 additions & 0 deletions src/NET_8/MapsApp/Properties/PublishProfiles/win10-x64.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Platform>x64</Platform>
<RuntimeIdentifier>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>
-->
</PropertyGroup>
</Project>
20 changes: 20 additions & 0 deletions src/NET_8/MapsApp/Properties/PublishProfiles/win10-x86.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Platform>x86</Platform>
<RuntimeIdentifier>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>
-->
</PropertyGroup>
</Project>
10 changes: 10 additions & 0 deletions src/NET_8/MapsApp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"MapsApp (Package)": {
"commandName": "MsixPackage"
},
"MapsApp (Unpackaged)": {
"commandName": "Project"
}
}
}
14 changes: 14 additions & 0 deletions src/NET_8/MapsApp/Views/HomePage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Maps;
using Microsoft.Maui.Devices.Sensors;
using Microsoft.Maui.Maps;

namespace MapsApp.Views;

public class HomePage : ContentPage
{
public HomePage()
{
Content = new Map(new MapSpan(new Location(47.643543, -122.130821), 0.01, 0.01));
}
}
Loading

0 comments on commit 6c7a3ca

Please sign in to comment.