GridSplitter throwing NullRefrenceException Error

Aug 7, 2010 at 6:18 PM
Edited Sep 15, 2010 at 3:55 PM

I just wanted to say what an excellent library this is and to keep up the good work on it. Now onto my problem. Whenever I drag a GridSplitter within the content of a DockableContent or DockablePane that is in a floating window, I get a NullRefrenceException can I haven't yet been able to track down where it is coming from. Here is a simple example that will replicate this:

 

<ad:DockableContent x:Name="AttributesContent" Title="Attributes" Background="Red">
    <Grid Name="SelectorGrid" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition  Height="100"/>
            <RowDefinition Height="6"/>
            <RowDefinition Height="100"/>
        </Grid.RowDefinitions>
                                    
        <Border BorderThickness="1" BorderBrush="Black" CornerRadius="5" Margin="10" Height="100"
                Background="AliceBlue" VerticalAlignment="Top"/>
            <GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" Height="6" ShowsPreview="True"/>
                <Border BorderThickness="1" BorderBrush="Black" CornerRadius="5" Margin="10" Height="100"
                        Background="LightSalmon" VerticalAlignment="Top"/>
    </Grid>
</ad:DockableContent>

 

Aug 7, 2010 at 6:25 PM
Edited Sep 15, 2010 at 3:49 PM

I found out what it was. It was the GridSplitter.ShowsPreview property being set to true.

 

The solution was to wrap the Grid in a AdornerDecorator like so:

 

 

<AdornerDecorator>
    <ad:DockableContent x:Name="AttributesContent" Title="Attributes" Background="Red">
        <Grid Name="SelectorGrid" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition  Height="100"/>
                <RowDefinition Height="6"/>
                <RowDefinition Height="100"/>
            </Grid.RowDefinitions>
                                        
            <Border BorderThickness="1" BorderBrush="Black" CornerRadius="5" Margin="10" Height="100"
                    Background="AliceBlue" VerticalAlignment="Top"/>
                <GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" Height="6" ShowsPreview="True"/>
                    <Border BorderThickness="1" BorderBrush="Black" CornerRadius="5" Margin="10" Height="100"
                            Background="LightSalmon" VerticalAlignment="Top"/>
        </Grid>
    </ad:DockableContent>
</AdornerDecorator>

 

Sep 9, 2010 at 12:04 AM

Woshiernog thank you for posting your solution.  I was having the exact same problem and now It's working . :-)

Sep 15, 2010 at 3:33 PM

You AdornerDecorator solution doesn't seem to get rid of the error for me. Here's the full stack trace:

System.ArgumentNullException occurred
  Message=Value cannot be null.
Parameter name: key
  Source=mscorlib
  ParamName=key
  StackTrace:
       at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
       at System.Collections.Generic.Dictionary`2.ContainsKey(TKey key)
       at System.Activities.Presentation.View.ImportDesigner.ValidateNamespaceModelAndUpdateContextItem(ModelItem namespaceModel)
       at System.Activities.Presentation.View.ImportDesigner.ValidateImportedNamespaces()
       at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
       at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
       at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)
       at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
       at System.Windows.Data.BindingExpression.Activate(Object item)
       at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
       at System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
       at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
       at MS.Internal.Data.DataBindEngine.Run(Object arg)
       at MS.Internal.Data.DataBindEngine.OnLayoutUpdated(Object sender, EventArgs e)
       at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
       at System.Windows.ContextLayoutManager.UpdateLayout()
       at AvalonDock.Pane.OnItemsChanged(NotifyCollectionChangedEventArgs e) in C:\AvalonDock_Trunk\Version1.3\AvalonDock\Pane.cs:line 145
  InnerException:

Sep 15, 2010 at 4:00 PM

Are you sure this is related to the same issue? I see this was started by the collection in Pane changing, however I can't see how moving the GridSplitter has an effect on the collection without more details.

Sep 15, 2010 at 4:07 PM

Apparently it's not the same issue. I thought it was related to the grid splitters because the error showed at the same time I added the splitters. Alas, it persists after removing the splitters. I'm stumped at this point.