开发者

WPF Frame Uri does not work when calling as project reference

I have a simple frame in my WPF project in VS2010. The Uri is called in codebehind with:

Dim U As New Uri("Pages/PageTranslate.xaml", UriKind.Relative)

Now I am using this project as reference in another project. I am calling the FrameProject by using a instance like

New FrameProjectInstance1

Now I receive an error开发者_开发百科:

System.IO.IOException was unhandled Message=Cannot locate resource 'pages/pagetranslate.xaml'. Source=PresentationFramework StackTrace: at MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode mode, FileAccess access) at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access) at System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream() at System.IO.Packaging.PackWebResponse.GetResponseStream() at System.IO.Packaging.PackWebResponse.get_ContentType()

   ... 

I've tried: http://msdn.microsoft.com/en-us/library/aa970069.aspx#Y5978 without luck. Always got the same error. Also with:

        U = New Uri("/Pages/PageTranslate.xaml", UriKind.RelativeOrAbsolute)
        U = New Uri("pack://application:,,,Pages/PageTranslate.xaml", UriKind.RelativeOrAbsolute)
        U = New Uri("pack://application:,,,/Pages/PageTranslate.xaml", UriKind.Absolute)


I found out this is working for me. Hope it helps other too:

  'In Application.Xaml
  Public Shared NavigationService As NavigationService 'set when MainWindow.xaml is Loaded 

  Public Shared Function NavigationUri(ByVal Path As String) As Uri
    Dim asm As System.Reflection.Assembly
    asm = System.Reflection.Assembly.GetExecutingAssembly

    Dim U As Uri
    U = New Uri("pack://application:,,,/" & asm.GetName().Name & ";component/" & Path, UriKind.Absolute)
    Return U
End Function

Calling that way:

Application.NavigationService.Source = Application.NavigationUri("Pages/PageAutoTranslation.xaml")


May be you should use this: "MyDll;/Pages/PageTranslate.xaml"? Where MyDll is dll's name of your FrameProject.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜