作为项目引用调用时,WPF 框架 Uri 不起作用

发布于 2024-11-04 01:17:38 字数 1297 浏览 0 评论 0原文

我在 VS2010 中的 WPF 项目中有一个简单的框架。 Uri 在代码隐藏中调用:

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

现在我正在使用此项目作为另一个项目的参考。 这样的实例来调用 FrameProject

New FrameProjectInstance1

我正在通过使用像现在我收到错误

System.IO.IOException 未处理 消息=无法找到资源“pages/pagetranslate.xaml”。 来源=PresentationFramework 堆栈跟踪: 在 MS.Internal.AppModel.ResourcePart.GetStreamCore(FileMode 模式,FileAccess 访问) 在System.IO.Packaging.PackagePart.GetStream(FileMode模式,FileAccess访问) 在 System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream() 在 System.IO.Packaging.PackWebResponse.GetResponseStream() 在 System.IO.Packaging.PackWebResponse.get_ContentType()

   ... 

我尝试过: http://msdn.microsoft.com/en-us/library/aa970069.aspx#Y5978 没有运气。总是遇到同样的错误。还带有:

        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 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你是暖光i 2024-11-11 01:17:38

我发现这对我有用。希望它也能帮助其他人:

  '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

这样调用:

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

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")
紫南 2024-11-11 01:17:38

也许你应该使用这个:“MyDll;/Pages/PageTranslate.xaml”?其中 MyDll 是 FrameProject 的 dll 名称。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文