Post by donqstuart on May 28, 2016 2:53:31 GMT 10
Hello First time poster- I found myself here thanks to www.youtube.com/watch?v=hMK4Z_WMnxA which is a fantastic tutorial for building a MediaElement media player in VB.Net. I've got one question which I just can't fathom; everything else I've got sorted, there's just one simple thing I haven't worked out. How can I set the visible size of the MediaElement? Ideally I want it to expand to fill the panel that it's contained on on my Windows form. At the moment it's still fixed at the 200x200 set height and width that it starts at, and when I send Size or RenderSize instructions to the MediaElement or its host, they don't seem to have any effect. Any tips would be very welcome indeed. Thanks very much Stuart
|
|
Post by Nathan Lecompte on May 28, 2016 14:52:56 GMT 10
Hey donqstuart, Welcome to the forum - glad you liked the tutorial! From what you've told me so far, try these few things to make the ElementHost fill the panel: Is the MediaElements' HorizontalAlignment and VerticalAlignment set to "Stretch" via the UserControl it's contained in (can be modified via the properties of the MediaElement)? Is the size of the MediaElement the same as the size of the UserControl? Is the Dock of the ElementHost set to fill the panel or is the Anchor of the ElementHost set to "Top, Bottom, Left, Right" (no need to do both, one or the other should work fine; however if you're using the anchor method then the size of the ElementHost would have to be the same as the size of the Panel it's contained in for it to have the same effect as the Dock set to fill)? If it still doesn't seem to be working or this isn't exactly what you'd want it to do then please explain in either further detail or provide some snippets of code you're currently using. Hope this helps!
|
|
Post by Nathan Lecompte on May 28, 2016 15:26:45 GMT 10
Ah, I see what you mean now; turns out that the MediaElement can't re-size according to the size of the UserControl without a container (such as a grid). Try changing the XAML code of the MediaElement (I'm guessing you've kept it the same as in the tutorial) to this (only change the old <MediaElement /> part, not all of the XAML): <Grid> <MediaElement Name="MediaElement1" Stretch="Uniform" /> </Grid>
If you're using the MediaElement to play videos, then I recommend you set the Stretch value to "Uniform"; so the content remains uniform when re-sized. Hope this helps!
|
|
Post by donqstuart on May 29, 2016 0:33:40 GMT 10
Thanks very much for the prompt response.
In the end my solution was slightly different to what you suggested. I didn't need a Grid (perhaps because I've already got the ElementHost docked to a panel on the form?), all I needed to do was take out the explicit width and height settings so that I got:
<MediaElement HorizontalAlignment="Stretch" Name="MediaElement1" VerticalAlignment="Stretch" Stretch="Fill" ClipToBounds="False" />
I had wrongly assumed that the width and height settings were just initial properties that could be adjusted at runtime (like other controls in VB.Net), but it turns out that if you explicitly state them in the XAML, VB.Net won't then allow you to adjust them as you go.
For slightly unusual reasons, "Fill" is more appropriate than "Stretch" for my particular use- there are videos which should explicitly be shown at a different aspect ratio to how they have been rendered- but you're right that in 99.9% of cases Stretch='Uniform' would be more appropriate.
Thanks again for the swift reply, it's really much appreciated.
|
|