Class: Window

Namespace: System.Windows

Library: PresentationFramework

For the creation a subclass of Window you can use a .XAML file having the name of the subclass. By example:Window1.xaml:

<Window  
  xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
  xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
  x:Class="DMU.Window1"
     
  Title="DMU Tutorials Serie"
  Top="100"
  Left= "100"
  Width="400"
  Height="400"

  Loaded="OnLoaded"
>
  
</Window>

And you need also a Window1.xaml.cs file:

//This is a list of commonly used namespaces for a window. Not all used here.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;

namespace DMU{
 public partial class Window1 : Window{
  
  public Window1(){
   InitializeComponent();
  }

  private void OnLoaded(object sender, EventArgs e){
    //... 
  }
    
 } 
} 

At the MyApp.xaml.cs file you need to create an object of the subclass and show it:

using System;
using System.Windows;
using System.Data;
using System.Xml;
using System.Configuration;

namespace DMU{
  public partial class MyApp : Application{

    void AppStartingUp(object sender, StartupEventArgs e){
      Window1 mainWindow = new Window1();
      mainWindow.Show();
    }

  }
}

There are many properties of the Class whose values is better to assign at the .XAML file, but can be assigned at any place.

Background

The value will be a color. There are many colors available for WPF users. Some (you can find more in the SDK Documentation):


AntiqueWhite  Aqua  Aquamarine  Beige  Black  Blue  Brown   BurlyWood  CadetBlue   Chocolate   CornflowerBlue  Cyan   
DarkBlue   DarkCyan   DarkGray   DarkGreen   DarkKhaki   DarkMagenta   DarkOliveGreen   DarkOrange   DarkRed   
DarkSalmon   DarkSeaGreen   DeepPink   DeepSkyBlue   FloralWhite   ForestGreen   Fuchsia   GhostWhite   Gold   Goldenrod   
Gray   GrayText  Green   GreenYellow   HotPink   IndianRed   Indigo   Khaki   Lavender   LavenderBlush   LemonChiffon   
LightBlue   LightCoral   LightCyan   LightGoldenrodYellow   LightGray   LightGreen   LightPink   LightSalmon   LightSeaGreen   
LightSkyBlue   LightYellow   Lime   LimeGreen   Magenta   MidnightBlue   MintCream   MistyRose   Navy   Olive   Orange   
OrangeRed   Orchid   PapayaWhip   PeachPuff   Pink   Plum   PowderBlue   Purple   Red   RoyalBlue   SaddleBrown   Salmon   
SeaGreen   SeaShell   Sienna   Silver   SkyBlue   SlateBlue   SlateGray   Snow   SpringGreen   SteelBlue   Tan   
Teal   Tomato   Transparent   Turquoise   Violet   White   WhiteSmoke   Yellow   YellowGreen   

BorderBrush

Also a color.

BorderTickness

Height

Left

Margin

Name

Opacity

Title

Top

Visibility

Width

And some methods:

Close()

Focus()

Hide()

Show()

The main events. To be overrided.

Closing

GotFoccus

KeyDown

KeyUp

Loaded

And some mouse events:


  MouseDoubleClick    
  MouseDown    
  MouseEnter    
  MouseLeave    
  MouseLeftButtonDown    
  MouseLeftButtonUp    
  MouseMove    
  MouseRightButtonDown   
  MouseRightButtonUp    
  MouseUp    
   



PREVIOUS LESSON NEXT LESSON
T.CONTENTS HOMEPAGE