【问题标题】:WPF - My relative path isn't working in my XAML interface, why?WPF - 我的相对路径在我的 XAML 界面中不起作用,为什么?
【发布时间】:2019-07-15 17:36:06
【问题描述】:

我正在开发 WPF/XAML 接口。使用 SharpVector.Reloaded 包,我想在 Image 组件中显示 SVG 图像文件。源文件位于我的硬盘上。

如果我使用文件的绝对路径:

<Image x:Name="imImage" Grid.Column="1" Source="{svgc:SvgImage Source=W:/Labo/WPF/SVG/SVG/Resources/Images/Ghost.svg}"/>

一切正常,图像可见。

现在我想把路径变成相对的。我尝试了所有我能想到的方法,但没有办法!甚至以下代码,通常应该与例如源属性,在这里不起作用:

<Image x:Name="imImage" Grid.Column="1" Source="{svgc:SvgImage Source=pack://siteoforigin:,,,/Resources/Images/Ghost.svg}"/>

这样做我会得到一个包含 9 个错误的列表:

Error   XDG0052 The unnamed argument "" must appear before named arguments. SVG MainWindow.xaml 18  
Error   XLS0112 Expected ''.    SVG MainWindow.xaml 18  
Error   XLS0414 The type '' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.    SVG MainWindow.xaml 18  
Error   XLS0112 Expected ''.    SVG MainWindow.xaml 18  
Error   XLS0414 The type '' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.    SVG MainWindow.xaml 18  
Error   XLS0112 Expected ''.    SVG MainWindow.xaml 18  
Error   XLS0414 The type '' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.    SVG MainWindow.xaml 18  
Error   XLS0112 Expected '}'.   SVG MainWindow.xaml 18  
Error   XLS0112 Expected '

那么有人可以解释一下我在这里做错了什么,以及在上述上下文中声明相对路径的秘密是什么?

另外一个问题是,为什么 WPF 需要使相对路径使用起来很复杂?

【问题讨论】:

    标签: c# wpf xaml url relative-path


    【解决方案1】:

    您需要在包 URI 周围加上单引号。

    XAML 解析器没有意识到您正在尝试将 Source 设置为所有这些,因此您会收到错误。

    <Image x:Name="imImage" Grid.Column="1" Source="{svgc:SvgImage Source='pack://siteoforigin:,,,/Resources/Images/Ghost.svg'}"/>
    

    我刚刚试了一下,效果很好。

    【讨论】:

      猜你喜欢
      • 2022-01-07
      • 2014-10-08
      • 2013-03-21
      • 2020-03-27
      • 1970-01-01
      • 2014-11-20
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多