Kodek
Kodek

Reputation: 179

Could not find a part of path when using ImageBrush

I get that error if i try to run my "application". In fact that's an empty window with background.

<Window x:Class="NWN_Tsuki.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="831" Width="875">
<Window.Background>
    <ImageBrush Stretch="None" ImageSource="pack://siteoforigin:,,,/Resources/Book.png" />
</Window.Background>
<Grid/>
</Window>

That's all my app. And i get error. If i set absolute path to image - all working fine.

I tried to google, i searched same topics here and tried to do what worked for others - there are no progress. Just one window. Just one background image in resourses added through wizard.

Visual Studio 2013, Windows 7 Ultimate x64

Upvotes: 1

Views: 4142

Answers (3)

Dave
Dave

Reputation: 8461

I have experienced this. It turned out, the .png was corrupted. When I navigated to the folder in File Explorer, I saw the following

enter image description here

I think the mkelem is something to do with our source control, so maybe it was that which corrupted it, regardless, this is why some people may get this error message.

Upvotes: 1

stromms
stromms

Reputation: 161

I haven't tried adding an image thru a wizard, what I do is create a "Resources" folder in my project. Then I add the image in said folder. Set the property of the image to Copy Always or Copy If New. Then do:

<ImageBrush Stretch="None" ImageSource="../Resources/Book.png" />

If anything, Book.png is just not getting copied.

EDIT: IMPORTANT Also make sure to change the Book.png's Build Action to Resource

Upvotes: 3

Alex Butenko
Alex Butenko

Reputation: 3764

First of all, I think you can just write ImageSource="Resources/Book.png" and it will work.

Second, if you want with "pack://", you suppose to write it ImageSource="pack://application:,,,/Resources/Book.png"

Yet another way - ImageSource="ProjectName;component/Resources/Book.png" where ProjectName is the name of the project where you keep you picture. You can even concatenate all this if you need ImageSource="pack://application:,,,/ProjectName;component/Resources/Book.png"

Upvotes: 1

Related Questions