Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Commented Unassigned: RichTextBox + RichTextBoxFormatBar throwing a NullReference exception when dragged, possible bug? [21943]

$
0
0
Hello,

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 **

Lastly I just noticed this is because I added field validation errors to the property bound to "Text" which was causing the Validation.ErrorTemplate to show introducing the other layer preventing the UIElementAdorner<Control> from being found.

So I am 100% this is a bug now, but in the meantime I have just removed the field validation and placed an error message to the right of the control.


Viewing all articles
Browse latest Browse all 4964

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>