Aren
Aren

Reputation: 55966

MVVM Practice for accessing the entire view

Still a bit new to the concept of M-V-VM in WPF, here's my problem:

I've built up my ui pretty cleanly, I have the following:

The View-Model is all wired up through bindings and cleanly keeps all logic inside it for testability.

What I need to do now is set the entire view's cursor property. However in the context of the ViewModel, it does not know about the view. How would I go about this under the MVVM paradigm. I don't want to resort to code-behind where possible.

Upvotes: 2

Views: 215

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564641

You can use a DataTrigger for this. Just have the DataTrigger bound to a property on the ViewModel, and when it's set to a specific value, change the View's Cursor property as needed.

This has the advantage of allowing your ViewModel to be completely unaware of "cursors" - it just sets a property (such as IsBusy), and the cursor logic is 100% View.

Upvotes: 4

Related Questions