This is a migrated thread and some comments may be shown as answers.

How to create an MDI UI; on closing problem

4 Answers 82 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 17 Oct 2012, 01:54 PM
Using RadDocking I am trying to create an MDI-style app with many Windows using RadGridViews to edit data.
Instead of using child Windows I try to dynamically create RadPanes with UserControls  from a Menu:

Dim p As New RadPane
p.Content = New SomeUserControl
paneGroup.AddItem(p, Docking.DockPosition.Center)


When the user tries to close the RadPane and the data is dirty I want to offer a choice "Discard changes?".
With Windows I would use the Closing event for this.
How can I do this with a RadPane?
There seems to be no PreviewClose event for RadPane even though they have a close button. UserControls do not have a Closing event.

Or is there a better way to create an MDI-Stlye UI?
As there is no example, I am not even sure if it is a good idea to create RadPanes with UserControls. One cannot put Windows on Panes, but maybe there is some other Control to host the editing Controls we should use.

4 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 22 Oct 2012, 02:51 PM
Hello Peter,

There is a PreviewClose event on the RadDocking control, not directly on the RadPane. Using the event args you could define which pane is closing and handle the event if it is necessary.

Hope this helps.

Regards,
George
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Peter
Top achievements
Rank 1
answered on 23 Oct 2012, 10:30 AM
Hi George,

thanks for your answer.

1.
Using your suggestion I implemented closing the editor Panes like follows. This seems to work, but after closing a pane the RadDocking.Panes.Count stays the same. So my solution does create a memory leak. How can we dispose a pane?
'In Main Window
Private Sub RadDocking_PreviewClose(sender As Object, e As Docking.StateChangeEventArgs)
    Dim activePane = CType(e.OriginalSource, RadDocking).ActivePane
    Dim gridEditor As GridEditorBase = activePane.Content
    If gridEditor.Close Then
        activePane = Nothing
    Else
        e.Handled = True
    End If
End Sub
 
 
'In editing pane
Public Function Close() As Boolean
    Dim OK As Boolean
    If IsDirty Then
        OK = MessageBox.Show("Änderungen verwerfen?", "Es gibt ungespeicherte Änderungen", MessageBoxButton.YesNo) = MessageBoxResult.Yes
    Else
        OK = True
    End If
    Return OK
End Function

2.
The documentation says: "If you want to close a pane in the code-behind, then you need to set the IsHidden property of the RadPane class to False". I don't understand this. Can you explain?

3.
Is using UserControls on Panes the recommended way to create MDI-stlye UIs with Telerik controls?
0
Accepted
George
Telerik team
answered on 26 Oct 2012, 03:27 PM
Hi Peter,

Let me explain the 1st and the 2nd questions together - when a pane is closed, it is actually hidden. This is how the RadDocking works and it is by design. In another words - when a user closes the RadPane, the pane goes hidden and the RadPane.IsHidden property is set to true. The pane is removed from the PaneGroup items collection, but it stays alive and can be accessed via the RadDocking.Panes property. If you want to remove the pane from the RadDocking control and dispose it, I would suggest calling the RadPane.RemoveFromParent method when the pane is closed. 

According to the 3rd question - we cannot confirm whether this is the best way or not because we are not aware of all requirements for MDI UI, but placing a UserControls as a content of the panes is a proper approach.

Kind regards,
George
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Peter
Top achievements
Rank 1
answered on 06 Nov 2012, 11:11 AM
Hi George,

thanks for your detailed answer.

Your suggestion to use RemoveFromParent does work.
In case someone else has the same probolem here my code:

Private Sub dock_PreviewClose(sender As Object, e As Docking.StateChangeEventArgs)
    Dim activePane = CType(e.OriginalSource, RadDocking).ActivePane
    Dim gridEditor As GridEditorBase = activePane.Content
    If Not gridEditor.Close Then e.Handled = True
End Sub
 
Private Sub dock_Close(sender As Object, e As Docking.StateChangeEventArgs)
    'Dispose the closed pane
    Dim closedPane = (From p In dock.Panes Where p.IsHidden).Single
    closedPane.RemoveFromParent()
End Sub


Tags
Docking
Asked by
Peter
Top achievements
Rank 1
Answers by
George
Telerik team
Peter
Top achievements
Rank 1
Share this question
or