开发者

scrollviewer and canvas - scrolling view to given position

开发者 https://www.devze.com 2023-01-16 02:32 出处:网络
I have some problems with implementing autoscrolling in WPF (I think I could call it that way). I have a canvas placed inside a scrollviwer. On my canvas I can dynamicly add different shapes. The posi

I have some problems with implementing autoscrolling in WPF (I think I could call it that way). I have a canvas placed inside a scrollviwer. On my canvas I can dynamicly add different shapes. The position of this shapes can be changed with mouse. Everytime I add new shape on canvas or change position of shape I fire measureOverride function.Thanks开发者_运维知识库 to this scrollview "know" the real size of canvas and the scrollbars appear. However even if scrolbars appear, the view doesn't "follow" shape which I currently move. I mean if I reach visible part of canvas I would like canvas to srcoll. I was trying to use this function

ScrollToHorizontalOffset()

However I have problem with proper use of that function. I was trying to use (as a parameter) canvas actualwidth but it didn't work well. I also was trying to use as a parameter current position of shape (which I move) but it works only one way. I the viewer follow the moving element if I was moving this element to right side of canvas. However if I move shape back(to the left) the view don't follow the shape.

I hope somebody will understand this :) It is hard to explain my problem.


I also was trying to use as a parameter current position of shape

That is the correct way to implement. Waht you need is a converter, which will returns the position according to the direction you move the object.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号