EventAggregator in views

Topics: Bootstrappers & IoC, Getting Started
Feb 14, 2012 at 2:10 PM

Hi

I want to use the SetSource method of mediaelement control in xaml code behind. I get this stream of this source in my viewmodel after firing http request and I want to publish this event which will be subscribed in the view. But when I am trying to eject the IEventAggregator in view constructor I am getting the error.

What is the best possible solution to this type of the problem.

Kindly help

 

Thanks

Feb 17, 2012 at 3:13 PM

you actually don't need to set it in codebehind it can be done through databinding in XAML. 

<MediaElement Source="{Binding SomeProperty}" />

SomeProperty is a property of type Uri, all you should need to do after that is fire a Notification that SomeProperty has updated based on the results of your http request.

Feb 18, 2012 at 7:17 AM

Hi

Thanks for your reply. I was aware of this property but I want to take control of downloading the file as i am using specialized Httpclient library for achieving the same. I am also required to do some processing on the download data before playing the media file. Hence I am using this method and setting up the Mp3MediaStreamSource to its parameter. 

Also I have figured out a way but i think it violates MVVM pattern. I can download the file as Coroutine and use the View property of the Executioncontext and get this done. I checked it out and it worked. but now there is tight coupling between view and viewmodel. :(

I 'm still in process of figuring out more efficient manner.

If you have any other ideas which can help me to resolve this it would be great.

 

Regards