0

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

1 Answers1

0

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.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • Basicly I know how to bind properties. My Problem is that this time the property I need is set by the view and not by the view model, so the direction of data flow is reversed. – ZaHaDum1984 Jul 07 '17 at 13:12
  • The view model needs to set a property of the view is the same thing as the view model setting a property of itself that is bound to a property of the view. This is how data binding works. – mm8 Jul 07 '17 at 13:15
  • Okay, so I don't have to define that as a ToWay-Binding? – ZaHaDum1984 Jul 07 '17 at 13:18
  • In my case its the other way around, so I will have to make that a TwoWay-binding. I will try that and report the result later. – ZaHaDum1984 Jul 07 '17 at 13:22
  • If the target property in the view to update the source property of the view model, the mode of the binding should be set to TwoWay. – mm8 Jul 07 '17 at 13:23