在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'的一部分。
备注:
[我注意到,虽然Resources
文件夹是项目的一部分,但未在Debug
文件夹下创建。我已经将MyIcon.png文件设置为Build
动作为Resource
,并且Copy to output directory
设置为Copy if newer
我不知道为什么它还不能与siteoforigin
一起使用,但是它却与uri中的Application一起使用。
Icon="pack://Application:,,,/Resources/test_32.png"