dotnet / dotnet/wpf

pack://application does not respect root folder in Designer view and causes bugged designer when using subfolders

Open
#8,452 0 comments 1 reaction 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

Unless I am misunderstanding something, `pack://application` does not respect root folder path in Designer View, for example:

Imagine you have a UserControl in a subdirectory

```
MainWindow.xaml
| - Sub Folder
| - CustomUserControl.xaml
```

With code like this:
```
Image.Source = new BitmapImage(new Uri($"pack://application:,,,/hello/world.png"));
```

This will work completely fine when running the application, when packaging the application, when opening that CustomUserControl.xaml.

But it will not work when you try open MainWindow.xaml and you'll get the error:

```
Cannot locate resource 'hello/world.png'.
```

It's not respecting the initial `/` to set root. This is a huge pain in the ass as the MainWindow Designer is now completely unusable unless you tick "Only Display Platform Controls"

Anyway to fix this? Or is it a bug?

.NET 7..

### Reproduction Steps

1. Make a custom user control inside a subfolder
2. Add images in a subfolder
3. Try use the images
4. Add the custom user control to the main window
5. the main window designer will now break.

### Expected behavior

I expect this to respect the initial path /xx root.

### Actual behavior

It seems to completely ignore root pathing /hello/world and convert to relative hello/world

### Regression?

_No response_

### Known Workarounds

_No response_

### Impact

_No response_

### Configuration

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.