10 Answers, 1 is accepted
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:
I hope this information will help you and don't hesitate to write back if you have more questions.
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;
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.
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.
Telerik by Progress
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?
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.
Telerik by Progress
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?
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.
Telerik by Progress
Thank you. That was the last piece of the puzzle I was missing.