views:

39

answers:

1

There is a MediaElement in my silverLight4 Application that plays videos. There are also other controls in the form (listbox, buttons etc...). When vieweing a Video, i want the option to switch to Fullscreen, but only the video and not all the form (something like youtube), is there a way to switch just the 'MediaElement' control to fullscreen?

A: 

Make your MediaElement the RootVisual of the app. Since you can't change the RootVisual once it's assigned you need to do something like so

private MainPage _mainPage = new MainPage();
private MediaElement _media = new MediaElement(); 

private void Application_Startup(object sender, StartupEventArgs e)
{
    Grid grid = new Grid();
    grid.Children.Add(_mainPage);
    this.RootVisual = grid;
}

public void FullscreenVideo()
{
    (this.RootVisual as Grid).Children.Clear();
    (this.RootVisual as Grid).Children.Add(_media);
    Application.Current.Host.Content.IsFullScreen = true;
}

If you call FullscreenVideo it should load your MediaElement into a fullscreen window

Stephan
thanks, but not very clear, where to call FullscreenVideo() from? i can't seem to see it from another page.
Zee99
When you switch the app to fullscreen now instead just change it to call `(Application.Current as App).FullscreenVideo();`
Stephan
Thanks, but im receiving this error when i click on the fullscreen button (ELement is already the child of another element). Any ideas?
Zee99
You will need to remove the MediaElement from it's current container before adding it to the `Application.RootVisual`. To be honest with you I'm not sure what the best way to manage this will be. You probably want to do something like passing the _media object to your MainPage and add that `MediaElement` to the MainPage in code. Then before calling `FullscreenVideo()` you need to remove it from the container you added it to and then add it back after you exit fullscreen.
Stephan