【问题标题】:WPF Frame Uri does not work when calling as project referenceWPF Frame Uri 在作为项目引用调用时不起作用
【发布时间】:2011-08-14 16:51:31
【问题描述】:

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

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

现在我在另一个项目中使用这个项目作为参考。我使用像

这样的实例来调用 FrameProject
New FrameProjectInstance1

现在我收到一个错误:

System.IO.IOException 未处理 Message=找不到资源“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)

【问题讨论】:

    标签: wpf url uri frame relative-path


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 感谢艾弗津。你的想法很好。只是语法和如何不完全那样工作。我找到了解决方案并将其发布。谢谢。
      猜你喜欢
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 2021-11-26
      • 1970-01-01
      • 1970-01-01
      • 2016-12-25
      相关资源
      最近更新 更多