0

Please explain in code how to handle unlock screen event for 8.1 app. i actually want to read next line from a text file and display it on my notification area every time my screen is unlocked.please explain in detail as i am new to c#.

where to write this code in MainPage.xaml.cs ?!

PhoneApplicationFrame rootFrame = (Application.Current as App).RootFrame;
rootFrame.Obscured += OnObscured;
rootFrame.Unobscured += Unobscured;
void OnObscured(Object sender, ObscuredEventArgs e)
{

}
void Unobscured(Object sender, EventArgs e)
{

}
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Mehul Parmar
  • 347
  • 4
  • 21
  • 1
    Welcome to Stack Overflow. Please take a moment and read [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) and [What topics can I ask about here?](http://stackoverflow.com/help/on-topic). Questions asking us to give you an answer without any **code example** of what you tried is off topic. – Erik Philips Feb 06 '15 at 22:33
  • @ErikPhilips have a look now – Mehul Parmar Feb 06 '15 at 22:49

1 Answers1

0

From what I can see I can conclude that this this code:

PhoneApplicationFrame rootFrame = (Application.Current as App).RootFrame;
rootFrame.Obscured += OnObscured;
rootFrame.Unobscured += Unobscured;

should be put into constructor of you App class(in App.cs file), so eventually it will look like:

public class App
{
    // more code could be here

    public App()
    {
         PhoneApplicationFrame rootFrame = (Application.Current as App).RootFrame;
         rootFrame.Obscured += OnObscured;
         rootFrame.Unobscured += Unobscured;
    }

    // and some code could be here

    void OnObscured(Object sender, ObscuredEventArgs e)
    {    
    }

    void Unobscured(Object sender, EventArgs e)
    {    
    }     

    // and even here
}

p.s./offtop/ general advice: if you're new to c# then it would make more sense to learn c# first and only then dive into winphone/asp/desktop/etc development. That's what my personal experience tells me.

hope this helps

alex.b
  • 4,547
  • 1
  • 31
  • 52
  • i am writing that code in public app() constructor ... but the following line is showing error.... " PhoneApplicationFrame rootframe =(Application.Current as App).RootFrame;.........ERROR-Member 'LockScreenNotification.App.RootFrame.get' cannot be accessed with an instance reference; qualify with an type name; – Mehul Parmar Feb 07 '15 at 06:45
  • 1. please post all code 2. learn c# basics, I doubt that any significant progress is possible without that – alex.b Feb 08 '15 at 03:31