Reputation: 14212
I had created a User Control in my main Project Originally. I have now created a new Project that uses the WPF User Control Library Template and moved my control there.
The issue I am having, is my control uses images as the content for buttons. I have moved the images along with the controls into the new project, but I cannot get the Pack URIs to work. The Control and the images both reside in the same folder of the project called MyControl
an the new Project name is MyControls
.
I have tried:
<Button Name="Button1" ToolTip="Button1" Click="Button1Action">
<Image Source="pack://application:,,,/MyControl/image1.png" />
</Button>
and
<Button Name="Button1" ToolTip="Button1" Click="Button1Action">
<Image Source="pack://application:,,,MyControls;/MyControl/image1.png" />
</Button>
I also tried adding the images to the Resources.resx
file, then in the Code Behind converting that to a BitmapSource
, creating an Image control, setting its source to the BitmapSource
, and then setting the Button.Content
to the Image
. I assume that since the png has a transparent background, it was messed up in the process, it was displayed with a black background using this method.
The Build Action for the Image in the project is set to Resource
, so I assume I am just missing the correct Pack string.
Upvotes: 2
Views: 465
Reputation: 30498
Your second pack uri was close, but you missed one word (and a slash)! It should be
<Image Source="pack://application:,,,/MyControls;component/MyControl/image1.png" />
Upvotes: 4