Floating FB sharing byReview Results

Floating FB sharing byReview Results

  • WPF Tutorial

    • # Read in Your Language


    WPF Fundamentals

    Tutorial Home | Base classes for WPF | WPF LifeCycle

    WPF Application LifeCycle

    WPF Application:


    WPF Application when started, application object is created.

    Run method fires Applicaton.Startup event and shows main window.
    
            static void Main()
            {	Application app = new Application();
    	        Window1 win = new Window1();
    	        app.Run(win); 
            }
             

    WPF uses application model by deriving Applicaton class:


    
             <Application x:Class="TestApplication.App"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                StartupUri="Window1.xaml">
                </Application>
                
    public partial class App : Application { [STAThread()] public static void Main() { TestApplication.App app = new TestApplication.App(); app.InitializeComponent(); app.Run(); } public void InitializeComponent() { this.StartupUri = new Uri("Window1.xaml", System.UriKind.Relative); }
    See in App.g.cs file in the obj\Debug folder inside project directory.

    Application Level Events :


    Startup : Occurs after the Application.Run() method is called and just before the main window is shown

    Exit : Occurs when the application is being shut down Use the Exit event to set the integer exit code .

    Deactivated :Occurs when a window in the application is deactivated.

    DispatcherUnhandledException
    Occurs when an unhandled exception is generated anywhere in your application ( On main thread)

    Splash Screen:


    Steps:

    1. Add an image file to your project. (Typically, this is a .bmp, .png, or .jpg.)

    2. Select the file in the Solution Explorer.

    3. Change the Build Action to SplashScreen.

    When you run application, this graphic will be shown immediately, in the center of the screen, Once the runtime environment is ready, and after the Application_Startup method has finished,

    Application’s first window appears, and the splash screen graphic fades away quickly (in about 300 milliseconds).

    Command Line arguments (Accept any text file name and load ):


    
                public partial class App : Application
                {
                private static void App_Startup(object sender, StartupEventArgs e)
                {
                FileViewer win = new FileViewer();
                if (e.Args.Length > 0) {string file = e.Args[0];
                if (System.IO.File.Exists(file))
                {
    	            win.LoadFile(file);
                } 
                }
    	        else
    	        {
    	        // (Perform alternate initialization here when
    	        // no command-line arguments are supplied.)
    	        }
                // This window will automatically be set as the
                // Application.MainWindow.
                win.Show(); }
                
    //Acccessing from FileViewer public partial class FileViewer : Window { ... public void LoadFile(string path) { this.Content = File.ReadAllText(path); this.Title = path; } }


    << Previous >> | << Next Topic>>