Namespace in WPF Application with Examples

By
Hi Friends, Today, I will discuss about Namespace in WPF. Before developing any WPF applications ,we have to understand the concepts of Namespace in WPF Application.There are lots of students in the world ,they can develop any WPF applications easily.But they don't know about Namespaces. This is not Good for a .NET Developers.If you are working in company then you will need to this knowledge otherwise you will never develop any unique application.Before developing any things ,We would understand its basics parts.Now we shall understand about Namespace and Layout controls in WPF Application.
When we install the .Net Framework 3.0/3.5/4.0/4.5 on your system then you will find a number of assemblies have been added  to the GAC. These assemblies provide references to our .net applications.These assemblies define a number of new namespaces and lots of NET Types(classes, structures, enumerations ,interfaces and delegates).
There are three Core WPF assemblies as given below:-
  1. WindowsBase .dll :-   This is helpful to define the core types and constitute the infrastructure of the wpf API.
  2. Presentationcore.dll:- This defines many types that constitute the foundation of the WPF GUI layer.
  3. PresentationFoundation.dll:- This dll defines the WPF controls types multimedia and animation support,data binding support , and other WPF services. 
There are some Namespaces used in above Assemblies files as given below:-
  • System.Windows:- This is main namespace of WPF. This includes two core types  such as Window and Application that are required any WPF desktop applications.
  • System.Windows.Controls :-  This is helpful to build WPF Widgets such as  menu systems, tool tips and numerous  layout managers.
  • System.Windows.Navigation :-  This namespace helps to provide  Navigation logic for XAML Browser Applications.
  • System.Windows.Markup :- This defines a number of types that allow XAML Markup to be parsed  as binary format.
  • System.Windws.Media :- This namespace provides animations,3D Rendering and other primitives multimedia for WPF applications.
  • System.Windows.shapes:-  This names defines basic geometric shapes such as Rectangle,hyperbola,elliptic .polygon,etc. Using this namespace, we can make any shapes for WPF Applications. 
There are some roles of Application and Window classes as given below:-
1.) Application Class :- The System.window.Application class type represents a global instance of a running WPF application.This is helpful to handle the series of events such as Startup and Exit .
There are some properties of Application Type as given below:-
  • Mainwindow :-This property allow us  to  get and set  the main window of the application programmatically.
  • Current :- This is very useful property that allows to gain access to the running application object from anywhere in your code. 
  • Properties :- This property allow us to establish and get data that is accessible throughout a WPF application.
  • StartupUri :- This property helps to get and set a URL that specifies a window to open  automatically when the wpf application starts.
  • Windows :-This property is helpful to return a WindowCollection type.which provides access to each window created from the thread that created the application object.
Example:-

using System;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// 
    /// Interaction logic for MainWindow.xaml
    /// 
    public partial class wpfApp : Application
    {
        static void main()
        {
            wpfApp wp = new wpfApp();
            wp.Startup += new StartupEventHandler(wp_Startup);
            wp.Exit += new ExitEventHandler(wp_Exit);
            wp.Run();
        }
        static void wp_Exit(object sender, ExitEventArgs e)
        {
            MessageBox.Show(" Application has successfully exited");
        }
        static void wp_Startup(object sender, StartupEventArgs e)
        {
            Window my_window = new Window();
            my_window.Title = "Welocme to my first wpf application";
            my_window.Height = 200;
            my_window.Width = 300;
            my_window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            my_window.Show();
        }
    }
}

2.)  Window class:-  The System.Windows.Window  type represent a single window owned by application derived class. This is included any dialogs displayed by the main window.
There are some hierarchy of the window Type ,this is helpful to support many features in window class object as given below:-
  • System.Windows.Controls.Contentcontrol:-This base class provides derived types with the ability to host content. A content control has the ability to contain a great number of UI elements beyond simple string data.
  • System.Windows.Controls.Control:- This control defines properties to establish the control's size ,tab order logic,opacity,background color,cursor to display etc.
  • System.Windows.UIElement:- This class provides more events to account  for drag and drop operations,mouse movement ,keyboard input ,stylus input etc.
  • System.Windows.FrameworkElement:- This framework Element  supports for WPF data binding services and the ability to participate in WPF style model.
  • System.Windows.Media.Visual:-  This class is helpful for Media and Graphical rendering operations such as painting a pie on a window's surface.
  • System.Windows.DependencyObject:- This property allows a type to compute the value of a property based on the value of other property.This is very helpful when programming against the WPF data binding model.I will discuss it in details in Our coming post.
  • System.Windows.Threading.DispatcherObject:- This provides the basic constructs for dealing with concurrency and threading .This lower level class that can be ignored by the majority of your WPF applications.

0 comments:

Post a Comment

Powered by Blogger.