M
M
Melz2017-02-16 01:03:54
WPF
Melz, 2017-02-16 01:03:54

WPF, how to correctly throw a MediaElement into a VM for testing?

Hello everyone,
Technologies: C#, WPF, Moq, NUnit, MVVM and some TDD :)
There is a MediaElement that plays a bit of video (logo and demo) a little. It is done following the example from StackOverflow.
XAML:

<ContentControl 
            x:Name="MediaElement"
            Content="{Binding MediaElementObject}"/>

viewmodel:
public MediaElement MediaElementObject
        {
            get { return _mediaElementObject; }
            set { _mediaElementObject = value; OnPropertyChanged(); }
        }

Accordingly, in the code of the view, only InitializeComponent () and almost everything is done by commands (ICommand).
MediaElementObject is needed in the VM because there are Play, Pause, Stop methods that I torture from different parts.
What I don't like:
1. ContentControl - it's a problem to write triggers in haml, etc.
2. MediaElement in the VM, as if against the canons.
3. MediaElement cannot be padlocked.
4 MediaElement requires STA, which is sad because the tests take a very long time. And generally requires a ref. on WPF in tests. Sheer sadness.
Alternative No. 1: There was an idea to make a wrapper around MediaElement, IMediaElement and a facade class, throwing all the methods. But bindings in the form of those are still obtained.
Alternative #2: throw everything into the Storyboard (example with control) .
Can experienced people tell me how to do it right? :)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question