【发布时间】:2018-06-26 09:02:22
【问题描述】:
我可以毫无问题地添加 PNG 图像来更改默认的 MapIcon 图像,但是一旦我尝试使用 SVG,应用程序就会崩溃,并出现“application.exe 已退出,代码 -529697949 (0xe06d7363) 'Microsoft C++ Exception'”。
我知道 SvgImageSource 类,我可以在应用程序的其他区域使用它来渲染 SVG 图像,但是当尝试将 SVG 添加到 MapIcon.Image 时;这是 IRandomAccessStreamReference 类型,它不起作用。我只是想知道这是否是 API 的限制,在 MapIcon 上显示自定义图像时我是否应该只使用位图而不是 SVG?
我在下面添加了一个快速失败的示例。
MainPage.xaml:
<Page xmlns:my="using:Windows.UI.Xaml.Controls.Maps"
x:Class="TestMapWithSVGForMapIcon.MainPage"
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"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<my:MapControl Loaded="{x:Bind _viewModel.AddMapIcon}"/>
</Grid>
</Page>
MainPage.xaml.cs:
public sealed partial class MainPage : Page
{
private MainViewModel _viewModel;
public MainPage()
{
InitializeComponent();
_viewModel = new MainViewModel();
DataContext = _viewModel;
}
}
MainViewModel.cs:
public class MainViewModel
{
protected MapControl Map { get; set; }
public void AddMapIcon(object sender, RoutedEventArgs e)
{
if (sender is MapControl map)
{
Map = map;
}
var mapIcon = new MapIcon
{
Location = new Geopoint(new BasicGeoposition()
{
Latitude = 53.795452,
Longitude = -4.304733
}),
//works Ok with .png files
Image = RandomAccessStreamReference.CreateFromUri(new Uri($"ms-appx:///Assets/Hazard_H1.svg")),
};
Map.MapElements.Add(mapIcon);
}
}
【问题讨论】:
标签: c# xaml svg windows-10-universal uwp-maps