[英]WPF UserControl Runtime error: Unable to find path of the icon in UserControl
在我的WPF User Control
中,我添加了一個圖標(如下面的 XAML 所示)。 但是在運行時,用戶控件的以下代碼中的InitializeComponent()
調用給出了如下所示的錯誤:
UserControl1.xaml.cs
public partial class UserControl1 : System.Windows.Window
{
public UserControl1()
{
InitializeComponent();
}
…………….
}
用戶控件的 XAML (帶圖標):
<Window x:Class="MyProject.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MyProject"
mc:Ignorable="d"
"d:DesignHeight="450" d:DesignWidth="800"
Icon="pack://siteoforigin:,,,/Resources/test_32.png">
<Grid>
………………
</Grid>
錯誤:
DirectoryNotFoundException:找不到路徑“C:\MyFolder\VSTO\MyProject\bin\Debug\Resources\MyIcon.png”的一部分。
備注:
我注意到雖然它是項目的一部分,但不會在Debug
文件夾下創建Resources
文件夾。 我已將帶有Build
操作的 MyIcon.png 文件設置為Resource
並Copy to output directory
設置為Copy if newer
new
我不知道為什么,但您應該將application
與資源 Uri 和siteoforigin
與 rest 一起使用。
您可以將 Uri 更改為:
Icon="pack://application:,,,/Resources/test_32.png"
或者,如果您想繼續使用siteoforigin
,而不是將構建選項更改為“內容”而不是“資源”。 相關話題:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.