When 'Cancel' button is pressed to stay on the page, the ApplicationBar is vanishing

4 posts, 1 answers
  1. Shantimohan
    Shantimohan avatar
    42 posts
    Member since:
    Jul 2012

    Posted 15 Jul 2012 Link to this post

    I am using RadMessageBox inside the OnBackKeyPressed event with some plumbing necessary to manage the non-modal running.

    For either Save or Discard button, finally I GoBack(). So I don't have any problem. But when the cancel is pressed, I want to stay in the current page. Yes, it does stay in the current page but the ApplicationBar is vanishing.

    My code is as below:
    protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
    {
        if (popup1.IsOpen)
        {
            popup1.IsOpen = false;
     
            e.Cancel = true;
        }
        else
        {
            if (TaskModified())
            {
                if (!isBackKeyInProgress)
                {
                    RadMessageBox.Show(new CustomHeaderedContentControl[]
                {
                    new CustomHeaderedContentControl() { Title = "Save", Message = "This details will be saved to the database." },
                    new CustomHeaderedContentControl() { Title = "Discard", Message = "This details will NOT be saved to the database." },
                    new CustomHeaderedContentControl() { Title = "Cancel", Message = "Returns to the details for further editing." }
                },
                "Back Key Pressed",
                "You are about to close the details editor. What do you want to do?",
                closedHandler: (args) =>
                {
                    // ClickedButton will be null in the case when RadMessageBox is closed because the user pressed the hardware back button.
                    if (args.ClickedButton == null)
                    {
                        DiscardTask();
                    }
     
                    CustomHeaderedContentControl option = (CustomHeaderedContentControl)args.ClickedButton.Content;
                    if (option.Title == "Save")
                    {
                        SaveTask(false);
                    }
     
                    if (option.Title == "Discard")
                    {
                        DiscardTask();
                    }
     
                    if (option.Title == "Cancel")
                    {
                        // Return to editing the task.
                        SystemTray.SetProgressIndicator(this, null);
                        return;
                    }
                });
     
                isBackKeyInProgress = true;
                e.Cancel = true;
            }
        }
     
        if (!isBackKeyInProgress)
            NavigateBack(true);
        SystemTray.SetProgressIndicator(this, App.sysProgressBar);
    }

    How can I make the ApplicationBar not vanish? Was it because I am using it in the OnBackKeyPressed event?

    ThanQ...
  2. Shantimohan
    Shantimohan avatar
    42 posts
    Member since:
    Jul 2012

    Posted 15 Jul 2012 Link to this post

    Just after posting the above, I thought I should try to set ApplicationBar.IsVisible = true; But I am getting the NullReferenceError. That is ApplicationBar is lost. Is this a bug?

    I am using the latest internal build 2012.2.0713 version.
  3. DevCraft banner
  4. Answer
    Victor
    Admin
    Victor avatar
    1351 posts

    Posted 16 Jul 2012 Link to this post

    Hello Shantimohan,

    Thanks for writing.
    This turns out to be a bug in WP Silverlight framework. When you try to to open RadMessageBox, the RadWindow instance in the message box fails to open because it relies on a LayoutUpdated event that does fire while the OnBackKeyPress method is executing. You can workaround this by making sure that RadMessageBox show is called after OnBackKeyPress. This  can be done with Dispatcher.BeginInvoke().

    Please write again if you need further assistance.

    All the best,
    Victor
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Shantimohan
    Shantimohan avatar
    42 posts
    Member since:
    Jul 2012

    Posted 16 Jul 2012 Link to this post

    Despatcher.BeginInvoke(() => ... ); worked magically.

    ThanQ...
Back to Top