i trying have mediatimeline bind uri so:
<usercontrol.resources> <storyboard x:key="mystoryboard"> <mediatimeline storyboard.targetname="mymediaplayer" source="{binding mediasource}" repeatbehavior="forever" /> </storyboard> </usercontrol.resources> <usercontrol.triggers> <eventtrigger routedevent="frameworkelement.loaded"> <beginstoryboard storyboard="{staticresource mystoryboard}" /> </eventtrigger> </usercontrol.triggers> <grid> <mediaelement x:name="mymediaplayer" /> </grid>
however, when this, says need "must specify uri." dispatcher exception. in viewmodel, have property like:
public uri mediasource { { return _mediasource; } set { if (_oscilloscopesource != value) { _mediasource= value; onpropertychanged("mediasource"); } } }
it seems though when media player loaded, doesn't read source binding. gives?
in constructor, have:
_mediasource = new uri(@"c:\somemovie.mov", urikind.absolute);
thanks.
update
can't work shooting in dark now. moving trigger mediaelement make difference?
<mediaelement x:name="mymediaplayer"> <mediaelement.triggers> <eventtrigger routedevent="frameworkelement.loaded"> <beginstoryboard storyboard="{staticresource mystoryboard}" /> </eventtrigger> </mediaelement.triggers> </mediaelement>
i tried out , works me. possible reasons can think of.
- do have datacontext set usercontrol?
- setting _mediasource directly won't call onpropertychanged since you're not setting clr property. set mediasource instead.
- your mediaelement named mymediaplayer , not mymediaplayer targetname. (typo?)
except mediaelement name changed, working xaml identical yours. full code behind file
public partial class usercontrol1 : usercontrol, inotifypropertychanged { public usercontrol1() { initializecomponent(); mediasource = new uri("c:\\c1.mov"); this.datacontext = this; } private uri _mediasource; public uri mediasource { { return _mediasource; } set { _mediasource = value; onpropertychanged("mediasource"); } } public event propertychangedeventhandler propertychanged; private void onpropertychanged(string propertyname) { if (propertychanged != null) { propertychanged(this, new propertychangedeventargs(propertyname)); } } }
Comments
Post a Comment