Problems with ScrollViewer control getting docked...

Docking/MDI for WPF Forum

Posted 9 years ago by SledgeHammer01
Version: 9.2.0515
Avatar
Part of my app is a thumbnail / image view. The powers that be decided that we need to be able to show a bunch of images at a time, so I am using the docking / MDI tabbing / w/ ribbon theme. I create the window hierarchy at runtime... but it basically ends up being like this:

Document Window
Content = ScrollViewer
Content = ContentControl
Content = StackPanel (vertical)
For each page of the image (i.e. 17)
{
Border + Drop Shadow Effect
Image
}

Everythings works fine at start up, windows are created correctly, I can open and close doc views all day long... if I tried to dock one image into another (i.e. horizontal tab groups, etc)... I sometimes see a few issues:

1) the scroll viewer loses its position and goes to 0,0
2) it seems like you are cloning controls when this happens, so I get some events like "scroll view pos changed" half way through the process because I see a crash in the following function:

private void scrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
if (_imageWindowCurrent == null)
return;

if ((_imageWindowCurrent.StackPanel.Children.Count == 0) || ((object)_imageWindowCurrent.TiffDocument == null))
return;

ScrollViewer scrollViewer = _imageWindowCurrent.ScrollViewer;
int nPage = 0;

foreach (UIElement element in _imageWindowCurrent.StackPanel.Children)
{
GeneralTransform gt = element.TransformToAncestor(scrollViewer);
Rect rect = gt.TransformBounds(new Rect(0, 0, element.RenderSize.Width, element.RenderSize.Height));

if (rect.Top <= (scrollViewer.RenderSize.Height * 0.75))
nPage++;
}

_imageWindowCurrent.TiffDocument.CurPage = nPage;
}

Basically when it gets a scroll changed, it finds out which page is at the top and updates the status bar text...

Problem is when I get one of these intermediate scroll events, the GeneralTransform line throws an exception saying that element is not a visual ancestor of scrollViewer (which it is).

Comments (1)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

If you can please put together a small sample project and email it over to our support address, then we can take a closer look.

We don't do any "cloning", but if you move/dock a DocumentWindow then it will most likely change parents. This causes it to unload (from the old parent) then reload (in the new parent). You might be able to detect this by check that the scrollViewer IsLoaded and/or IsVisible properties.


Actipro Software Support

The latest build of this product (v2019.1 build 0681) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.