wpfpropertiescaliburn.microwindow-chrome

How to access View-Propperties in the ViewModel, using Caliburn.Micro


Until now I only used the basic features of the Caliburn.Micro Framework. But now I want and need to to get deeper into it.

Now I have the case that I need to access properties of the view (a Window) inside its view model.

The details are the following: I customize the shell-window, using Microsoft's Window-Chrome (NuGet-Package: Microsoft.Windows.Chrome). Now I need to check the value of the window's WindowState-Property, to set the property bound to its ResizeBorderThickness-property correctly.

How can I do that with the Caliburn.Micro Framework?

Additional infos: .NET Framework: 4.5; Caliburn.Micro: 3.1.0


Solution

  • You don't directly access view properties in a view model. This effectively breaks the MVVM pattern and what it is all about. A view model shouldn't have any dependency upon the view.

    What you could do is to bind the WindowState property of the window to a bool? source property of your view model and then perform any logic in the setter of the latter.