我正在開發(fā) WPF/XAML 界面。使用 SharpVector.Reloaded 包,我想在圖像組件內顯示 SVG 圖像文件。源文件位于我的硬盤上。如果我使用文件的絕對路徑:<Image x:Name="imImage" Grid.Column="1" Source="{svgc:SvgImage Source=W:/Labo/WPF/SVG/SVG/Resources/Images/Ghost.svg}"/>一切正常,圖像可見?,F(xiàn)在我想將路徑變?yōu)橄鄬β窂健N覈L試了所有我能想到的方法來做到這一點,但沒有辦法!即使下面的代碼(通常應該與 Source 屬性一起使用)在這里也不起作用:<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 需要使相對路徑使用起來如此復雜?
1 回答

絕地無雙
TA貢獻1946條經驗 獲得超4個贊
您需要在包 URI 兩邊加上單引號。
XAML 解析器沒有意識到您正在嘗試將 Source 設置為所有這些,因此會出現(xiàn)錯誤。
<Image x:Name="imImage" Grid.Column="1" Source="{svgc:SvgImage Source='pack://siteoforigin:,,,/Resources/Images/Ghost.svg'}"/>
我剛剛嘗試過并且有效。
- 1 回答
- 0 關注
- 320 瀏覽
添加回答
舉報
0/150
提交
取消