开发者

HyperlinkButton to internal source

开发者 https://www.devze.com 2023-01-26 01:33 出处:网络
I have a SilverLight p开发者_Go百科roject, in the project I have a PDF document. How to create a reference to the pdf document so it will open with a click on a HyperlinkButton? What should the build

I have a SilverLight p开发者_Go百科roject, in the project I have a PDF document.

How to create a reference to the pdf document so it will open with a click on a HyperlinkButton? What should the build action be on the PDF document?

Thanks in advance.


I think, the trick with HyperlinkButton won't work, because you will navigate relate to silverlight project but not associated web project.

You can use file download. I recomend Interlink Upload Download.

Good luck.


You should not include it in the Silverlight project. Instead include it in the associated web project as standard web content. For example if you place it in the web project in a folder called "Documents" then your button will look like:-

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


You can use 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"/>
0

精彩评论

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