【发布时间】:2020-05-23 05:39:32
【问题描述】:
在我的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 文件夹下创建,尽管它是项目的一部分。我已将带有Build 操作的 MyIcon.png 文件设置为 Resource 和 Copy to output directory 设置为 Copy if newer
【问题讨论】:
标签: c# wpf wpf-controls