0

i tried out the following answer:

https://stackoverflow.com/a/16947081/2111258

I have gotten the code to work, but I dont understand how the slider in the dockpanel has the ScaleFactor property bound. Using breakpoints i found out that its bound to the MainWindow's ViewModel object.

How does the bind definition "{Binding ScaleFactor}" bind it to the property of a completely different object belonging to the MainWindow?

Community
  • 1
  • 1
MooshBeef
  • 279
  • 1
  • 5
  • 15

1 Answers1

0

Maybe I am missing something but I don't see anything unusual there.

Object the view is bound to is specified in DataContext property:

DataContext = ViewModel = new PanZoomViewModel();

PanZoomViewModel contains ScaleFactor property which value is read and updated by view when changed in UI. And when it is changed in code its setter fires OnPropertyChanged event, so view knows it should update corresponding UI element.

dewaffled
  • 2,850
  • 2
  • 17
  • 30
  • Thank you, I'm new to WPF so I don't know how databinding works yet, based on the term DataContext i found http://www.codeproject.com/Articles/321899/DataContext-in-WPF which explained more in detail, thanks again – MooshBeef Oct 31 '14 at 09:52