Here is the Source property, nothing special about it: #region Source propertyĪs for Visibility, and stuff like this, you can use converters (e.g. HACK for MediaElement: to force it to play a new source, set source to null then put the real source URI. The view model's play function should look like this: private void PlaySomething(string fileUri) The trick is extremely simple so I won't post a complete example.
HUMMA HUMMA OK JAANU SONG DOWNLOAD MP3 CODE
Hopefully no code behind is needed for what you want to achieve. Probably, the most important aspect of this tip is that you have to set MediaElement's property LoadedBehaviour to Play in XAML of your view. The view model handling this, was created with a Source property of type Uri (with notify property changed, but you already know you need that to notify UI).Īll you have to do whenever source changes (and this is up to you), is to set the source property to null (this is why Source property should be Uri and not string, MediaElement will naturally throw exception, NotSupportedException I think), then set it to whatever URI you want. I use media element to play sounds in UI whenever an event occurs in the application. So at the View's code behind file there is no DataContext assignment code, and I prefer to keep it that way, and hence I chose to use purely Commands to achieve this result. Side note: I use Prism's Auto Wiring feature to link up the View and ViewModel. other commands are not listed, but you get the idea This.loadedCommand = new DelegateCommand((mediaService) => We now can catch everything in the ViewModel (I'm using prism's DelegateCommand here): public class AboutUsViewModel : SkinTalkViewModelBase, IConfirmNavigationRequest last but not least, we need to hookup the media controls through Commands:.Hookup the Loaded event through Trigger to pass the view itself to the view model through a Command.import the interactivity namespace for later use (some default namespaces are omitted for simplicity reason):.
![humma humma ok jaanu song download mp3 humma humma ok jaanu song download mp3](https://img.youtube.com/vi/GjdGfiA_UJ8/0.jpg)
Give the view a name so we can pass it as a parameter, and.Give the MediaElement a name so the code behind can access it like above:.We then do few things in the DemoView.XAML: Implement the IMediaService in the View: public partial class DemoView : UserControl, IMediaService Introduce an interface called IMediaService as below: public interface IMediaService
![humma humma ok jaanu song download mp3 humma humma ok jaanu song download mp3](https://4.bp.blogspot.com/-g9NAdt_rYRA/WG0zlt4EI0I/AAAAAAAAAH4/hp7C_jMP3QM56eOWmoSatUg9hPXcFrAvwCLcB/s1600/OKJAANU%2BThe%2B%2BHumma%2BSong%2BLyrics.png)
In short, we are going to introduce an interface between the View and the ViewModel to break the dependecy, and the View will be implementing the interface and be responsible for the direct controlling of the MediaElement while leaving the ViewModel talking only to the interface, which can be swapped with other implementation for testing purposes if needed, and here comes the long version:
![humma humma ok jaanu song download mp3 humma humma ok jaanu song download mp3](https://i.ytimg.com/vi/68Yq9Fn2pSc/hqdefault.jpg)
![humma humma ok jaanu song download mp3 humma humma ok jaanu song download mp3](https://static.qobuz.com/images/covers/06/69/0886446296906_600.jpg)