This project is read-only.

Zooming with slider is wrong

Nov 29, 2011 at 10:06 AM


I've placed the ZoomControl in my project, and performed some bindings to my Model (I'm using MVVM pattern)

Here's the code for my binding:

    <Controls:ZoomControl Style="{DynamicResource ZoomControlStyle1}" Background="#44433e" x:Name="zoomControl" Zoom="{Binding MapModel.ZoomFactor, Mode=OneWayToSource}" 
                          TranslateX="{Binding MapModel.CenterXLocation, Mode=OneWayToSource}" TranslateY="{Binding MapModel.CenterYLocation, Mode=OneWayToSource}"
                          MaxZoom="{Binding MapModel.MaxZoom,Mode=OneTime}" MinZoom="{Binding MapModel.MinZoom,Mode=OneTime}" 

The problem is that when I slide the zoom slider it zooms weirdly (not directly to the center of the current view, but it goes to one of the corners of the canvas), I suspected that maybe the TranslateX / TranslateY causes it, but only when I remove my Zoom binding it solves the problem (but causes other problems in my project)

Did anyone ever encounter such thing? I would kill for a hint here...


Nov 29, 2011 at 1:48 PM

The binding mode for the Zoom property causes the problem. OneWayToSource mean that the zoom writes its value to the MapModel.ZoomFactor property. When setting the binding mode to OneWay, it's reading the property from MapModel.ZoomFactor, hence it will work.

I'm not so sure I understand why this is happening, but I sure need to investigate this some more...

Nov 29, 2011 at 3:20 PM

OK, fixed my own problem - My MapModel.ZoomFactor was of type float and not double, so the loss of precision was causing the weird stuff I was seeing. Changing it to double fixed the problem.