Search code examples
c#xamlwindows-8windows-store-appsmicrosoft-metro

Setting video height/width to actual size


When a new MediaElement is made and inserted into a Grid, it is auto-sized to fit the entire Grid size. How can you adjust the proportions of the MediaElement to mimic the video's original size ?

Grid gDim = new Grid();

MediaElement plr = new MediaElement();
plr.Source = new Uri(my_string); // web link to video file
plr.Play();
plr.Width = plr.NaturalVideoWidth ;
plr.Height = plr.NaturalVideoHeight ;
plr.AreTransportControlsEnabled = true;

gDim.Children.Add(plr);

Setting the NaturalVideoWidth/Height makes the MediaElement go invisible.


Solution

  • Did you try my advice for this case(using Stretch property)?

    <MediaElement Stretch="None"/>