简体   繁体   中英

how to make MediaElement to take the whole space of a Grid?

I have a MediaElement in a Grid , and i want it to take the entire space when i play it. here is my code:

<Grid Grid.Row="2" Grid.ColumnSpan="2">
                <Grid.Background>
                    <ImageBrush ImageSource="Resource/bgrdMedia.png" Stretch="None"/>
                </Grid.Background>

                <MediaElement x:Name="VideoControl" LoadedBehavior="Manual" UnloadedBehavior="Stop"
                              Stretch="Uniform" StretchDirection="DownOnly" MediaEnded="Element_MediaEnded"
                               HorizontalAlignment="Stretch" 
                               VerticalAlignment="Stretch"  />

            </Grid>

but i have that: 在此处输入图片说明

any ideas! thanks !

By setting the StretchDirection to DownOnly you are preventing it from scaling upwards:

DownOnly | The content scales downward only when it is larger than the parent. If the content is smaller, no scaling upward is performed.

Source

If you leave the StretchDirection as Both (the default) and have the horizontal and vertical alignments as Stretch (which you have) it should give the result you want.

Note, however, that upscaling may result in a blurred or pixelated image if the original media isn't of sufficiently high resolution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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