Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Strange Scrolling Issue - Suddenly Resets (Read 9290 times)
benm
YaBB Newbies
*
Offline


I <3 MindFusion

Posts: 32
Location: CA
Joined: Dec 10th, 2008
Strange Scrolling Issue - Suddenly Resets
Apr 23rd, 2010 at 7:18pm
Print Post  
I am running into a strange problem where after adding a node programmatically and adjusting the diagram bounds manually, sometimes the diagram.ScrollX and diagram.ScrollY will be set to -18. There is no place in my code that I am ever setting the scroll position manually, but somehow it ends up at -18, -18. I notice this because sometimes when I try to move the Overview window by dragging, it suddenly snaps to the top left corner. Does this indicate some sort of error happenend when I was manipulating the diagram?
« Last Edit: Apr 29th, 2010 at 10:42am by benm »  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Strange Scrolling Issue - Scroll Set To -18, -
Reply #1 - Apr 23rd, 2010 at 7:46pm
Print Post  
There's this code running after diagram.Bounds changes:

if (ScrollX < bounds.Left || ScrollX > bounds.Right)
     ScrollX = bounds.Left;
// similar for Y

Is the new Bounds rectangle top-left position equal to -18,-18?
  
Back to top
 
IP Logged
 
benm
YaBB Newbies
*
Offline


I <3 MindFusion

Posts: 32
Location: CA
Joined: Dec 10th, 2008
Re: Strange Scrolling Issue - Scroll Set To -18, -
Reply #2 - Apr 24th, 2010 at 1:45am
Print Post  
Ah, I am not explicitly ever setting the diagram bounds, but I am calling diagram.ResizeToFitItems(10), which then causes the top left of the diagram bounds to be (-18, -18). I stepped through the code and determined that before the ResizeToFitItems call, all items of the diagram have top left bounds that are zero or greater. Any idea why this would cause ResizeToFitItems to set a negative top left?

Another puzzling thing is that the scrollY is always reset to -18 even when the bounds bottom right Y appears to be greater than scrollY.
  
Back to top
WWW  
IP Logged
 
benm
YaBB Newbies
*
Offline


I <3 MindFusion

Posts: 32
Location: CA
Joined: Dec 10th, 2008
Re: Strange Scrolling Issue - Scroll Set To -18, -
Reply #3 - Apr 26th, 2010 at 7:34am
Print Post  
I am trying to solve this problem in a different way and that is not working either. What happens is that after I add nodes and resize the diagram, the ScrollViewer around the diagram is in the correct position (let's say Y = 400) and even the region in the overview window is drawn in the correct position. But there is a mismatch between the ScrollViewer's position and the diagram ScrollY position. I can see this using the following code on the overview's mouse down event:

Code
Select All
private void DiagramOverview_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    ScrollViewer viewer = (ScrollViewer)DiagramOverview.Document.Parent;
    Console.WriteLine(viewer.VerticalOffset);
    Console.WriteLine(DiagramOverview.Document.ScrollY);
} 



And in the console, I see that the ScrollViewer Y position is 400, but the diagram ScrollY reports 0. This causes a sudden snap as soon as I begin to drag the mouse around the overview because the overview overrides the ScrollViewer. I attempted to manually synchronize the two by adding this line in the same event handler:

Code
Select All
    DiagramOverview.Document.ScrollY = viewer.VerticalOffset; 


But this still causes the overview window to override the ScrollViewer. I want it the other way around. Any ideas how to synchronize them?
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Strange Scrolling Issue - Scroll Set To -18, -
Reply #4 - Apr 26th, 2010 at 3:08pm
Print Post  
ResizeToFitItems sets Bounds to the union of the items' GetRepaintRect method results. GetRepaintRect adds the stroke thickness and the selection handle size to Bounds, so you will get negative coordinates even if you call ResizeToFitItems(0) when there are items at 0. And then the found union is inflated by the amount specified as ResizeToFit argument, so the coordinates become even more negative. Anyway our developer will check what happens with the scroll values tomorrow.
« Last Edit: Apr 26th, 2010 at 5:48pm by Stoyo »  
Back to top
 
IP Logged
 
benm
YaBB Newbies
*
Offline


I <3 MindFusion

Posts: 32
Location: CA
Joined: Dec 10th, 2008
Re: Strange Scrolling Issue - Scroll Set To -18, -
Reply #5 - Apr 26th, 2010 at 6:42pm
Print Post  
Thanks so much for looking into it.
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Strange Scrolling Issue - Scroll Set To -18, -
Reply #6 - Apr 27th, 2010 at 2:06pm
Print Post  
Actually in the general case the scrollbar's HorizontalOffset and the diagram's ScrollX won't match. The scrollbar's range and offset also depend on the measure unit, zoom level and the diagram.Bounds origin. You can get the same values only if Bounds starts from 0,0, ZoomFactor is 100 and MeasureUnit is WpfPoint. If using the default unit and at zoom level 100, ScrollX should be equal to scrollbar.HorizontalOffset + diagram.Bounds.Left. Can you verify if you are getting such values?

I can't understand exactly what problem you have with the overview, but try calling ovw.ScrollTo(new Point(diagram.ScrollX, diagram.ScrollY)) after ResizeToFit, so that the tracker rectangle position is synchronized with the current scroll position.

Stoyan
  
Back to top
 
IP Logged
 
benm
YaBB Newbies
*
Offline


I <3 MindFusion

Posts: 32
Location: CA
Joined: Dec 10th, 2008
Re: Strange Scrolling Issue - Scroll Set To -18, -
Reply #7 - Apr 27th, 2010 at 9:14pm
Print Post  
That makes perfect sense about HorizontalOffset not necessarily matching ScrollX.

I added the ScrollTo command after ResizeToFit, but that still did not synchronize the overview window.  However, I played around and found that if I set ovw.FitAll = false and then ovw.FitAll = true after the ResizeToFit, it fixed the problem.  Something in there must have forced a sync.

Thanks again for your help.
  
Back to top
WWW  
IP Logged
 
benm
YaBB Newbies
*
Offline


I <3 MindFusion

Posts: 32
Location: CA
Joined: Dec 10th, 2008
Re: Strange Scrolling Issue - Scroll Set To -18, -
Reply #8 - Apr 27th, 2010 at 9:16pm
Print Post  
As a side note, having an OnScroll or ScrollChanged event in future versions for the diagram may be useful.
  
Back to top
WWW  
IP Logged
 
benm
YaBB Newbies
*
Offline


I <3 MindFusion

Posts: 32
Location: CA
Joined: Dec 10th, 2008
Re: Strange Scrolling Issue - Scroll Set To -18, -
Reply #9 - Apr 29th, 2010 at 10:34am
Print Post  
Hi Stoyan,

Sorry to keep bothering you but I have one additional piece of the puzzle here.

I am using DiagramNodeAdapters throughout my diagram and they wrap a user control that has a scroll viewer in it.  I noticed that whenever I scroll the viewer inside the user control, the diagram scroll is affected but the scroll viewer around the diagram does not move!  I think this is the root of all of the problems I am having.  Any idea why this is happening?

Thanks,
Ben
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Strange Scrolling Issue - Suddenly Resets
Reply #10 - Apr 29th, 2010 at 10:51am
Print Post  
Hi Ben,

Do you mean moving a scrollbar in the node scrolls the whole diagram?

Stoyan
  
Back to top
 
IP Logged
 
benm
YaBB Newbies
*
Offline


I <3 MindFusion

Posts: 32
Location: CA
Joined: Dec 10th, 2008
Re: Strange Scrolling Issue - Suddenly Resets
Reply #11 - Apr 29th, 2010 at 6:46pm
Print Post  
That's what I think is happening. Here is all that I am doing:

1) Add a node with a TextBlock inside of a ScrollViewer inside the node.
2) Use the scroll the TextBlock up and down by clicking the arrows or using the scroll wheel.
3) Nothing appears to have changed but then when I click the Overview, it snaps the diagram back to 0,0 instantly upon dragging.

Removing the ScrollViewer from the node not only fixes this problem, but all of the other problems I was having as well. Even just adding the node to the diagram would reset the Overview back to 0, 0 in this way.
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Strange Scrolling Issue - Suddenly Resets
Reply #12 - Apr 30th, 2010 at 10:51am
Print Post  
Our bad - the diagram handles the ScrollViewer's ScrollChanged event, but doesn't check the event source. And since it's a routed event, our handler is called also for the child scroll viewers. For the time being handle the event in your control to stop its routing:

Code
Select All
private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
	e.Handled = true;
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
benm
YaBB Newbies
*
Offline


I <3 MindFusion

Posts: 32
Location: CA
Joined: Dec 10th, 2008
Re: Strange Scrolling Issue - Suddenly Resets
Reply #13 - Apr 30th, 2010 at 6:23pm
Print Post  
Thanks!  It's nice to have finally tracked this down.
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Strange Scrolling Issue - Suddenly Resets
Reply #14 - May 18th, 2010 at 6:48am
Print Post  
Hi Ben,

The Overview in this beta version should work correctly with ScrollViewers in child items -
http://mindfusion.eu/Forum/YaBB.pl?board=wpfdg_disc;action=display;num=127416450...

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint