C# WPF Bing地圖展示

来源:https://www.cnblogs.com/Dotnet9-com/archive/2020/01/03/12146566.html
-Advertisement-
Play Games

微信公眾號: "Dotnet9" ,網站: "Dotnet9" ,問題或建議,請網站留言; "如果您覺得Dotnet9對您有幫助,歡迎贊賞" 內容目錄 1. 實現效果 2. 業務場景 3. 編碼實現 4. 本文參考 5. 源碼下載 1.實現效果 Bing地圖展示界面 2.業務場景 Bing地圖控制項的 ...


微信公眾號:Dotnet9,網站:Dotnet9,問題或建議,請網站留言;
如果您覺得Dotnet9對您有幫助,歡迎贊賞

內容目錄

  1. 實現效果
  2. 業務場景
  3. 編碼實現
  4. 本文參考
  5. 源碼下載

1.實現效果

Bing地圖展示界面
Bing地圖展示界面

2.業務場景

Bing地圖控制項的使用

3.編碼實現

3.1 添加Nuget庫

站長使用 .Net Core 3.1 創建的WPF工程,創建“BingMap”解決方案後,需要添加三個Nuget庫:MaterialDesignThemes、MaterialDesignColors和Bing WPF地圖控制項Microsoft.Maps.MapControl.WPF,其中Bing地圖控制項是.net framework 4.6.1版本,所以項目使用framework版本要好點,其實影響也不大。

MaterialDesign控制項庫

Bing WPF地圖控制項Microsoft.Maps.MapControl.WPF
Bing WPF地圖控制項Microsoft.Maps.MapControl.WPF

註意
使用bing map地圖控制項需要註冊開發者賬號,站長只是按視頻教程敲的代碼,VS 2019設計器能正常載入地圖,但運行時會有提示請註冊開發者賬號,否則地圖無法正常顯示

需要註冊Bing地圖開發者賬號
需要註冊Bing地圖開發者賬號

3.2 工程結構

不需要截圖,只修改了兩個文件,App.xaml添加MD控制項樣式,MainWindow主視窗實現效果。

3.3 App.xaml引入MD控制項樣式

<Application x:Class="BingMap.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:BingMap"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.LightBlue.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

3.4 主窗體 MainWindow.xaml

載入Bing地圖控制項,設置地圖屬性等:

<Window x:Class="BingMap.MainWindow"
        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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:BingMap"
        mc:Ignorable="d"
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
        xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
        Title="Bing地圖" Height="600" Width="1080" WindowStyle="None" ResizeMode="NoResize"
        WindowStartupLocation="CenterScreen" Background="#FF3A3A3A">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="250"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <StackPanel Grid.Row="1" Margin="10">
            <Grid>
                <TextBox Background="White" Padding="10 0 25 0"/>
                <materialDesign:PackIcon Kind="MapMarker" VerticalAlignment="Center" Margin="2"/>
                <Button HorizontalAlignment="Right" Style="{StaticResource MaterialDesignFlatButton}">
                    <materialDesign:PackIcon Kind="Search"/>
                </Button>
            </Grid>
            <ListView>
                <ListViewItem>
                    <Border BorderBrush="LightGray" BorderThickness="0 0 0 1" Width="260">
                        <Grid>
                            <StackPanel Height="50">
                                <TextBlock Text="雞腿"/>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="4.5" Foreground="#DDFF6F0B" Margin="1" FontSize="10"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="StarHalf" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                </StackPanel>
                                <TextBlock Text="Open until 6:00PM" Opacity="0.7"/>
                            </StackPanel>
                            <Image HorizontalAlignment="Right" Margin="0 0 50 0" Width="50" Height="50" Source="https://img.dotnet9.com/logo.png"/>
                        </Grid>
                    </Border>
                </ListViewItem>
                <ListViewItem>
                    <Border BorderBrush="LightGray" BorderThickness="0 0 0 1" Width="260">
                        <Grid>
                            <StackPanel Height="50">
                                <TextBlock Text="La Casita Grill"/>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="4.5" Foreground="#DDFF6F0B" Margin="1" FontSize="10"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="StarHalf" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                </StackPanel>
                                <TextBlock Text="Open until 6:00PM" Opacity="0.7"/>
                            </StackPanel>
                            <Image HorizontalAlignment="Right" Margin="0 0 50 0" Width="50" Height="50" Source="https://img.dotnet9.com/logo.png"/>
                        </Grid>
                    </Border>
                </ListViewItem>
                <ListViewItem>
                    <Border BorderBrush="LightGray" BorderThickness="0 0 0 1" Width="260">
                        <Grid>
                            <StackPanel Height="50">
                                <TextBlock Text="La Casita Grill"/>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="4.5" Foreground="#DDFF6F0B" Margin="1" FontSize="10"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="StarHalf" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                </StackPanel>
                                <TextBlock Text="Open until 6:00PM" Opacity="0.7"/>
                            </StackPanel>
                            <Image HorizontalAlignment="Right" Margin="0 0 50 0" Width="50" Height="50" Source="https://img.dotnet9.com/logo.png"/>
                        </Grid>
                    </Border>

                </ListViewItem>
                <ListViewItem>
                    <Border BorderBrush="LightGray" BorderThickness="0 0 0 1" Width="260">
                        <Grid>
                            <StackPanel Height="50">
                                <TextBlock Text="La Casita Grill"/>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="4.5" Foreground="#DDFF6F0B" Margin="1" FontSize="10"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="Star" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                    <materialDesign:PackIcon Kind="StarHalf" Foreground="#DDFF6F0B" Margin="1" VerticalAlignment="Center" Width="12" Height="12"/>
                                </StackPanel>
                                <TextBlock Text="Open until 6:00PM" Opacity="0.7"/>
                            </StackPanel>
                            <Image HorizontalAlignment="Right" Margin="0 0 50 0" Width="50" Height="50" Source="https://img.dotnet9.com/logo.png"/>
                        </Grid>
                    </Border>
                </ListViewItem>
            </ListView>
        </StackPanel>

        <Button Grid.Column="1" HorizontalAlignment="Right" Style="{StaticResource MaterialDesignFlatButton}">
            <materialDesign:PackIcon Kind="Close"/>
        </Button>

        <m:Map Mode="Road" Grid.Column="1" Grid.Row="1" ZoomLevel="16" Center="-23.1870304,-50.6606103">
            <Canvas
                m:MapLayer.Position="-23.1870304,-50.6606103"
                m:MapLayer.PositionOrigin="BottomCenter" Width="30" Height="30">
                <materialDesign:PackIcon Kind="MapMarker" Width="30" Height="30" Foreground="#FF3C3C3C"/>
            </Canvas>
        </m:Map>
    </Grid>
</Window>

4.本文參考

Design com WPF 大神的學習視頻:Bing Maps

開源控制項庫:MaterialDesignInXamlToolkit

本站對MD開源控制項庫的介紹:控制項介紹

5.代碼下載

文中代碼已經全部給出。

除非註明,文章均由 Dotnet9 整理髮布,歡迎轉載。

轉載請註明本文地址:https://dotnet9.com/6814.html

歡迎掃描下方二維碼關註 Dotnet9 的微信公眾號,本站會及時推送最新技術文章

Dotnet9


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1024是2的10次方,1024=2¹º。 在電腦中,1GB=1024MB,1MB=1024KB,1KB=1024Byte。 因此1024多指互聯網和科技公司,經常表示程式員,另外還表示一級棒的意思(1GB)。 image 996是個工作制,表示工作時間從早上9點到晚上9點,每周工作6天。也就是說 ...
  • 首先要使用composer來下載一個第三方擴展就可以實現php的websocket客戶端,直接在當前目錄生成下composer.json文件就可以了composer require textalk/websocket 配合php的讀取文件操作,只讀取最新的追加的內容,下麵代碼為讀取日誌的客戶端 , ...
  • 記錄一道學長們說有點難度的題目 好好玩啊這道題 ACM程式設計大賽是大學級別最高的腦力競賽,素來被冠以"程式設計的奧林匹克"的尊稱。大賽至今已有近40年的歷史,是世界範圍內歷史最悠久、規模最大的程式設計競賽。比賽形式是:從各大洲區域預賽出線的參賽隊伍,於指定的時間、地點參加世界級的決賽,由1個教練、 ...
  • 開發者工具(F12) 其中常用的有Elements(元素麵板)、Console(控制臺面板)、Sources(源代碼面板)、Network(網路面板) 找 JS 文件的幾種方法 1、找發起地址 2、設置事件觸發斷點 Event Listener Breakpoint 使用Sources面板上的Eve ...
  • 沒有什麼能比學以致用讓學習變得更有動力的了。 不知道大家在工作中有沒有一些工作需要重覆的點擊滑鼠,因為會影響到財務統計報表的關係,我們每個月底月初都要修改ERP中的單據日期,單據多的時候光修改就能讓你點滑鼠點到手麻。(這裡要吐槽一下浪沙軟體,別的單據都可以批量修改日期,就是這個移倉單不行,你們研發怎 ...
  • 告別枯燥,60秒學會一個Python小例子。奔著此出發點,我在過去1個月,將平時經常使用的代碼段換為小例子,分享出來後受到大家的喜歡。 一、基本操作 。 1 鏈式比較 i = 3 print(1 < i < 3) # False print(1 < i <= 3) # True 2 不用else和i ...
  • 一、發送純文本郵件 import smtplib from email.mime.text import MIMEText subject = "標題" # 郵件的主題 content = "測試" # 郵件的內容 sender = "[email protected]" # 發件人 passwor ...
  • 最近在溫故Delphi精要,下麵是按照其中做的托盤圖標組件,記錄一下。 工具:Delphi 7+Image Editer 先上圖: 組件源碼如下:對於圖標,百度 unit XsdTrayIcon; interface uses SysUtils, Classes, Windows, Messages ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...