hengi
❔ Trigger MediaElement.play() the MVVM way?
Someone asked that exact question on SO: https://stackoverflow.com/questions/10631748/mvvm-pattern-violation-mediaelement-play
TL;DR you could raise an event
PlayRequested
in the VM and subscribe to the event in the View. There, you just call MediaElement.Play()
. The other way would be a bit more elaborate but actually "feels" how MVVM should be used.
Basically the second answer of the StackOverflow question. You wrap the MediaElement in an Interface, create a new UserControl with them and then use the UserControl.4 replies
✅ BackgroundWorker in WPF MVVM
BackgroundWorkers are just a bit old and they feel a bit like Java Threads? Where you subclass a Thread but with Events instead. Just treat the Events like enclosed actions, do not manipulate the BackgroundWorker outside of them except for Cancellation
17 replies
can't make a cycle properly
the inner loop will run until the number reaches 1, then the outer loop should immediately break after that? because num == 1, count will always be 1
i think you want a counter variable inside the while loop
at the start of the loop, you just increase it by 1, no need for two loops
22 replies
✅ BackgroundWorker in WPF MVVM
yes ofc, most of the stuff you do in WPF usually does not require even that, Task.Run is only really needed when you do CPU heavy stuff. Everything else is awaitable at least somewhere
so you can just use async Events or expand your Command class to support Async Commands and stuff
17 replies