开发者

Tap to open File

In my app I have links for videos, now when you click on the link IE launches and asks you "Tap to open the File"

I was hoping to over come that, any suggestions?

I am using开发者_如何学Go a simple HyperlinkButton that has an image as its template,


Instead of using the HyperlinkButton's NavigateUri property, you could play the video inside a MediaElement on a separate page.

First, add a new page to your project (MoviePlayer.xaml) and put a single MediaElement in it. Handle the MediaElement.Loaded event in the code behind as well as wire up the OnNavigatedTo and OnNavigatingFrom events:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    var qs = NavigationContext.QueryString["url"];
    MyMovie.Source = new Uri(qs, UriKind.Absolute);
}

protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
{
    MyMovie.Stop();
    base.OnNavigatingFrom(e);
}

private void MyMovie_Loaded(object sender, RoutedEventArgs e)
{
    MyMovie.Position = new TimeSpan(0);
    MyMovie.Play();
}

Then in your main page, change the HyperlinkButton to handle the Click event instead of setting the NavigateUri property, and run something like this:

private void HyperlinkButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
    var button = sender as HyperlinkButton;
    var video = button.DataContext as VideoWrapperClass; // name, url, playing time, etc.
    NavigationService.Navigate(new Uri("/MoviePlayer.xaml?url=" + video.Url, UriKind.Relative));
}

That's all there is too it! With this approach, you could also customize the playback experience if you wanted to, or run some custom animations such as bumpers or advertisement overlays.

If you'd rather see an MVVM-type solution, just ping me on Twitter at @chriskoenig and I'll shoot you over something.

/chris

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜