views:

16

answers:

1

How do I bind the isEnabled property of play, pause, rewind & forward buttons - for a MediaElement?

I can do this in code of course on MediaOpened & MediaClosed, using a shared dependancy property, but I just wondered if I can bind all the buttons (maybe with a converter) directly to a property of the MediaElement? I thought HasVideo looked like a good bet, but it didn't work.

Thanks in advance, Pedro

A: 

It's not exactly clear where you're stuck, but maybe this helps:

<MediaElement x:Name="mediaElement"/>
<Button x:Name="playButton" IsEnabled="{Binding HasVideo, ElementName=mediaElement}"/>

HTH,
Kent

Kent Boogaart
Thanks for reply HTH but mediaElement.HasVideo and button.isEnabled are both boolean anyway, so I presume no converter would be neaded, particularly not one of visibility.I was just mentioning converters in case it's another (non-bool) property of the MediaElement that people use in this situation. To enable/disable play buttons when there is or isn't media available seems obvious, so I was just wondering if there was a XAML binding. I believe I could do this with triggers too, but it just seemed like an obvious binding thing...Regards,Pedro
Ugh, my brain obviously stopped working. Have updataed my post. Does this answer your question? It's bound in XAML the way you're saying. If not, I'm afraid I don't follow your question.
Kent Boogaart
Thanks for the update Kent, but that's kind of where I came in. That's what seemed most obvious to me too, but in practice it didn't work. Maybe it doesn't use INotifyPropertyChanged. Thanks for the 'sanity check' anyway, it's clearly not an obvious one, so I'll go down the code route for now.