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

RadDocking PreviewClose

6 Answers 231 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Adrian
Top achievements
Rank 1
Adrian asked on 08 Nov 2013, 01:30 PM
I have 2 questions about this event.

1. How can I cancel pane closing in this event (or any other way)?
2. What this event is designed for?

Regards,
Adrian

6 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 13 Nov 2013, 02:10 PM
Hi,

The PreviewClose as any preview event in WPF is designed to trigger before the corresponding event is triggered. In order to cancel the closing of a Pane/PaneGroup in that event all you need to do is handle it by setting the Handled property of the StateChangeEventArgs to True. The next code snippet shows how to cancel the closing in the PreviewClose event:
<telerik:RadDocking PreviewClose="RadDocking_PreviewClose">
    ...
</telerik:RadDocking>

and the event handler:
private void RadDocking_PreviewClose(object sender, Telerik.Windows.Controls.Docking.StateChangeEventArgs e)
{
    e.Handled = true;
}

Hope this is helpful.

Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Adrian
Top achievements
Rank 1
answered on 13 Nov 2013, 02:28 PM
Thanks Vladi,

I was looking for Cancel property because I thought that StateChangeEventArgs is a CancelEventArgs and I forgot about Handled. Other question I have is how to cancel closing only one pane if multiple pane are closed (e.g. when closing ToolWindow with few panes docked inside)?

Regards,
Adrian
0
Vladi
Telerik team
answered on 14 Nov 2013, 02:16 PM
Hello,

When closing multiple Panes at the same time the PreviewClose event will be triggered multiple times for each Pane. You could simply get the first element of the Panes collection from the StateChangeEventArgs which is the currently closing Pane and use that Pane's details to filter if it needs to be closed or not. The next code snippet shows how to filter the closing Pane and if its Header matches the condition it will not be closed:
private void RadDocking_PreviewClose(object sender, Telerik.Windows.Controls.Docking.StateChangeEventArgs e)
{
    var pane = e.Panes.First();
 
    if (pane.Header.ToString() == "Pane 1")
    {
        e.Handled = true;
    }
}


Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Robert
Top achievements
Rank 1
answered on 06 Jul 2017, 04:38 AM

        <telerik:RadDocking Grid.Row="1" x:Name="RadDocking" PanesSource="{Binding Panes}" >
            <telerik:RadDocking.DocumentHost>
                <telerik:RadSplitContainer>
                    <telerik:RadPaneGroup x:Name="DocumentHostPaneGroup"/>
                </telerik:RadSplitContainer>
            </telerik:RadDocking.DocumentHost>

            <telerik:RadDocking.DockingPanesFactory>
                <vm:CustomDockingPanesFactory />
            </telerik:RadDocking.DockingPanesFactory>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Close">
                    <command:EventToCommand Command="{Binding PreviewPaneCloseCommand}" PassEventArgsToCommand="True" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </telerik:RadDocking>

 

       private readonly RelayCommand<StateChangeEventArgs> _previewPaneCloseCommand;
           _previewPaneCloseCommand = new RelayCommand<StateChangeEventArgs>(OnPreviewPaneClose);
        public ICommand PreviewPaneCloseCommand => _previewPaneCloseCommand;

        private void OnPreviewPaneClose(StateChangeEventArgs obj)
        {

            obj.Handled = true;
        }

 

 

0
Robert
Top achievements
Rank 1
answered on 06 Jul 2017, 04:39 AM
Using MVVMLight and the above code did not prevent the pane from being closed. 
0
Kalin
Telerik team
answered on 10 Jul 2017, 01:36 PM
Hello Robert,

From the provided snippet I can see you are attaching the Command to the Close event and in order to cancel it you have to use PreviewClose:

<i:EventTrigger EventName="PreviewClose">

Please give it a try and let me know if you have any further issues or concerns.

Regards,
Kalin
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
Docking
Asked by
Adrian
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Adrian
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or