我无法在页面上显示矢量图像
这应该有用,不应该吗?
<ContentControl>
<ContentControl.Resources>
<ResourceDictionary Source="./Assets/vectorImage.xaml"></ResourceDictionary>
</ContentControl.Resources>
</ContentControl>
我担心问题出在xaml图像文件中,该文件是使用Inkscape从位图创建的。 vectorImage.xaml非常大(136KB)所以我不会复制整个文件,但它会像这样开始
<?xml version="1.0" encoding="UTF-8"?>
<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform">
<Canvas Name="svg2985" Width="126" Height="198">
<Canvas.Resources/>
...
编辑:
<ResourceDictionary Source="./Assets/vectorImage.xaml"></ResourceDictionary>
有红色下划线和提示:预期ResourceDictionary的继承者。
当我运行应用程序时,我得到了以下优点
An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in app.exe but was not handled in user code
WinRT information: Failed to assign to property 'Windows.UI.Xaml.ResourceDictionary.Source'. [Line: 134 Position: 68]
编辑:
我忘记提到的一件事是该项目是Windows商店应用
答案 0 :(得分:2)
1)将x:Key
分配给ViewBox
,这最有可能导致您的错误
<ViewBox x:Key="MySvgImage" ....>
2)将资源移至ContentControl
以上至少1级,例如移至Window
资源,如下所示:
<Window.Resources>
<ResourceDictionary Source="./Assets/vectorImage.xaml"/>
</Window.Resources>
3)像这样改变ContentControl
:
<ContentControl Content="{StaticResource MySvgImage}"/>
4)如果这真的是vectorImage.xaml
ResourceDictionary
的开始,那么它应该像这样开始和结束:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Viewbox x:Key="MySvgImage">
<Canvas Width="126" Height="198">
...
</Canvas>
</Viewbox>
</ResourceDictionary>