C# 用视频处理MediaElement

C# 用视频处理MediaElement,c#,windows-8,mediaelement,windows-8.1,C#,Windows 8,Mediaelement,Windows 8.1,我有一个页面,上面伸展着MediaElement: <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> <MediaElement x:Name="Player" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Str

我有一个页面,上面伸展着MediaElement:

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

当我打开页面时,它如下所示:

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

这是因为视频和页面大小不一样

好的,我想拉伸我在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>

但现在徽标(视频的中心)不在页面的中心如何实现它?

现在看起来是这样的:

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

从中心的偏移量只是垂直的,水平的看起来像标志保持在中心


MediaElement中有一个内置的拉伸选项,但当我设置它时,它会说:元素MediaElement上的未知成员“拉伸”

当您这样设置它时,它似乎按照您想要的方式工作:

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


答案是设置ViewBox元素的verticaligment=“Center”

<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>


不,答案是ViewBox的垂直照明=“中心”要简单得多