Approved
Last Updated: 29 Mar 2018 12:44 by ADMIN
ADMIN
Tanya
Created on: 05 Feb 2018 16:44
Category: RichTextBox
Type: Bug Report
1
RichTextBox: Alert windows don't have Owner set
The dialogs don't have an owner, thus they behave unexpected and can be easily lost from the user and block the UI.

This applies to many of the RadWindow.Alert() invocations in the UI of RichTextBox.
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
2 comments
Marc
Posted on: 06 Feb 2018 18:31
This is only an issue when our control is hosted by an ElementHost.  We are using the RadRichTextBox with a RadRichTextBoxRibbonUI  and when our WPF control is hosted in an ElementHost all of the RadWindows created do not have an owner.

For the dialog boxes this is because the SetOwner() method calls the WindowHelper.GetParentWindow() method which always returns null.  Being hosted in an element host seems to mean that there is no Window or RadWindow at the root of the VisualTree.  So parentIsWindow is always false in the GetParentWindow() method.

We worked around this for the dialog boxes because we are able to get the dialog objects from the RadRichTextBox (FindReplaceDialog, FontPropertiesDialog, etc) and then hook the HostCreated event for all of the "exposed" dialogs.  In the HostCreated event handler we are able to get the top level HWND from the ElementHost:

HwndSource presentationSource = PresentationSource.FromDependencyObject(radRichTextBox) as HwndSource;

ElementHost elementHost = System.Windows.Forms.Control.FromChildHandle(presentationSource.Handle) as ElementHost;

System.Windows.Forms.Form topLevelControl = elementHost.TopLevelControl as System.Windows.Forms.Form;

topLevelWindowHandle = topLevelControl.Handle;

then we are able to set the window owner as follows:

RadWindow radWindow = sender as RadWindow;
Window window = Window.GetWindow(radWindow);
WindowInteropHelper windowInteropHelper = new WindowInteropHelper(window);
windowInteropHelper.Owner = hwndMainWindow;

However, some of the dialogs display Alerts.  For example, the FindReplaceDialog displays an alert when you have searched through the entire document.  We could not find a way to get access to these generic generated RadWindows in order to set the owner.  We were hoping that there might be some way to hook the HostCreated event for all RadWindows that are created by the RadRichTextBox so that we could set the owner.

We looked at changing the source for the RichTextBox project so that the SetOwner() method in the RadRichTextBoxWindow class hooked the HostCreated event and did what we needed in that handler (same as we did above) if the WindowHelper.GetParentWindow() returned null.  This worked for us but then we discovered the way to do it without changing the Telerik source which is what we did.

But now we are back to thinking about modifying the source to be able to hook the HostCreated event for any RadWindow that is created when we are running under an ElementHost.  But we really do not want to modify the Telerik source.

So some way to be able to hook the HostCreated event any time a RadWindow is created would be awesome!  But again, we would only want to do this when running under an ElementHost.  It should not be needed if you are running in a full fledged WPF application.
ADMIN
Tanya
Posted on: 29 Mar 2018 12:44
Hi Marc,

Thank you for the detailed explanation.

The methods that show the alerts cannot be overridden, so I am afraid that I cannot suggest a different approach to workaround this behavior.

Continue following this item so you can be notified of status changes on it.

Regards,
Tanya