【发布时间】:2017-05-09 14:56:40
【问题描述】:
我正在开发 UWP 导航应用。
我想做什么?
- 我想在 Map 控件上绘制多条(准确地说是 10 条)折线。
- 我想要一个是不同的颜色,而其他的是灰色的。
- 选择任意一条折线后,新选择的折线将变为原色,而其他折线为灰色。类似于地图应用的多条路线,只是在更大的范围内显示运输卡车的移动。
网上到处都有通过 c# 或代码实现折线的方法,但我想通过 XAML 来实现,因为从代码隐藏中添加 10 条折线在事件和不透明度以及标签和名称方面没有太大的灵活性。
我都尝试了什么:
我尝试为 mapElement 创建附加的折线,但该方法的问题是我每次都必须删除并重新创建折线以更改颜色。更多关于这个here。此外,这只是从后面的代码实现折线的一种很好的方式。
我目前在做什么:
我在Page.Resources 中添加了折线的 DataTemplate,如下所示:
<DataTemplate x:Key="PolylineDataTemplate" x:DataType="polyLineData:IPolylinePath">
<Polyline Points="{x:Bind Polyline,Mode=OneWay}" Fill="{x:Bind PolylineColor,Mode=OneWay}" Tag="{x:Bind PolylineTag,Mode=OneWay}" StrokeThickness="{x:Bind PolylineThinkness}" />
</DataTemplate>`
其中 IPolylinePath 定义为:
public interface IPolylinePath
{
SolidColorBrush PolylineColor { get; set; }
int PolylineThinkness { get; set; }
string PolylineTag { get; set; }
IEnumerable<IBasicGeoposition> PolylinePoints { get; set; }
Geopath PolylineGeopath { get; }
PointCollection Polyline { get; }
}`
我的Polyline 属性填充如下:
public PointCollection Polyline
{
get
{
PointCollection returnObject = new PointCollection();
//could have used LINQ but wanted to check if the collection is being populated correctly
foreach (var location in PolylinePoints)
{
returnObject.Add(new Windows.Foundation.Point(location.Latitude, location.Longitude));
}
return returnObject;
}
}
我只是在 MapItems 控件中调用它,如下所示:
<maps:MapControl x:Name="MyMap" >
<maps:MapItemsControl ItemTemplate="{StaticResource PolylineDataTemplate}" ItemsSource="{x:Bind ViewModel.PolylinePoints}"/>
</maps:MapControl>
问题是:
代码运行良好。只是折线不可见。 我以为它只是很小,所以我看不到它。所以我增加了大小和距离,它只是在左上角显示为一个小弧(有一些间距),并且没有被限定或平移。
有人可以帮忙吗?
【问题讨论】:
标签: xaml bing-maps uwp-xaml uwp-maps