1. 設為首頁   文化中國網歡迎您~!

          C# WPF Bing地圖展示

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

          內容目錄

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

          1.實現效果

          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 map地圖控件需要注冊開發者賬號,站長只是按視頻教程敲的代碼,VS 2019設計器能正常加載地圖,但運行時會有提示請注冊開發者賬號,否則地圖無法正常顯示

          需要注冊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

          推薦閱讀:蘋果x與xr
          好运来 www.www834suncity.com:壤塘县| www.hg01345.com:平湖市| www.findnewyorkclubs.com:新化县| www.msplg.com:江永县| www.aliciacreative.com:福安市| www.zjyoushun.com:岳池县| www.xiexiaosuan.com:保康县| www.vidyaseminars.com:富民县| www.jd2002.net:陈巴尔虎旗| www.steven-z.com:莆田市| www.whxblaw.com:江都市| www.starsmadrid.com:伊春市| www.xfkqf.com:西充县| www.aiellocalabro.org:连城县| www.jtjdg.cn:益阳市| www.wed-direct.com:东光县| www.sap-rope.com:边坝县| www.ewunthegun.com:繁昌县| www.99chunyin.com:盐池县| www.tcga4u.org:新河县| www.slclong.com:平邑县| www.chansamabut.com:梅河口市| www.99069dd.com:玛沁县| www.esfhera.com:祁门县| www.fg556.com:浪卡子县| www.zajstone.com:班戈县| www.foothill-bible.org:金川县| www.zshuamao.com:樟树市| www.associazionesimbiosigratteri.com:大足县| www.365zhy.com:阳春市| www.leominstersba.com:安庆市| www.silverspoonhoney.com:塔城市| www.cocordia.com:灌南县| www.aureliogonzalez.com:德兴市| www.wazww.com:南靖县| www.izhuoji.net:丹凤县| www.lakehousemitchell.com:金坛市| www.931821.com:旺苍县| www.xirunjiaoyu.com:浙江省| www.teeshirtyeswekahn.com:濮阳市| www.xadeco.com:禹州市| www.ohhiyo.com:夹江县| www.jsccdt.com:潍坊市| www.baraka-ter.com:枝江市| www.abgxx.com:甘洛县| www.parcfrankston.com:息烽县| www.chinacheapshop.com:大邑县| www.truboot.com:鹰潭市| www.razorcrusaders.com:曲周县| www.anjiescl.com:潮州市| www.mulama.com:阿瓦提县| www.greenitways.com:菏泽市| www.kingsfishing.com:民丰县| www.specialdayvideo.com:南充市| www.ss-shop.org:银川市| www.zumbafarnorthcoast.com:宣汉县| www.senimarmer.com:东城区| www.hmartusa.net:汨罗市| www.videodownloadming.com:霍邱县| www.generofem.com:安乡县| www.code1220.com:盐池县| www.alamat-sekolah.com:财经| www.ramblingabare.com:溧阳市| www.hairbook.org:汪清县| www.abbottslandscape.com:黄山市| www.ohkarma.com:澎湖县| www.commonelementllc.com:库尔勒市| www.sjssxj.com:涪陵区| www.rcybgg.com:泰州市| www.bustybarmaid.com:陵川县| www.zjubbs.net:甘泉县| www.addx-technologies.com:潜江市| www.blogcampghana.com:阿拉善右旗| www.rncjw.cn:宣化县| www.kscdw.com:漳州市| www.shoplocalinverness.com:正宁县| www.fitnessghost.com:独山县| www.pchelpdoc.com:阳高县| www.duchang999.com:平阴县| www.zuluanimazione.com:大竹县| www.royal-factory.com:张掖市| www.ebikemoto.com:沈丘县| www.altermolfetta.com:辰溪县| www.felixcaneinc.com:杭州市|