How to Navigate Back from Popup in Windows Phone8 - c#

here i have this problem with popup window, i popup an usercontrol in a dll and call this dll in an app, but it shows upon a black page that i have no idear where its from. when i push the '<-' button ,the app directly exit... i can't go back to the app's mainpage where calls it.
I wonder how can I return from the popup window. I tried to hide the popup window, but it doesn't go back to app's mainpage.
public void change_PIN(OnCCB_ChangeUserPINCall changeUserPINCall)
{
Popup ppChangePIN = new Popup();
ChangePIN changePIN = new ChangePIN();
ppChangePIN.Child = changePIN;
ppChangePIN.IsOpen = true;
}
How can I set ppChangePIN.IsOpen=false inside popup window .cs to make it disappear?

Handle back key press event of back button like
step1: first set one flag when popup is open like **bool PopupOpen=True**
step2: When popup is close at that time PopupOpen=False
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
if(PopupOpen== True)
{
ppChangePIN.IsOpen=false;
PopupOpen=False;
e.Cancel = true;
}
else
{}
}
If any query let me know...
hope it work for you

private bool RemovePopup()
{
if (ppChangePIN == null || !ppChangePIN.IsOpen)
return false;
ppChangePIN.IsOpen = false;
return true;
}
protected override void OnBackKeyPress(CancelEventArgs e)
{
if (RemovePopup())
e.Cancel = true;
}

Related

WPF Detecting Window Close Event and coupling with a button event

For two days, I have tried various methods for making it so that on loadButton click, it opens a secondary window and disables the loadButton; Then, when that secondary window has been closed, the loadButton will be re-enabled. Although, obviously all of my attempts have been unsucessful.
I have been reading about using the isClosing event, although, I haven't figured out how to properly implement it. So I decided to go with this route.
private void loadButton_Click(object sender, RoutedEventArgs e)
{
var richWindow = RichTextWindow.GetWindow(new RichTextWindow());
if (richWindow.IsActive != true)
{
loadButton.IsEnabled = false;
richWindow.Show();
}
else
{
loadButton.IsEnabled = true;
}
}
Issue here is, the first half is executed. Once I click the loadButton, it does disable. However, on closing the new Window, the loadButton is still disabled.
Could anyone point me in the right direction on where I need to go with this?
I think what you want is something like this:
private void loadButton_Click(object sender, RoutedEventArgs e)
{
var richWindow = RichTextWindow.GetWindow(new RichTextWindow());
richWindow.Closed += (s, e) => loadButton.IsEnabled = true;
loadButton.IsEnabled = false;
richWindow.Show();
}
Basically, disable the button before opening the window. Then, listen for the window to close and enable the button again.
richWindow.Loaded +=
{
loadedButton.IsEnabled = false;
};
richWindow.Closing +=
{
loadedButton.IsEnabled = true;
}

Manipulate control on other form

I'm trying to manipulate a PictureBox(pBATalk) to show whenever I close a form(PAInput). So basically I want to show a picture, whenever the 2nd form is closed.
2nd Form
public void PAInput_FormClosing(object sender, FormClosingEventArgs e)
{
this.Hide();
fPAMain.PATalkActive(false);
e.Cancel = true;
}
MainForm:
public void PATalkActive(bool active)
{
//MessageBox.Show("");
if (active == true)
{
pBPATalk.Hide();
}
if (active == false)
{
pBPATalk.Show();
}
}
Whenever I close PAInput it will trigger PATalkActive, but will only fire the MessageBox.Show(""); and not the pBATalk.Hide(); or pBATalk.Show();
Well, I'm not so sure about what you are trying to accomplish here but first of all you're keeping PAInput open, with this line e.Cancel = true . Besides that, MessageBox.Show(""); will open a modal window displaying a text, until it is closed the rest of the method won't run.

Windows Phone 8 Back button to go back in WebBrowser

I made a WebBrowser and it works except the back button after pressing the back button the app closes and does not go back one in history. How can I solve the problem? I found solutions in the internet but they don't seem to work.
public MainPage()
{
this.InitializeComponent();
this.webBrowser.Navigate(new Uri("http://www.google.com", UriKind.Absolute));
this.webBrowser.LoadCompleted += webBrowser_LoadCompleted;
this.webBrowser.NavigationFailed += webBrowser_NavigationFailed;
this.webBrowser.IsScriptEnabled = true;
}
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
webBrowser.InvokeScript("eval", "history.go(-1)" );
}
P. S.:that is not the whole script but i think the rest is unneccesary if not tell me :)
P. P. S.:I'm new to Windows Phone programing.
Web browser is just a control inside the page and pressing the device back button navigates back to the previous page or exits the app if it has only one page. So, you would need to stop page navigation on back key press something like this.
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
e.Cancel=true;
}
This prevents a backnavigation
Now rest is to go to the previous page which can be done by
webBrowser.InvokeScript("eval", "history.go(-1)" );
so the event becomes
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
e.Cancel=true;
webBrowser.InvokeScript("eval", "history.go(-1)" );
}
Try to do:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
WB1.InvokeScript("eval", "history.go(-1)");
e.Cancel = true;
}
When you override OnBackKeyPress, and you don't perform e.Cancel = true; it will do your code, but will also do what normal BackButton does - NavigateBack, Exit App and so on. But you must remember to leave the User an ability to exit your App or Navigate Back, so it will be more suitable to check some conditions (e.g. your webbrowser history is not null) and then do e.Canel, otherwise Exit the App.
To exit the app when you are in the root (so you can approve the cerfitication requirements), and also go back in navigation until you are in the root, try with this
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
if (MiniBrowser.CanGoBack){
e.Cancel = true;
MiniBrowser.InvokeScript("eval", "history.go(-1)");
}
}

Want to show UserControl page on app startup

I have recently created an application for wp7. Now i am ready submit an update for my app. In the i have added a UserControl page(contains a dialog box). I want it to displayed on the MainPage.xaml or in app startup but only for the first app launch. I know how to show a MessageBox for the first time but don't know how to show a xaml page.
if (!IsolatedStorageSettings.ApplicationSettings.Contains("IsFourthLaunchDone"))
{
MessageBox.Show("To Enable Full screen mode, go to settings and select Full Screen Browsing.");
IsolatedStorageSettings.ApplicationSettings["IsFourthLaunchDone"] = true;
}
Can anybody help me with this? Thanks in advance for your help!
Here's an idea of how this is properly done with a MessageBox.
App.xaml.cs:
public static bool IsFourthLaunch = false;
ApplicationLaunching(){
if (!IsolatedStorageSettings.ApplicationSettings.Contains("IsFourthLaunchDone"))
{
IsFourthLaunch = true;
}
}
MainPage.xaml.cs:
MainPage()
{
if (App.isFourthLaunch)
{
Loaded += OnFourthLaunch;
}
}
public void OnFourthLaunch(object sender, RoutedEventArgs e)
{
Loaded -= OnFourthLaunch;
if (App.IsFourthLaunch)
{
MessageBox.Show("To Enable Full screen mode, go to settings and select Full Screen Browsing.");
IsolatedStorageSettings.ApplicationSettings["IsFourthLaunchDone"] = true;
App.IsFourthLaunch = false;
}
}
To do this with a UserControl, add the Control to the page, initially with a Collapsed Visibility. In the scenario you want to display it, change the visibility to Visible. You'll need to figure out in what way you want the Control to work, and probably you'll need to override OnBackKeyPress to provide a logical way for the user to close your control.
protected override void OnBackKeyPress( System.ComponentModel.CancelEventArgs e )
{
if (myControl.Visibility == Visibility.Visible)
{
e.Cancel = true;
myControl.Visibility = Visibility.Collapsed;
}
}

Emulate ShowDialog for Winforms UserControl

I would like to achieve the same effect like in this article but for windows forms, is it even possible without hosting the control on different Form?
EDIT
I'm more interested in implementing the exact behavior of the control in the article, showing the control on the form and blocking the calling function, but without using other form for this purpose.
You can create a UserControl with the two buttons and the label for the message, then set its visibility to false in the constructor:
public MyDialog()
{
InitializeComponent();
Visible = false;
}
Then you add three variables to the control:
Form _parent;
bool _result;
bool _clicked = false;
the parent Form will be the Form your control is contained in and must be set before using the control, since it has to know what has to be disabled.
public void SetParent(Form f)
{
_parent = f;
}
_result will contain the result of the dialog, and _clicked will be used to determine when to close your dialog. What has to be done when you show your dialog is:
set the label
disable the form (but not the dialog)
make the dialog visible
wait for the user to click one of the buttons
hide the dialog
reenable the parent form
return the result
So you could add this method to enable/disable the parent form:
private void ParentEnabled(bool aBool)
{
if (_parent == null)
return;
foreach (Control c in _parent.Controls)
if (c != this)
c.Enabled = aBool;
}
and use it in the ShowDialog method:
public bool ShowDialog(string msg)
{
if (_parent == null)
return false;
// set the label
msgLbl.Text = msg;
// disable the form
ParentEnabled(false);
// make the dialog visible
Visible = true;
// wait for the user to click a button
_clicked = false;
while (!_clicked)
{
Thread.Sleep(20);
Application.DoEvents();
}
// reenable the form
ParentEnabled(true);
// hide the dialog
Visible = false;
// return the result
return _result;
}
Obviously the buttons have the responsibility to set the _result and _clicked variables:
private void okBtn_Click(object sender, EventArgs e)
{
_result = true;
_clicked = true;
}
private void cancelBtn_Click(object sender, EventArgs e)
{
_result = false;
_clicked = true;
}
How about creating transparent form that in the middle contains text on opaque shape (whatever you like). Then at runtime you would resize this form to have same size as the window over which you want to display it and place it so that it covers it.

Categories

Resources