Cast event sender to Window with as : Window « Windows Presentation Foundation « C# / CSharp Tutorial






using System;
using System.Windows;
using System.Windows.Input;

    class MainClass
    {
        [STAThread]
        public static void Main()
        {
            Application app = new Application();

            Window win = new Window();
            win.Title = "Handle An Event";
            win.MouseDown += WindowOnMouseDown;

            app.Run(win);
        }
        static void WindowOnMouseDown(object sender, MouseButtonEventArgs args)
        {
            Window win = sender as Window;
            string strMessage =args.ChangedButton +":"+ args.GetPosition(win);
            MessageBox.Show(strMessage, win.Title);
        }
    }








24.70.Window
24.70.1.Window ResizeMode=CanMinimizeWindow ResizeMode=CanMinimize
24.70.2.Set Window Height and WidthSet Window Height and Width
24.70.3.Window OwnershipWindow Ownership
24.70.4.Launch a window with defined XAMLLaunch a window with defined XAML
24.70.5.Hosting a Windows Forms Property Grid in WPFHosting a Windows Forms Property Grid in WPF
24.70.6.Order of precedence for sizing-related properties that are implemented by Window.Order of precedence for sizing-related properties that are implemented by Window.
24.70.7.Animated Video WindowAnimated Video Window
24.70.8.Use WindowState to make full screen window, change resize mode to NoReSizeUse WindowState to make full screen window, change resize mode to NoReSize
24.70.9.Creating the main panel and add to Window in CodeCreating the main panel and add to Window in Code
24.70.10.Is Window activeIs Window active
24.70.11.Load the Data for a Window Asynchronously After It Has RenderedLoad the Data for a Window Asynchronously After It Has Rendered
24.70.12.Change window cursorChange window cursor
24.70.13.Show window based on button nameShow window based on button name
24.70.14.Activate window, close window, bring window to frontActivate window, close window, bring window to front
24.70.15.Load resource from Window ResourcesLoad resource from Window Resources
24.70.16.Save Window Position to RegistrySave Window Position to Registry
24.70.17.Center a Window to ScreenCenter a Window to Screen
24.70.18.Set a Default ButtonSet a Default Button
24.70.19.Use the Grid to create a dialog box that uses the WPF layout APIUse the Grid to create a dialog box that uses the WPF layout API
24.70.20.ShowInTaskbar = falseShowInTaskbar = false
24.70.21.SizeToContent=WidthAndHeightSizeToContent=WidthAndHeight
24.70.22.ResizeMode=CanResizeWithGripResizeMode=CanResizeWithGrip
24.70.23.Set the DataContext of a Window to a person objectSet the DataContext of a Window to a person object
24.70.24.DataContext with user defined objectDataContext with user defined object
24.70.25.Add Button to window content
24.70.26.Not show Window in Taskbar
24.70.27.extends Window
24.70.28.Window loaded event listener
24.70.29.Set window Startup Location
24.70.30.Change window resize mode
24.70.31.Set window start up location
24.70.32.Set WPF window title
24.70.33.Set WPF window width and height
24.70.34.Passing Window instance to Application run method
24.70.35.Listen to window mouse down event
24.70.36.Cast event sender to Window with as
24.70.37.Register and Handle Window event in code
24.70.38.Create Canvas as content of window
24.70.39.Create new windows in Application start up event
24.70.40.Create new window and add mouse down event listener
24.70.41.Display text on to window content
24.70.42.Assign TextBlock to window content