2011-04-28 72 views
1

我在VS2010中的WPF項目中有一個簡單的框架。 Uri被稱爲代碼隱藏與:當調用項目參考時,WPF框架Uri不起作用

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

現在我在另一個項目中使用此項目作爲參考。我用實例調用FrameProject像

New FrameProjectInstance1 

現在我收到一個錯誤:

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

... 

我已經試過: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) 

回答

0

可能你應該使用這個:「MyDll; /Pages/PageTranslate.xaml」? MyDll是您的FrameProject的dll名稱。

+0

感謝Iverzin。你的想法很好。只是語法和如何不以這種方式工作。我找到了解決方案併發布。謝謝。 – goldengel 2011-04-29 08:09:00

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