UriFormatException : Invalid URI: Invalid port specified

后端 未结 3 1157
借酒劲吻你
借酒劲吻你 2020-12-23 16:01

The assembly qualified string used as a parameter below for a Uri works in XAML, but gives me the error shown when used in code.

I tried every kind of UriKind with

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 16:38

    If you're seeing this error in a Windows Store / WinRT project:

    I wasn't able to use the "pack://" syntax at all when trying to load a resource in my C# app. What worked was ms-appx:// syntax of this kind:

    ms-appx://[project folder]/[resource path]
    

    For example, I wanted to load a resource dictionary named "styles.xaml" from a folder "core". This URI ended up working for me:

    dictionary.Source = new System.Uri("ms-appx:///core/styles.xaml");
    

    Even though the question specified WPF, the problem seemed extremely similar but ended up having a completely different solution, which took a while to find, and existing answers didn't help at all.

    Again, this solution does not apply to WPF

提交回复
热议问题