简体   繁体   English

媒体元素在底部WPF上被剪切

[英]Media Element is cut on the bottom WPF

I have issue with displaying video inside MediaElement. 我在MediaElement中显示视频时遇到问题。

I tries to put MediaElement inside Grid so I can take his size: 我尝试将MediaElement放在Grid中,以便可以使用他的大小:

<Grid Grid.Row="1" Name="RootMediaElement"
      Margin="10 10 10 10">
    <MediaElement
    ClipToBounds="True"
    x:Name="MediaPlayer"
    HorizontalAlignment="Center"
    Stretch="UniformToFill"
    LoadedBehavior="Manual"
    Source="{Binding Source}">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="MediaEnded">
                <i:InvokeCommandAction Command="{Binding MediaEndedCommand}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </MediaElement>
</Grid>

I also set ClipToBound property to true which didn't help also. 我还将ClipToBound属性设置为true,这也没有帮助。 I can't see bottom part of video. 我看不到视频的底部。 Also there is SizeChanged event which fires at the begining and I tried to set width and height manually as below : 另外还有SizeChanged事件,该事件会在开始时触发,我尝试如下手动设置宽度和高度:

 MediaPlayer.SizeChanged += (sender, args) =>
            {
                var x = sender as MediaElement;
                MediaPlayer.Height = RootMediaElement.ActualHeight;
                MediaPlayer.Width = RootMediaElement.ActualWidth;

            };

I am reading so much and cant find solution. 我读了太多书,找不到解决方法。 Does anyone know ? 有人知道吗 ?

EDIT: Parent grid setup 编辑:父网格设置

<Grid>
<Grid.RowDefinitions>
            <RowDefinition Height="105" /> <!-- First row-->
            <RowDefinition Height="895" /> <!-- Second row -->
</Grid.RowDefinitions>

<!-- Media is places inside RootMediaElement Grid which take whoole second row -->
</Grid>

I've tested your xaml and you probably want to add this 我已经测试过您的xaml,您可能要添加它

VerticalAlignment="Center"

to your MediaElement, but keep in mind that your video will get "zoomed" in. 到MediaElement,但请记住,视频将被放大

EDIT : You specified a height value for both rows that means they wont change when resizing the window so you should either 编辑:您为两行指定了一个高度值,这意​​味着它们在调整窗口大小时不会改变,因此您应该

set your window minimum height to row 1 height + row 2 height + Margin (RootMediaGrid) (1030px): 将窗口的最小高度设置为第1行的高度+第2行的高度+边距(RootMediaGrid) (1030px):

MinHeight="1030"

or just set the second row height to: 或仅将第二行高度设置为:

<RowDefinition Height="*" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM