Pergunta

I have a Page, and MediaElement stretched on it:

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <MediaElement x:Name="Player" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch" Source="myvideo.mp4"/>
</Grid>

When i open the page it looks like this:

enter image description here

Thats because video isn't the same size as Page.

Ok, i want to stretch the content i set the ViewBox:

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <Viewbox Stretch="UniformToFill" StretchDirection="Both">
    <MediaElement x:Name="Player" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch" Source="myvideo.mp4"/>
    </Viewbox>
</Grid>

But now logo (center of the video) is not on center of the page. How to achieve it?

Now it looks like this:

enter image description here

The offset from center is only Vertical, Horizontally looks like logo remains on center.

There is a build in Stretch option in MediaElement, but somewhy when i set it it says: Unknown member 'Stretch' on element MediaElement

Foi útil?

Solução 2

The answer was to set VerticalAligment="Center" of ViewBox element

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Viewbox VerticalAligment="Center" Stretch="UniformToFill" StretchDirection="Both">
<MediaElement x:Name="Player" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch" Source="myvideo.mp4"/>
</Viewbox>

Outras dicas

It seems to work the way you want it when you set it up like this:

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <MediaElement x:Name="Player" Stretch="UniformToFill Source="myvideo.mp4"/>
</Grid>

From the MS docs it looks like Stretch is only supported in Windows 8.1: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.mediaelement.stretch.aspx

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top