-
Notifications
You must be signed in to change notification settings - Fork 885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null Reference Exception inserting documents when isActive is set before insertion #1481
Comments
Hi, I've looked into this and can confirm the problem - also found that it occurs with my stabilized version of AvalonDock
I'll be trying to debug and hope to find a fix when my time permits |
Here is the stacktrace I got: System.NullReferenceException |
I found the source of the problem and the fix does not appear to be difficult either :-) I located the problem in Xceed.Wpf.AvalonDock.Controls.DocumentPaneTabPanel class at line 54 where the following code crashes at the line where the if statement checks
Here is the listing of the offending code and a fix is shown below: protected override Size ArrangeOverride( Size finalSize )
{
var visibleChildren = Children.Cast<UIElement>().Where( ch => ch.Visibility != System.Windows.Visibility.Collapsed );
var offset = 0.0;
var skipAllOthers = false;
foreach( TabItem doc in visibleChildren )
{
var layoutContent = doc.Content as LayoutContent;
if( skipAllOthers || offset + doc.DesiredSize.Width > finalSize.Width )
{
if( layoutContent.IsSelected && !doc.IsVisible )
{
var parentContainer = layoutContent.Parent as ILayoutContainer;
var parentSelector = layoutContent.Parent as ILayoutContentSelector;
var parentPane = layoutContent.Parent as ILayoutPane;
int contentIndex = parentSelector.IndexOf( layoutContent );
if( contentIndex > 0 &&
parentContainer.ChildrenCount > 1 )
{
parentPane.MoveChild( contentIndex, 0 );
parentSelector.SelectedContentIndex = 0;
return ArrangeOverride( finalSize );
}
}
doc.Visibility = System.Windows.Visibility.Hidden;
skipAllOthers = true;
}
else
{
doc.Visibility = System.Windows.Visibility.Visible;
doc.Arrange( new Rect( offset, 0.0, doc.DesiredSize.Width, finalSize.Height ) );
offset += doc.ActualWidth + doc.Margin.Left + doc.Margin.Right;
}
}
return finalSize;
} A fix is to insert these two lines in the
|
On a second thought about this - there is a much better fix that lets the rest of the code work as before but won't crash on your test case :-) So, the better solution is to move the Any opionions on this?
|
Solution is available in Version 3.5.3 on Nuget |
This will be fixed in v3.9. |
I have an application using the AvalonDock library, and to fix an issue with new documents not showing content correctly (#1480), we have to set the IsActive property on the LayoutDocument to true in the BeforeInsertDocument method of the ILayoutUpdateStrategy implementation.
With this setup, the library throws a Null Reference Exception under these circumstances:
I have been able to produce a sample application that produces the same error; which is simply the DocumentOpenSample modified to set the IsActive property as described.
DocumentOpenSample.zip
Is there a fix or work around for this? I cannot simply remove setting the IsActive property, as that causes the previously mentioned bug.
The text was updated successfully, but these errors were encountered: