I am not sure why but I am receiving the following exception when I select text then attempt to drag the attached RichTextBoxFormatBar:
```
Object reference not set to an instance of an object.
at Xceed.Wpf.Toolkit.RichTextBoxFormatBar.ProcessMove(DragDeltaEventArgs e)
at Xceed.Wpf.Toolkit.RichTextBoxFormatBar.DragWidget_DragDelta(Object sender, DragDeltaEventArgs e)
at System.Windows.Controls.Primitives.DragDeltaEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
etc.... etc...
```
Looking at the source code for RichTextBoxFormatBar: http://wpftoolkit.codeplex.com/SourceControl/latest#Main/Source/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/RichTextBoxFormatBar/RichTextBoxFormatBar.cs
The code for ProcessMove():
```
private void ProcessMove( DragDeltaEventArgs e )
{
AdornerLayer layer = AdornerLayer.GetAdornerLayer( Target );
UIElementAdorner<Control> adorner = layer.GetAdorners( Target )[ 0 ] as UIElementAdorner<Control>;
adorner.SetOffsets( adorner.OffsetLeft + e.HorizontalChange, adorner.OffsetTop + e.VerticalChange );
}
```
It appears that maybe (I have not built the source myself) the call to AdornerLayer.GetAdornerLayer(Target) is failing to return a value... So I was wondering if there is something I might be missing in my view XAML to get it working correctly?
```
<Toolkit:RichTextBox DockPanel.Dock="Right"
Text="{Binding Query, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<Toolkit:RichTextBox.Style>
<Style TargetType="{x:Type Toolkit:RichTextBox}">
... (Note have tried removing the custom style, did not resolve the issue) ...
</Style>
</Toolkit:RichTextBox.Style>
<Toolkit:RichTextBox.TextFormatter>
<TextFormatting:RtfToHtmlFormatter></TextFormatting:RtfToHtmlFormatter>
</Toolkit:RichTextBox.TextFormatter>
<Toolkit:RichTextBoxFormatBarManager.FormatBar>
<Toolkit:RichTextBoxFormatBar></Toolkit:RichTextBoxFormatBar>
</Toolkit:RichTextBoxFormatBarManager.FormatBar>
</Toolkit:RichTextBox>
```
Also is there a way to use the RichTextBoxFormatBar with dragging disabled for the meantime?
Thanks,
Alex.
Comments: ** Comment from web user: alex21 **
Ok after building the source myself I have figured out what is going on but still do not understand it...
The line that is failing to return a value is actually this one:
```
UIElementAdorner<Control> adorner = layer.GetAdorners(Target)[0] as UIElementAdorner<Control>;
```
Not because layer.GetAdorners(Target) does not return the UIElementAdorner<Control>, but because it is not at position zero of the array returned...
If I execute the method in the immediate window I get the following output:
```
layer.GetAdorners(Target)
{System.Windows.Documents.Adorner[2]}
[0]: {MS.Internal.Controls.TemplatedAdorner}
[1]: {Xceed.Wpf.Toolkit.Core.UIElementAdorner<System.Windows.Controls.Control>}
```
So I modified the ProcessMove() method to the following to fix this:
```
private void ProcessMove(DragDeltaEventArgs e)
{
AdornerLayer layer = AdornerLayer.GetAdornerLayer(Target);
UIElementAdorner<Control> adorner = layer.GetAdorners(Target).OfType<UIElementAdorner<Control>>().First();
adorner.SetOffsets(adorner.OffsetLeft + e.HorizontalChange, adorner.OffsetTop + e.VerticalChange);
}
```
Can anyone suggest the best way to proceed? I really do not want to build the source myself as I want to get updates from nuget, but I also need this bug fixed ASAP as it is in a production build.