2010-11-22 66 views
1

我有一個SilverLight項目,在項目中我有一個PDF文檔。HyperlinkBut​​ton內部來源

如何創建PDF文檔的引用,以便在HyperlinkBut​​ton上單擊打開?構建操作應該在PDF文檔上做什麼?

在此先感謝。

回答

0

我認爲,隨着HyperlinkBut​​ton招是行不通的,因爲你將導航涉及到silverlight項目,但沒有關聯的web項目。

您可以使用文件下載。我建議Interlink Upload Download

祝你好運。

+0

謝謝,沒有意識到這將是一個複雜的引用一個簡單的文件在Silverlight項目。但公平是公平的,你不能指望一切都很簡單。 :-) – RvG 2010-11-22 10:48:58

+0

我不知道這是如何幫助,一旦它下載了你對它做了什麼呢? – AnthonyWJones 2010-11-24 08:02:50

0

您不應該將其包含在Silverlight項目中。而應將其作爲標準Web內容包含在關聯的Web項目中。例如,如果你將它放在web項目名爲「文檔」文件夾中,然後你的按鈕看起來像: -

<HyperlinkButton Content="LaunchPDF" TargetName="_blank" NavigateUri="/Documents/MyDoc.pdf" /> 
+0

感謝,也想過,但我寧願在文件我的Silverlight項目。因爲我希望能夠獨立於網站來重新分配xap文件。 – RvG 2010-11-22 10:34:20

+0

@RvG:當它在Xap中時,你將如何處理它? Silverlight無法直接使用PDF內容> – AnthonyWJones 2010-11-24 08:01:56

+0

這個想法只是爲了顯示文檔,我們使用PDF文件作爲用戶文檔。正如我以前寫的,這個想法是,在XAP項目中擁有該文檔,當重新分發應用程序時,您將始終有一個鏈接。 – RvG 2010-12-02 07:09:20

0

可以使用的ICommand:

ViewModel.cs:

 private static string _ApplicationUrl; 
    public static string ApplicationUrl 
    { 
     get 
     { 
      if (_ApplicationUrl == null) 
      { 
       _ApplicationUrl = Application.Current.Host.Source.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Port, UriFormat.UriEscaped); 
       //_ApplicationUrl = HtmlPage.Document.DocumentUri.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Port, UriFormat.UriEscaped); 
      } 
      return _ApplicationUrl; 
     } 
    } 

    private RelayCommand<string> _WebUriCommand; 
    public RelayCommand<string> WebUriCommand 
    { 
     get 
     { 
      if (_WebUriCommand == null) 
      { 
       _WebUriCommand = new RelayCommand<string>((p) => { HtmlPage.Window.Navigate(new Uri(ApplicationUrl + p), "_blank"); }); 
      } 
      return _WebUriCommand; 
     } 
    } 

View.xaml:

<HyperlinkButton Command="{Binding WebUriCommand}" CommandParameter="/Documents/MyDoc.pdf" Content="Download"/> 
相關問題