Reputation: 23749
In my WPF User Control
, I have added an icon (shown in the XAML below). But at run time, the InitializeComponent()
call in the following code of the user control gives the error shown below:
UserControl1.xaml.cs
public partial class UserControl1 : System.Windows.Window
{
public UserControl1()
{
InitializeComponent();
}
…………….
}
XAML of the User Control (with icon):
<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>
Error:
DirectoryNotFoundException: Could not find a part of the path 'C:\MyFolder\VSTO\MyProject\bin\Debug\Resources\MyIcon.png'.
Remark:
I noticed that Resources
folder does not get created under Debug
folder although it is part of the project. I have set MyIcon.png file with Build
action as Resource
and Copy to output directory
is set to Copy if newer
Upvotes: 1
Views: 231
Reputation: 9671
I don't why but you should use application
with resources Uri and siteoforigin
with the rest.
You can either change your Uri to:
Icon="pack://application:,,,/Resources/test_32.png"
Or if you want to keep using siteoforigin
than change the build option to "content" instead of "Resource".
Related topics:
What is application's site of origin and when to use it
Upvotes: 1