【发布时间】:2014-07-29 00:27:09
【问题描述】:
我正在使用来自 Windows Phone 8.1 WinRT 的新 api 的 MapControl。我想要实现的是在点击的图钉上方显示一个简单的工具提示(带有关于图钉位置的附加信息)。最好我希望该工具提示是UserControl。
遗憾的是,api 没有内置支持,web.xml 也没有简单的解决方案。到目前为止,人们习惯使用 WindowsPhoneToolkit 库中的 ContextMenu 功能,不幸的是它仅适用于 Silverlight。 Flyout 也不是一个选项。 ToolTipService 也不能正常工作。
到目前为止,我所做的是连接到图钉的 Tapped 事件,然后在代码隐藏中添加一个子图钉的Grid - 但它看起来不是一个好选择,它使我的图钉移动。
代码 XAML:
<maps:MapControl x:Name="Map">
<maps:MapItemsControl ItemsSource="{Binding Pushpins}">
<maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<Grid x:Name="MyGrid"
Tapped="UIElement_OnTapped">
<Grid.RowDefinitions>
<RowDefinition Height="*" /> // if grid is tapped I will insert a UserControl to that row
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Grid.Row="1"
Width="24"
Height="24"
Source="{Binding Converter={StaticResource PushpinLogoConverter}}"
maps:MapControl.Location="{Binding Location}"
maps:MapControl.NormalizedAnchorPoint="1,0.5" />
</Grid>
</DataTemplate>
</maps:MapItemsControl.ItemTemplate>
</maps:MapItemsControl>
</maps:MapControl>
后面的代码:
private void UIElement_OnTapped(object sender, TappedRoutedEventArgs e)
{
var grid = (Grid)e.OriginalSource;
var tooltipBase = new TooltipBase();
grid.Children.Add(tooltipBase);
tooltipBase.SetValue(Grid.RowProperty, 0);
}
你能告诉我是否有更好的方法吗?当我添加一个孩子时,如何让MyGrid不动?提前感谢您的帮助,我真的很感激!
【问题讨论】:
标签: c# xaml user-controls winrt-xaml windows-phone-8.1