WPF UserControl运行时错误:无法在UserControl中找到图标的路径

问题描述 投票:0回答:1

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

c# wpf wpf-controls
1个回答
0
投票

我不知道为什么它还不能与siteoforigin一起使用,但是它却与uri中的Application一起使用。

    Icon="pack://Application:,,,/Resources/test_32.png"
© www.soinside.com 2019 - 2024. All rights reserved.