Infobox in WPF Bing Maps

I recently started doing some things in WPF, and I came up with the idea of ​​integrating maps into my application. I tried some things with Google Maps, but the possibilities are not that great, so after a while I abandoned Google Maps in WPF.

After some time, I came across Bing Maps. It looked more promising than Google Maps for use with WPF. I started playing with Bing Maps and the possibilities are great!

However, when I tried to put the button on the map, it did not immediately become clear to me how to add the info box to the click when it hangs above it. I found some examples of how to do this, but this requires the procedural code related to xaml. I was really looking for a method without using procedural code.

Is it possible to add infobox to pushpin using only xaml? Or does anyone have a good alternative method on how to do this?

However, there is a tooltip feature, but I really did not look for it. I really searched for the style of the Google Maps buttons (if available).

+5
source share
1 answer

Assuming that I understand correctly what you want, I think the short answer is: Sorry, but it's impossible to add a Google Maps style info window to a pushpin with only XAML. However, I will try to help if I can.

Disclaimer: I played with the Bing Maps control for Silverlight, so hopefully this applies to the WPF control version as well.

, , , - ( ), , , , .

, -, . Pushpins, , .

Bing Map with custom ToolTip

ToolTip, StaticResource, , , , :

<Style x:Key="MyToolTipStyle" TargetType="ToolTip">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <Border CornerRadius="5" BorderBrush="Black" BorderThickness="2" Background="#5c87b2">
                    <ContentPresenter Margin="5">
                        <ContentPresenter.Content>
                            <StackPanel Margin="5" MaxWidth="400">
                                <TextBlock Text="{Binding Name}" FontWeight="Bold" FontSize="16" Foreground="White" TextWrapping="Wrap"/>
                                <TextBlock Text="{Binding Description}" Foreground="White" TextWrapping="Wrap"/>
                            </StackPanel>
                        </ContentPresenter.Content>
                    </ContentPresenter>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

, :

<maps:Map>
    <maps:MapItemsControl ItemsSource="{Binding SearchResultsManager.Items}">
        <maps:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <maps:Pushpin Location="{Binding Location}" Cursor="Hand" MouseLeftButtonUp="Pushpin_MouseLeftButtonUp">
                    <ToolTipService.ToolTip>
                        <ToolTip Style="{StaticResource MyToolTipStyle}" />
                    </ToolTipService.ToolTip>
                </maps:Pushpin>
            </DataTemplate>
        </maps:MapItemsControl.ItemTemplate>
    </maps:MapItemsControl>
</maps:Map>

, , .

private void Pushpin_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    // Get a reference to the object that was clicked.
    var clickedSearchResult = (sender as FrameworkElement).DataContext as SearchResultViewModel;

    // Do something with it.
}

, , , , . , , . , , , , #/VB.

, Pushpin, / . VisualStateManager, XAML. #/VB .

, !

+8

All Articles