国产午夜男女在线|欧美日本一道高清国产|亚洲日韩乱码中文字幕|麻豆国产97在线精品一区|日韩一区2区三区另类图片|亚洲精品国产99在线观看|亚洲国产午夜福利精品大秀在线|一级做a爰片性色毛片免费网站

您當(dāng)前的位置 :寧夏資訊網(wǎng) > 財(cái)經(jīng) >  內(nèi)容正文
投稿

C# WPF Bing地圖展示

寧夏資訊網(wǎng) 2020-03-23 06:38:22 來(lái)源: 閱讀:-

微信公眾號(hào):Dotnet9,網(wǎng)站:Dotnet9,問(wèn)題或建議,請(qǐng)網(wǎng)站留言; 如果您覺(jué)得Dotnet9對(duì)您有幫助,歡迎贊賞

內(nèi)容目錄

  1. 實(shí)現(xiàn)效果
  2. 業(yè)務(wù)場(chǎng)景
  3. 編碼實(shí)現(xiàn)
  4. 本文參考
  5. 源碼下載

1.實(shí)現(xiàn)效果

2.業(yè)務(wù)場(chǎng)景

Bing地圖控件的使用

3.編碼實(shí)現(xiàn)

3.1 添加Nuget庫(kù)

站長(zhǎng)使用 .Net Core 3.1 創(chuàng)建的WPF工程,創(chuàng)建“BingMap”解決方案后,需要添加三個(gè)Nuget庫(kù):MaterialDesignThemes、MaterialDesignColors和Bing WPF地圖控件Microsoft.Maps.MapControl.WPF,其中Bing地圖控件是.net framework 4.6.1版本,所以項(xiàng)目使用framework版本要好點(diǎn),其實(shí)影響也不大。

MaterialDesign控件庫(kù)

Bing WPF地圖控件Microsoft.Maps.MapControl.WPF


注意 使用bing map地圖控件需要注冊(cè)開(kāi)發(fā)者賬號(hào),站長(zhǎng)只是按視頻教程敲的代碼,VS 2019設(shè)計(jì)器能正常加載地圖,但運(yùn)行時(shí)會(huì)有提示請(qǐng)注冊(cè)開(kāi)發(fā)者賬號(hào),否則地圖無(wú)法正常顯示

需要注冊(cè)Bing地圖開(kāi)發(fā)者賬號(hào)


3.2 工程結(jié)構(gòu)

不需要截圖,只修改了兩個(gè)文件,App.xaml添加MD控件樣式,MainWindow主窗口實(shí)現(xiàn)效果。

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地圖控件,設(shè)置地圖屬性等:

<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 大神的學(xué)習(xí)視頻:Bing Maps
開(kāi)源控件庫(kù):MaterialDesignInXamlToolkit
本站對(duì)MD開(kāi)源控件庫(kù)的介紹:控件介紹

5.代碼下載

文中代碼已經(jīng)全部給出。


除非注明,文章均由 Dotnet9 整理發(fā)布,歡迎轉(zhuǎn)載。

轉(zhuǎn)載請(qǐng)注明本文地址:https://dotnet9.com/6814.html

(正文已結(jié)束)

推薦閱讀:蘋(píng)果手機(jī)驗(yàn)機(jī)軟件

免責(zé)聲明及提醒:此文內(nèi)容為本網(wǎng)所轉(zhuǎn)載企業(yè)宣傳資訊,該相關(guān)信息僅為宣傳及傳遞更多信息之目的,不代表本網(wǎng)站觀點(diǎn),文章真實(shí)性請(qǐng)瀏覽者慎重核實(shí)!任何投資加盟均有風(fēng)險(xiǎn),提醒廣大民眾投資需謹(jǐn)慎!

網(wǎng)站簡(jiǎn)介 - 聯(lián)系我們 - 營(yíng)銷(xiāo)服務(wù) - 老版地圖 - 版權(quán)聲明 - 網(wǎng)站地圖
Copyright.2002-2019 寧夏資訊網(wǎng) 版權(quán)所有 本網(wǎng)拒絕一切非法行為 歡迎監(jiān)督舉報(bào) 如有錯(cuò)誤信息 歡迎糾正