I kept running into the same issue even after passing the UriKind.Relative
argument. The weird bit was that some of the Uris to XAML pages were working using the method @Magnus suggested - but most of them would throw the:
The format of the URI could not be determined
exception.
Finally, I read up on Pack Uris for WPF applications which solved my problem a 100%.
I started using urls like this:
// ResourceFile is in the Root of the Application
myResourceDictionary.Source =
new Uri("pack://application:,,,/ResourceFile.xaml", UriKind.RelativeOrAbsolute);
or
// ResourceFile is in the Subfolder of the Application
myResourceDictionary.Source =
new Uri("pack://application:,,,/SubFolder/ResourceFile.xaml", UriKind.RelativeOrAbsolute);
Hope this helps someone struggling with the same issues I was facing.