6 Answers, 1 is accepted
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
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 >>
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
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
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 >>
<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;
}
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