Hi all - me again :)
Been making some good progress with the backstage view, but have hit another snag. We have defined the backstage view content as a DataTemplate, which allows us to use caliburn micro to inject views into the backstage view based on the items source (a list of menu item view models).
I would like to be able to close the backstage view from within these views. Eg, clicking cancel on a form within the backstage should close the backstage view. Currently, only the root object can do so (via the BackstageOpen binding), but don't like the idea of propagating that expression down the chain.
Any suggestions ? Basically, I want to be able to bind a cancel button to something that closes the backstage view.
3 Answers, 1 is accepted
The RadRibbonView exposes a command that could be executed while the BackstageIsOpen and it is a CloseBackstageCommand. You could use that command and directly bind the button in your xaml, here is an example of how to do that:
<
telerik:RadRibbonButton
Command
=
"{x:Static telerik:RibbonCommands.CloseBackstage}"
Content
=
"Close"
/>
I hope this information helps.
Kind regards,
Kiril Vandov
Telerik
That's almost exactly what I want !
On close, I want to do a bit of cleanup though, so I created a CompositeCommand that was made up of the ribbon command, as well as my own command. That doesn't seem to work however. Maybe the Prism composite command doesn't like combining a RoutedUICommand with a DelegateCommand ...
I can't invoke the Ribbon command directly, as I don't know what the target is.
Is there a way I can clean up while closing ?
The CloseBackstageCommand is a standard RoutedUICommand and as all RouterUICommand it can be intersected in the static constructor of you your application. Once you intersect it you can execute your own logic. Unfortunately as the RadRibbonBackstage is not aware of its RibbonView you cant access it and close the backstage. We can consider exposing a public method in the RadRibbonBackstage whcih can trigger close. Until such logic is implemented you could either create a CustomBackstage and make the command and cleanup logic there. Or you could use the ApplicationMenuOpenStateChanged event of the RadRibbonView and clean your code if the backstage is closed.
I hope this information helps.
Regards,
Kiril Vandov
Telerik
Are you guys ever going to add this? It's been 8 years and I could still use it.
Or - just tell me how to invoke the CloseBackstage Telerik Ribbon Command that is already out there.
FWIW: I am already invoking this in Xaml from the backstage, but in another place in my project, I need to kick it off from my viewmodel.
I just need to do it in code, something I would expect looks like this (I just don't know what to pass it, I know what it wants for the arguments, but I am invoking this myself, so the sender is ME not the control, I can just pass it the backstage that I am using in my ribbon? What do we need to give it for the second argument to trigger this?
RibbonCommands.CloseBackstage.Execute(null, null); <=would something like this work? What am I to pass it?
There are no immediate plans to provide a public CloseBackstage method. This is mostly because, you can use the IsBackstageOpen property of the parent RadRibbonView or the CloseBackstage command.
To use the command, you need to pass the RadRibbonBackstage instance as second argument of the Execute method:
RibbonCommands.CloseBackstage.Execute(null, this.backstage);
This approach (RoutedUICommands in general) is not very suitable for usage in the view model. For that situation, I suggest you to use the IsBackstageOpen property of RadRibbonView. This will allow you to data bind it to a property in your view model, which you can set to False, in order to close the backstage. For example:
<telerik:RadRibbonView IsBackstageOpen="{Binding IsBackstageOpen, Mode=TwoWay}"/>
public class MyViewModel : ViewModelBase
{
private bool isBackstageOpen;
public bool IsBackstageOpen
{
get { return isBackstageOpen; }
set { isBackstageOpen = value; OnPropertyChanged(nameof(IsBackstageOpen)); }
}
public void CloseBackstage()
{
IsBackstageOpen = false;
}
}