Is it possible to retrieve the instance of the DataContext of a UserControl within a WPF Application?
I have tried it with FrameworkElement.DataContextProperty, but FrameworkElement.GetProperty(FrameworkElement.DataContextProperty) just get's the FullName of the DataContext as a string.
I am working with VS2015, .NET Framework 4.5.2, MSTest (switching to MSTest V2 once no longer a prerelease).
Here's my example code of a MVVM WPF-Application:
Default App.xaml and App.xaml.cs, with StartupUri="MainWindow.xaml"
MainWindow.xaml: (default Code-Behind)
MyUserControl.xaml: (default Code-Behind)
Unit Test (MSTest):
And are there any other ways to get and/or set a Property of a ViewModel alternatively?
From the code sample above, I would like to get the current value of MyDataContext.Count.
In my Unit Test, I want to Assert the incremented MyDataContext.Count property after each Button-Click.