I have some trouble with uri in my C# code
This is working:
var uri = new Uri("d:/Programozas dotNet/Ugyfel/Ugyfel.ClientWpf/Skins/MainSkin.xaml");
But unfortunately non of these:
var uri = new Uri("/Skins/MainSkin.xaml", UriKind.Relative);
var uri = new Uri("pack://application:,,,/Skins/MainSkin.xaml");
var uri = new Uri("Ugyfel.ClientWpf;/Skins/MainSkin.xaml", UriKind.Relative);
IOException: Cannot locate resource 'skins/mainskin.xaml'.
How can I use relative uri insted of absolute?
That was a stupid misstake. The correct method is without leading "/"
var uri = new Uri("Skins/MainSkin.xaml", UriKind.Relative);
Thank you for your effort
Relative Url (in WPF or any other desktop application) is relative to Environment.CurrentDirectory. Usually this is the folder where your exe resides, but it can be different in VS Unit Testing environment.
I assume that in your project you have a folder called "Skins", and probably your exe is in "bin\debug".
The easiest thing to do is to set the MainSkin.xaml to be copied to the output directory (in the file properties) so you can refer to it with the name only with no path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With