【问题标题】:Handling MediaElement with video使用视频处理 MediaElement
【发布时间】:2013-11-28 16:08:50
【问题描述】:

我有一个页面,MediaElement 在上面拉伸:

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <MediaElement x:Name="Player" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch" 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>

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

现在看起来像这样:

与中心的偏移仅为垂直,水平看起来像徽标仍然在中心。

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

【问题讨论】:

    标签: c# windows-8 mediaelement windows-8.1


    【解决方案1】:

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

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

    从 MS 文档看来,Stretch 仅在 Windows 8.1 中受支持:http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.mediaelement.stretch.aspx

    【讨论】:

    • 不,答案要容易得多 VerticalAligment = ViewBox 的“Center”
    【解决方案2】:

    答案是设置 ViewBox 元素的 VerticalAligment="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>
    

    【讨论】:

      猜你喜欢
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-06
      • 1970-01-01
      • 2014-05-29
      • 1970-01-01
      相关资源
      最近更新 更多