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).
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).