Question

I am using DevExpress12.2 to develop a MetroUI liked Application for Windows 7. However, I am facing a problem that seems cannot be solved by myself.

I am using DocumentManager to create a Tile Container Page. Therefore, the DevExpress will generate a Back Button for us automatically.

User can click the back button anytime to back to the tile menu. However, in some case, such as data entry, we need to force user not to back until user is completed the operation?

Is there any event that i can catch when user click the back button? or is there any way that i can hide the back button under some condition?

Était-ce utile?

La solution

There is no embedded capability to handle the 'Back' button click, because the Windows UI Navigation concepts does not accept actions that are executed or not based on conditions that change after these actions are already shown. All the actions (navigation bar actions and embedded actions like the 'Back' button) are shown or not based on its CanExecute() method implementation.

In other words, if you need to cancel the "Back" action you should not show this action at all (to remove the "Back" navigation element you should clear the Parent property of the specific container).

Thus to prevent a user from deactivating the Page content container by using the 'Back' or 'Home' navigation action you should not include this Page content container into navigation hierarchy and navigate to this container and back from this container manually, using WindowsUIView.Controller methods and custom buttons:

WindowsUIButton customBackButton;
public Form1() {
    InitializeComponent();

    // add custom button on 'page1' container
    customBackButton = new DevExpress.XtraBars.Docking2010.WindowsUIButton();
    customBackButton.Caption = "Back to Main Tile Container";
    customBackButton.Image = ContentContainerAction.Back.Image;
    page1.Buttons.Add(customBackButton);

    page1.ButtonClick += Page_ButtonClick;
    tileContainer1.Click += TileContainer_Click;
}
void TileContainer_Click(object sender, TileClickEventArgs e) {
    page1.Document = ((Tile)e.Tile).Document;
    page1.Subtitle = ((Tile)e.Tile).Document.Caption;
    // handle 'tileContainer1' click to activate 'page1' manually
    e.Handled = windowsUIView1.Controller.Activate(page1); 
}
const string messageText = "Do you want to navigate back in Main Tile Container?";
void Page_ButtonClick(object sender, ButtonEventArgs e) {
    if(e.Button == customBackButton) {
        if(MessageBox.Show(messageText, "Back", MessageBoxButtons.YesNo) == DialogResult.Yes)
            windowsUIView1.Controller.Activate(tileContainer1); // activate container
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top