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

Prevent closing of the Backstage

10 Answers 237 Views
RibbonView and RibbonWindow
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 25 Jun 2014, 04:32 PM
Is there a way to prevent the closing of the Backstage until a condition is true. So if the user clicks on another tab, I would like to keep it open.

10 Answers, 1 is accepted

Sort by
0
Milena
Telerik team
answered on 26 Jun 2014, 11:08 AM
Hello Michael,

You can achieve such behavior by using PreviewSelectionChanged and SelectionChanged events of the RadRibbonView. On PreviewSelectionChange you can check if the backstage is open (through the IsBackStageOpen property of the RadRibbonView) and then keep it open until the ApplicationMenuButton isn't pressed:  

bool isBackstageOpen = false;
 
private void radRibbonView_PreviewSelectionChanged(object sender, Telerik.Windows.Controls.RadSelectionChangedEventArgs e)
{
    var ribbon = (sender as RadRibbonView);
    isBackstageOpen = ribbon.IsBackstageOpen;     
}    
 
private void RadRibbonView_SelectionChanged(object sender, RadSelectionChangedEventArgs e)
{
    var ribbon = (sender as RadRibbonView);
    if (isBackstageOpen)
    {
        ribbon.IsBackstageOpen = true;
    }
}
I hope this information will help you and don't hesitate to write back if you have more questions.


Regards,
Milena
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Michael
Top achievements
Rank 1
answered on 26 Jun 2014, 04:31 PM
I'm getting this error 

A first chance exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll

Additional information: Specified element is already the logical child of another element. Disconnect it first.

on the line:

ribbon.IsBackstageOpen = true;
0
Milena
Telerik team
answered on 27 Jun 2014, 01:04 PM
Hello Michael,

I have tried to reproduce the exception (using binaries from our last release - 2014.2 617 as you) but to no avail. However I attached the test project I used to reproduce the issue. Please feel free to modify it in order to show us how to reproduce it. This will allow us to investigate the problem further.

Thank you for your understanding and cooperation in advance.

Regards,
Milena
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Gord
Top achievements
Rank 1
answered on 19 Jul 2016, 05:37 PM
I realize this is an older post, but I am trying to do something similar.  Following the direction here works if there are other tabs loaded.  However, if there is only the application button and no other tabs, the PreviewSelectionChanged event does not get fired.   Is the only way to prevent the backstage from closing, to put a dummy placeholder tab in so that the selectionChanged event can fire?
0
Milena
Telerik team
answered on 20 Jul 2016, 08:08 AM
Hi Gord,

PreviewSelectionChanged and SelectionChanged events are raised when the tab selection is about to be done or is done. If you don't have any RibbonTabs in RibbonView, then the events will not be fired. You can find more information in our help article Ribbon Tab in section Events

However, I'm not sure that I understand your scenario. Could you please send us more detailed information about it - a sample project, a code-snippet of your RibbonView, steps - when the backstage closes, etc. 

Thank you in advance for your cooperation. 

Regards,
Milena
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Gord
Top achievements
Rank 1
answered on 20 Jul 2016, 11:12 AM

I have an application that loads a single object for editing.  When loaded, based on the configuration information in the object, different tabs are displayed in the ribbon bar.  When no object is loaded, the ribbon bar is completely empty.  In that situation, I want to keep the backstage open so the user is not presented with an empty screen.

I did some tests.  I set the boolean for keeping the backstage open in the preSelectionChanged event, and then set it to shown in the SelectionChanged (with placing a dummy tab to trigger the change events), as outlined above.  When I click the "back" button that closes the backstage, the UI thread locks up. I assume there is some kind of recusive loop occurring because the "IsBackstageOpen" is getting set after the change happens.

 

Would the only solution for this be to create a static class with a "CloseBackstage" command in it, and override the existing command reference in the RadRibbonBackstage control template?

0
Milena
Telerik team
answered on 22 Jul 2016, 07:32 AM
Hello Gord,

Thank you for the additional information. I tried to follow your scenario, but I cannot reproduce the issue. However, I might be missing important part of your implementation (e.g. what do you mean by "dummy tab"). This is why I believe it will be better if you send us a sample project with steps to reproduce. This will allow us to examine your implementation and try to reproduce the issue locally. We can then modify the solution to work per your requirements and send it back to you.

Also you wrote "ribbon bar", I suppose you mean RadRibbonView control? Could you tell us which version of our UI for WPF you are using? 

I'm looking forward for helping you solve this issue.

Regards,
Milena
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Gord
Top achievements
Rank 1
answered on 22 Jul 2016, 11:28 AM

Hello Milena,

I wasn't able to upload the project here.  It says the file was either too large or not the allowed type.  I have uploaded it to a dropbox account instead:  Sample.zip

It has a RibbonView with an application button, and one tab.  In the SelectionChanged event, it checks if an internal data object is null, and if it is, it sets the "IsBackstageOpen" property to true, to keep it open.

This tab serves no purpose aside from its existence triggering the SelectionChanged event, which is why I referred to it as a "dummy tab".  When hitting escape, or clicking the back arrow in the backstage, the UI freezes.

I am currently using version 2016.1.217, which is a bit out of date.  If upgrading resolves this, then that's a simple solution.

The other problem I had mentioned is that, ideally, I don't want to have to use a placeholder tab when no data is loaded, just to handle keeping the backstage open. 

To address this issue, what I have done is changed the reference to "telerik:RibbonCommands.CloseBackstage" in the RadRibbonBackstage template that I extracted, for the close button, to reference my own custom implementation through a static class, in which it can check if my view model is null or not, and prevent closing. This works fine for the button click, however, the escape key still closes the backstage.  Is this because the original RibbonCommands.CloseBackstage has a keybinding to Key.Escape? 

0
Kiril Vandov
Telerik team
answered on 27 Jul 2016, 08:37 AM
Hello Gord,

About the UI lock issue we are aware of that and as you have find out changing the command for the close button is currently the only solution for it. The problem is that the command is already executed in the SelectionChanged event and the RibbonView is closing the Backstage (however it still holding resources which are not released as the UnloadedEvent is still not fired). Then we try to open the backstage before the unloaded and that is why the UI freezes.

The Escape key is designed to close the Backstage by default. This logic comes from the Backstage itself and is not executed via command. In order to remove that default behavior you will need to:
- create a CustomBackstage class
- make the class inherit from our RadRibbonBackstage
- override the HandleKey method, and in the override don\t call the base.HandleKey() (leave the method empty).

Doing so you will be able to forbid the clients from closing the Backstage when the EscapeKey is pressed.

I hope this information helps.

Regards,
Kiril Vandov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Gord
Top achievements
Rank 1
answered on 27 Jul 2016, 11:00 AM

Hello Kiril,

Thank you.  That was the last piece of the puzzle I was missing. 

Tags
RibbonView and RibbonWindow
Asked by
Michael
Top achievements
Rank 1
Answers by
Milena
Telerik team
Michael
Top achievements
Rank 1
Gord
Top achievements
Rank 1
Kiril Vandov
Telerik team
Share this question
or