I'm trying to make a bit of code like this work:
Type pageType = typeof(Page1);
Uri pageUri = GetPackUriForType(pageType);
The problem is the GetPackUriForType method - I can't find anything in the .NET framework that will do this.
In the .g.cs files that are built at compile time, the URI is embedded as part of the InitializeComponent code:
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/PageCollection;component/pages/page1.xaml", System.UriKind.Relative);
#line 1 "..\..\..\Pages\Page1.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
#line default
#line hidden
}
But that URI doesn't appear to be public anywhere. I know IUriContext can be used at runtime, but I'm trying to avoid instantiating the type just to get its URI.
The only solution I can come up with is to try to assume the URI using conventions based on the namespace. But I'd like a less brittle solution.