I'm trying to write an alarm clock app for Windows Phone that requires the user to solve a math problem upon the ringing of the alarm. Right now I'm stuck, I've got the MainPage containing the settings for turning on the alarm, and when the alarm rings the user is redirected to another xaml page, one that requires the user to enter the answer to a randomly generated math problem in order to turn off the alarm. My problem is, once the user solves the problem and taps the check box, the app is supposed to first set the alarmSet value to false, and redirect the user back to the mainPage:
private void Solve_Click(object sender, EventArgs e)
{
this.userSolve = Convert.ToInt32(answerInput.Text);
if (userSolve != answer)
{
MessageBox.Show("Incorrect");
//userAnswerInt = Convert.ToInt32(answerInput.Text);
}
else if (userSolve == answer)
{
MainPage.alarmSet.Value = false;
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
}
And then when the user arrives at the mainPage, the OnLoaded method is supposed to stop the alarm sound and reset everything back to normal:
public async void OnLoaded(object sender, EventArgs e)
{
this.timer.Stop();
this.alarmSound.Stop();
alarmSet.Value = false;
this.notificationSwitch.IsChecked = alarmSet.Value;
this.timePicker.Value = new DateTime(1, 1, 1,
alarmTime.Value.Hours,
alarmTime.Value.Minutes,
0
);
if (alarmSet.Value == true)
this.alarmTimeText.Text = alarmTimeString;
else if (alarmSet.Value == false)
this.alarmTimeText.Text = "alarm off";
But the problem is, every time the user solves the math problem, they're taken back to the main page and immediately redirected back to the alarm ringing page, because the alarm is still turned on. This creates an infinite loop of alarms overlapping each other, and I can't figure out why, even though I set alarmSet.Value to false before navigating back to the main page, the alarm is still seen as on... is there something more I need to be doing? How can I have the alarm on and set to the current minute the clock is at without it ringing immediately?
I do not see an "OnLoaded" event on the Application life cycle for Windows Phone.
Refer: http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff817008(v=vs.105).aspx
You may do the following:
In Mainpage.xaml, see if the alarm is running and if the alarmSet is true, redirect user to next page under onNavigatedTo Event.
In next page, set alarmSet as false and redirect user to MainPage.xaml. The onNavigatedTo will again be fired, however, since alarmSet is false, user wont be redirected anywhere. You may do the else case of stopping alarm or anything further here.
Related
I am trying to prevent the back button being used by expiring the pages.
I have been trying to find an article on here to help and nothing works.
I have the function below that I call as the first thing on all my pages.
I call it in the Page_Load handler, is that the right place ?
I see no errors which is good, but my application just reacts as if there is no change. The back/forward buttons work and the pages display as normal and don't expire.
UPDATE:
As an added layer of security, what I want is the page to time out so if they use the "back" button they won't get the previous page. I have F5 covered so that doesn't repeat posts, and login is covered, if as I abandon the Session when they log out. But I want to stop the back button showing the previous page and force them to use the app navigation to get around my application.
I've known this functionality to fail penetration testing so I want to cover that off before I get to that point.
J
protected void Page_Load(object sender, EventArgs e)
{
MyWebApplication.SetPageStatus(Response);
....
}
internal static void SetPageStatus(System.Web.HttpResponse oResponse)
{
oResponse.ClearHeaders();
oResponse.ExpiresAbsolute = DateTime.Now;
oResponse.Expires = 0;
oResponse.CacheControl = "no-cache";
oResponse.Buffer = true;
oResponse.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
oResponse.Cache.SetExpires(DateTime.UtcNow);
oResponse.Cache.SetNoStore();
oResponse.Cache.SetRevalidation(System.Web.HttpCacheRevalidation.AllCaches);
}
I am working on a timer application for Windows Phone, and I am trying to make it so that if the remaining time on the timer is zero, a sound from a BackgroundAudioPlayer will play, regardless of whether or not the application is active, inactive, or under lock.
Currently, my issue is that the tick events don't actually do anything while the application isn't active. As soon as the user goes back into the application, the tick events run to the point that they would've otherwise, but the sound effect (or anything else) wont actually play unless the application is active, or switches to being active.
I do have in my Page.xaml.cs:
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
The relevant code is:
void dispatcherTimer_Tick(object sender, EventArgs e)
{
var remaining = this.EndTime - DateTime.Now;
int remainingSeconds = (int)remaining.TotalSeconds;
this.timeSpan.Value = TimeSpan.FromSeconds(remainingSeconds);
if (remaining.TotalSeconds <= 0)
{
this.dispatcherTimer.Stop();
button1.Visibility = Visibility.Collapsed;
button6.Visibility = Visibility.Visible;
this.EndTime = DateTime.MinValue;
this.timeSpan.Value = TimeSpan.FromSeconds(0);
BackgroundAudioPlayer.Instance.Play();
}
}
What can I do to make the tick events run while the application is under the lockscreen, or other wise not active?
Windows Phone has strict limits on background working. May be you need permission to work under lockscreen?
http://developer.nokia.com/community/wiki/Run_Windows_Phone_application_under_lock_screen
But it only stays application active under lockscreen, but not when user press windows or closes your app.
I have created a little Win Form App in C# and added the WebBrowser component to it. What i am trying to achieve is a little app that can load a local html page from a file which has "custom" protocols in it and can of course also navigate to a web address.
For example i would have entry as follows in my webpage
'Close Company</TD></TR>' which would open a task in a program.
The way i tried to achieve this was via the Navigating event as shown below
private void webBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
if ((webBrowser.StatusText.Contains("Special")))
{
//For some reason the stop doesn't do much it still tries to proceed to special:123
//diplaying can not load page..
webBrowser.Stop();
//Launch program here.
MessageBox.Show("Special Command Found");
}
}
Problem is that it still navigates and says it can't find of course the page.
I swapped Stop with GoBack which for some reason has the same issue the first time i run it and when i then select backward in the browser it works from thereon.
I also tried navigated and use of GoBack, besides having a flashing in the app from going back the event does not fire again after the first time anymore.
Has anyone any ideas how to solve this or what i am doing wrong here ?
Instead of using WebBrowser.Stop();
just set e.cancel = true;
I have an application for Windows 8 with a page (Frame) for displaying a list of items and a page for downloading & displaying the items details. I am also using MVVM Light for sending notifications.
Application use goes something like this:
Open Main Page
Navigate to List Page
Frame.Navigate(typeof(MyPage));
Choose Item
//Complete logic
Frame.GoBack();
Back on Main Page, I start downloading the file in the view model, I send ONE NotificationMessage saying BeginDownloadFile and after it is downloaded ONE NotificationMessage saying EndDownloadFile.
The first time I do steps 2,3, & 4 my NotificationReceived method is hit once, the second twice and so forth.
private async void NotificationMessageReceived(NotificationMessage msg)
{
if (msg.Notification == Notifications.BeginDownloadFile)
{
FileDownloadPopup.IsOpen = true;
}
else if (msg.Notification == Notifications.EndDownloadFile)
{
FileDownloadPopup.IsOpen = false;
}
}
Additional information: I only have one FileDownloadPopup, yet each time, an additional popup is shown each time the NotificationMessageReceived method is called.
My only conclusion is that between navigating forwards and backwards in my app, there are multiple MainPages being created and never closed. This results in many NotificationsMessageReceived methods just waiting for a notification to come their way so they can show their popup.
I have two questions:
1. Does this sound like normal behaviour for a Windows 8 app?
2. How can I close all instances of the MainPage or return to the previous instance without creating a new instance?
Please let me know if I have missed something important out before marking my question down.
This sounds normal to me. The default navigation behaviour in Windows 8 is to create a new page instance each time you navigate to a new page, regardless of whether this is forward or back navigation.
Try setting the NavigatinCacheMode on MainPage to Required. See the MSDN documentation for details of how page caching works.
It sounds like you are registering eventhandlers in the page and then not removing them. Each time you navigate to the page again the handler is being added again in addition to the one you previously added. Try to add your event handler in OnNavigatedTo, and make sure you unregister it in OnNavigatedFrom.
protected override void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
MyEvent.OnDownloadRequest += MyLocalDOwnloadHandler; // add the handler
}
protected override void OnNavigatedFrom(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
MyEvent.OnDownloadRequest -= MyLocalDOwnloadHandler; // remove the handler
}
In the application I am working with, if the user changes the value in a cell that is say positive to negative and the value is supposed to be positive at all times, the application forces the positive value. Right now, when this happens there is no alert shown to the user.
I would like to show a little unobtrusive alert, like the one that shows up when a new mail arrives in outlook, or something similar, so that the user can be alerted that the application did something on her behalf.
I tried using the NotifyIcon class to do this. But the problem with that class seems to be that the timeout on it doesn't work as expected. I want to show this alert for not more than 2s and the BallonTipText lasts for longer than 10s.
Is there a .NET class for this purpose?
If not, is there an alternate way to do something like this?
Using a notification icon for this case seems wrong to me. The user's attention is, when entering something into a cell, on the cell. If you display the notification on the lower right of the screen the user is very likely to miss it, or worse, it disrupts his work flow.
You might instead consider adding a balloon tip to the cell the user is editing. Kinda like the balloon tip Windows Explorer is showing on Vista and Windows 7 on renaming a file when you try entering a character that is disallowed in file names:
I have had this problem in the past. I gather that the timeout problem is because the operating system fixes a minimum value of 10 seconds and a maximum value of 30 seconds (or something like that).Edit Oh and this doesn't include time that a user is idle.Edit
I have used the following code in the past to get around this.
Just to clarify
Declare a public variable, say called ballonTipActive with a value of 0.
Insert a timer control disabled with 100ms delay and create an event from BalloonTipShown from the notifyicon control.
Then
private void ptNotifyIcon_BalloonTipShown(object sender, EventArgs e)
{
timer1.Enabled = true;
balloonTipActive = 0;
}
private void timer1_Tick(object sender, EventArgs e)
{
balloonTipActive++;
if (balloonTipActive == 40)
{
ptNotifyIcon.Visible = false;
ptNotifyIcon.Visible = true;
balloonTipActive = 0;
timer1.Enabled = false;
}
}
Setting the visible property to false then true gets rid of the balloon.