In this video will try to understand
what is WPF and why do we need WPF so let's first
start with the full form of WPF. WPF stands
for Windows Presentation Foundation, WPF is nothing but it's graphical subsystem by which you can go and display user
interfaces in Windows application so the next
question which you ask is basically why do we need one more
graphical system then we already had been forms if you remember right you can always go and create a project in Winform in which will help you to create user
interfaces for business applications like this site so when you already had been forms why
do we need one more graphical system like WPF and the reasons are A, B, C, D E, F and G so let me go through each of these reason step-by-step so that you can get convinced that the
WPF is far superior than Winforms so let's start with the first point
A, Any Where Execution Any where execution means you
know you can create your UI once in WPF and then you can run it as Windows form I'll say a Win application are you can run it as
a Web Application so now you was be wandering that how it is possible to execute WPF application on multi platforms if you go and create a WPF
application so you can see what I've done as you know because we are doing the comparison with Windows also I have created two projects here one is a Widows projects and other
one is a WPF application right so if you go and see a WPF application UI right now if you want to create a WPF application
very quickly you need to go and use the WPF application template so by
using this template I have created this UI over here which is a WPF UI right, now if you go and see the WPF UI now that two parts to
it one as you can see that we have a XML
here this XML is termed as Xaml you can also see the file
notation or the file extension here as Xaml so this XML is
red and rendered as WPF UI in
other words the internal representation of WPF UI is XML now anything you know why is the internal representation as XML
think about WCF services why the use XML think about Web services why the use
XML absolutely right XML is use you know when have two systems you know which are heterogeneous in
nature so for example in WCF services you know you have C#
at one end and then you have JAVA at other end that so that's why you use
XML so here also they have kept that internal representation as XML so that you know they can create the UI
once in XML and then they can render it on a Win application or on a Windows
platform like a exe or they can run it as a Web
application inside the brouser and on the other side if you see a
Winform farm so if you go and open a windows form
and if you see the internal representation of the UI it
is a C# code it is a C# object
right so it's very difficult now to take this
C# object this UI object and you can see this UI object is very specific again you can see System.Widows.Form so I don't know how I can take this
behind code and i can put it into a web application right so here you know in WPF the start itself is very great it's awesome that
complete internal representation of the UI UI is in XML format so can take this XML format and then run it as Winform or you can run it as a Web Application so let me show you a
small demo here you know how this whole thing works so you can see here I have selected this WPF application and if I run this I do a Ctrl+F5
I see this screen here right so if you want to go and move this to
a Web Application what you can do is you can create a WPF Web okay so if you go here so i let me go and add project so if you
see that is a project template here called as WPF
browser Or you can also term it has WPF Web ok so you can go and create a WPF browser application here night now you can see I have copied that XML code you know for the buttons and the text box and I will just go and
be still over here so I will just to Ctrl-V and if I now go and run this now this is
a WPF browser application. Ok so if I do a Ctrl - F5 now you can see that the same screen is now
running inside the browser right, and here is my WPF Winforms application
So you can see this is my WPF browser application or WPF Web right and this is my Winforms application right, so the top on is the a browse it
you can see the browser here Internet Explorer and this one is my windows, my WPF
Windows application so because you know our internal
representation was XML format so this XML format is red and it can
be rendered in any platform now so the render the render the WPF render can run and
render this UI on a Web as well as on Windows so these the first big point of WPF which I like anywhere execution you right the Xaml once and then you can run it on as a web application or as a Windows application now the next thing which makes WPF better than Winforms is B. B for Binding so let's go into more details on
the bindings now when we talk about WPF
applications WPF application will create objects and at some moment of time these objects
would like to communicate with each other in other words you know they would
like to send data or they would like to receive data from
other objects. right for example you can see on the screen I
have two text boxes and you know that can be scenario
you know where I want these two text boxes to communicate with each other for
example you know when I type on this text box I
would like the data to be sent to this text box and when I type on this text box I would
like to send data to this text box so in other words you know both of them are objects at the end of the day and they would like to
communicate with each other Now if I want to implement this in Winforms then I would have to go to the exchange of each text box and set data to the other text box in other words you know lot of coding right but here in WPF you just go and you set the bindings
and is done so for example over here now let's say that this is the text box 1 ok.so one of the text box is text box 1 TXT 1
I'm sorry another one is TXT 2 right. so what I can do
now as I can go to the properties of one of those text
boxes. for example let me take the left hand text books here that is TXT 1 so I can see that I want to go and bind
the Text property here so I want to bind the TXT 1 property
Text property to the other Text box so so you can see i'm saying I want to bind.The bind the
Text property of TXT 1 with the Text property of TXT 2
so TXT 2 right so you can see here at the top TXT 1 Text will change when
TXT 2 Text will change why because I'm creating a binding between them and I'll see ok why for go and run this
application here very quickly so if i say Ctrl F5 here so the error
application is running so now if I see here like Text 1 so this data of Text 1 which
are written gets update to Text 2 if I see here like Text 2 or you can see
how it is updating text 1. right so you can see that you know by just setting simple bindings I'm able to
establish connection between both of these objects so again this is one more big
advantage of WPF or Windows that you don't have to write too much
code and you can just said the bindings and established connection
between two objects again you know when I saw objection it
is not just text boxes probably would like to connect this text
boxes to a customer object at back end right so even that is possible with
bindings so first benefit of WPF anywhere execution second benefit of WPF bindings Now the 3rd benefit again of
WPF or i will say advantage of WPF over Windows is common look & feel C -- common look and
feel so A -- anywhere execution, B --bindings and C -- common look & feel so what
exactly is this common look & feel now let's say if you want to go and I'll you know set common look and feel for your buttons and text boxes for example it so
that you want to go and see that all of your text boxers in your
Windows form should have a back groud color of blue
right so in Winformss you know you cannot go and define a common look and feel in the Apply overhere right you have to go to every text properties
in other words you to go to every text property here you know go and set the background color for each one of them right Which is TDS right so in WPF a what you can do is very quickly and WPF you can go and
create something called the state's so you can go in WPF here okay we are go into styles letter on in-depth but for now you know I'm just trying to
make you understand the important advantages of WPF over Winforms okay so we are go to have you know separate topics on styles,
separate topics on binding right but you know this lecture you know i want to just ensure that that you understand how WPF is superior than Winforms so like I can just go and create a style
here so for example I can go and create a style here, I will explain all the
syles in textes later on so you can see now I am saying here you know the font size on the textbook should be Fourteen you know the hight of the text box should be 40, you
know when I move my cursor on the text box I should see
a hand right so I have define a common look and feel here now what I can do I can go to
my text box here okay I can go to both of my text boxes
and I can say F4 so properties and I can see that
can you go and bind the style of these text boxes so very quickly can you go and bind the
style to the style which I have just created okay I think we can bind style in one go
so let me go one by one so I can go here and say F4 and see that okay I want to go and create the data binding which will actually go and so I am to go and apply a style to this text box one here txt1 first that it is someone to take this basic
style here apply over here that I can go to the other text box here
and say okay again F4 and apply the style here as well right so you can see like I have created
a style once and I'm just going and applying them to all my controls here right so that it is so this is I'm applying to
TXT2 here so now if I go and on this
application you can see now the height of the text
box the font of the text box you know they're looking very similar and if I do look into a five-year I should also see a hand off a cursor so
very quickly so that it is you can see now when I move my
mouse it is showing hand also you can see the font size is set in a standard way right so again this is
one more a big advantage of WPF over widows you know if you want to go and create a
common look and feel for your controls you can just go and
create a style and then start applying them to every control while in Winform you know you have to go
to every control and said the values right. so A for a Anywhere execution, B for Bindings C for Common look and feel the
4th in which is again very interesting in WPF is
Declarative programming D okay D for Declarative programming what do we mean by that in Declarative
programming you describe in a abstract Manner how your code looks like rather than writing the actually
code for example if you've notice till now I did demonstrations and bindings I
did demonstrations on styles but I have not writen a single line of
code for example you know when I did demonstration on the binding I know where one text box value was
set the other text box and this text box value are set to this text box
right I did not right the single line of code so
how did it happen it was happening because of direct to
programming in other words when I was setting those properties
of binding to the Text box at the back-end visual studio was doing
direct to programming for example when I said the binding of the Text
boxes you can see over hear I'm highlighting the code here now this
is a directive XML so in other words you
know without writing a single line of code I'm expressing what I want to do so it says here that the text 1 Textbox text should be set to Text 2's text so you can see that you know without writing a single
line of code I'm able to express what I want to do and he just does it so this is again a very big achievement
of WPF direct to programming so in other words you
know we can expect that our development can become faster because we have to right now less amount of code so A for anywhere execution, B for bindings, C for common look and
feel is that it's style D for direct to programming so now let's
take the next one E. E for Expression Blend an
animation animation is again a big plus point for
WPF if you see the architecture of WPF
or if you see the way WPF works internally it uses
DirectX. now DirectX is a nice frame work for doing
animation so because DirctX can do animation
even WPF can do animation and by using Expression Blend . Expression
Blend is nothing but its a tool so by using Expression Blend we can go and do your animation and then we can reused that animation in Visual studio so again
this is a big point here so for example I can just go
and write animation here so we can see I have page set the animation here will talk about animation in depth
later on but for now you can see that what
have done is I have a label here and what I'm trying
to do is I am trying to modify the label font size so you can see here I am saying at double animation and I want to modify the label font size
from 0 to 2000 you know with the value of 10 in
other words with the steps of 10 right so if I run this program here you
will see that the label font size increases from 02 to
2000 with the step of 10 so you can see this label font size
becoming bigger and bigger you know by 10 and you know with the
duration of 3 seconds right. so that is again a
very big pius point of WPF you know you can go
and create animation by using the Expression Blend tool and then you can go and write animation
in a very simple directive way right so A for Anywhere execution, B for Binding, C for
common look and feel D for Directive programming, E for
Expression Blend an animation why because WPF uses DirectX internally F for faster execution so you must be
wondering why WPF is faster than Winforms WPF internally uses DirectX while Winform internaly uses GDI or GDI+
I will say now because WPF uses DirectX internally
DirectX has the capability to do hardware rendring while GDI does only software
rendering so the next question is you know what
exactly is the difference between Hardware rendering and Software rendering. now there are 2 ways by which a computer renders display on the monitor first by using a CPU and second by using the GPU so in case of CPU
rendering the CPU drives the whole logic of how to
render a display on the monitor I remembered that in a CPA also does
lot of other things for example he runs the application he does memory management he runs an operating system and what
not right, and on that top of it you know have a loaded him with extra work also displaying the things on Monitor
right so that's what this extra dite GPUs but
me GPU stand for Graphical Processing Unit. GPU is
nothing but you can think about its a specialize kind of process that which is
specifically meant for rendering and display now the GPU
is Pacificly meant you know to render your display is foster
that is a whole point of GPU so the GPU actually takes the whole load
from the CPU about displays and tells to CPU that you take care of memory management and
application running I will take care of the display part does making your CPU free for doing other things right, now the CPU is way of rendering is called
as Software renederig the GPU way of rendering is called as Hardware renederig now when you used WPF right and when it
comes about rendering these controls on the screen it will try to use the GPU In case
it does not find the GPU then he will switch to CPU rendering okay but when it comes to Winform you know the WinForms used GDI internally And GDI purely use the CPU rendering
must be there are some cases you know where it use GPU but most of the time it uses CPU rendering
which means that the time your GPU start seeking the
load of rendering and your CPU becomes free your application as to run faster right because now the load is shared
between two hardware right one is specialized you know for display and the other one is specialize to run your application so WPF you know use this hardware renedering internally and thus making your application fast and WPF goes one step further you know this rendering is further optimize into
Tier 0, Tier 1 and Tier 2 mode Tier 0 mode means pure software
rendering you know because must be you don't
have a GPU or you don't have that Card you know for display so we will purely switch to CPU rendering
that means it will use direct X 7 internally if he sees you know that you know some other
functionalities can be done better by GPU and some other functionality can
be better done by CPU then he will switch to partial
software rendering or you can say partial Hardware rendering, ok and the last one is Tier 2 you know where it switches purely to
hardware rendering and then where uses DirectX 9 so if it is pure software rendering if you see that there is no GPU he will switch to directX7 that mean pure software rendering if you see that you know some of the functionality can be better drawn by using GPU and some other functionality it can be better drawn by CPU he will switchin between that is
between DirectX 7 to 9 and second one last one you know when he sees that you know that there is a very nice GPU card you know they be purely switch to hardware rendering that meanse he will use DirectX 9 so again you know WPF is very smart enough you know to switch between software rendering and hardware rendering depending on your a Hardware environment, So retrating in a so that you don't forget again and again A for Any where execution, B for Binding,
C for Common look and feel D for Direct to programming, E for
Expression Blend and animation F for Faster execution because it uses
Hardware -rending internally and now G for Graphic independency means what so what do you mean by Graphic Independency here Graphic Independency means resolution in dependency so let me define first resolutions
resolution is nothing but the total number of Pixels you know that fit
into your screen into your monitor right now what
exactly is a Pixels, A Pixel is nothing but it's a simple dot on the screen so now if someone sees that my
resolution is 800 by 600 pixels on a 15 inch monitor that means you know per inch you know
there are 53 Pixles but now if you take the same 800 by 600
and if you say 19 inch you know that means in 1 inch have 42 pixels so in 1 inch if you have 53 Pixels
you know that resolution is much better as compared to are in the 19 inch a video
forty-two percent cite so resolution if you asked to and use
that you know he things in terms of Pixeles and most of the times you will see that you
know the indivusual goes to this computer and actually he can adjust his resolution so will see that
if somebody wants to make a resolution better he will right click on the desktop go to the screen resolution and normally
will see that you know people fiddle around with this pixels overhere right now if your application is using pixels you know for doing linemen doing
measurement right that means you know if the individual
goes and changes this pixels you know application goes for a toss right the
alignment goes for a toss the look and feel goes for a toss So if you look at windows form right,
Windows form uses excels as a measurement unit so if the
pixel changes you know than Windows form has to
adjust himself again that means you are right logic for it but in WPF you know he does not use Pixel as a measurement unit but it uses something called as DIP D I P that is Device Independent Pixels so now 1DIP = 1/96 th up of the inch so in other words here you know WPF does
not use pixel as a measurement or alignment unit
but it uses DIP, DIP Deals Directly with the
Physical measurement that is inch so 1DIP = 196th of the inch that means he's trying to relate himself
directly with the with the physical length of the monitor
okay so that means if you know I change my resolution right it does not matter for
WPF because he's gone to use this one by 96 factor right so we will talk about you
know this graphical independence in more depth later on but
for now you know what you need to understand is that if I
change my resolution in a windows-based application then I will see the same screen different in different resolution but if I change my resolution for WPF
application you will see that WPF application almost look look similar right so just iterating you know what
of the benefits of WPF over windows let's start first A - Anywhere Execution
execution you write the xaml once you can run it as a Silverlight
application, you can run it as a Winform application,
you can run it as you know WPF Web application, B for Binding you know where basically you can just take two objects and if you want to pass data from one object to other
object to define a binding and the data just starts getting
replicated between those two objects C for Common Look and Feel in Windows
form I have to go to every text box every button and if I want to make it a standard
color I have to go to Every text box every button fix your colors but here I can just go and
defined the style and then you can start applying D you know for Directive programming so in a rather than writing a lot of C# code you can just go and use the xaml directive and it will actually you know run the code accordingly
so less coading as compare to Winform programming E for Expression Blend an animation
so because WPF uses a DirectX internally you know
you can just go ahead and right a nice directive animation you know a directive xaml animation
and you will to the animation for you F for Faster Execution why because now he
can use hardware accleration because it has DirectX internally and hardware acceleration means you're going to use your GPU so your CPU will be less loaded that
means you know your CPU can do better work you know rather than doing the
display work and finally G for Graphic independence
you know where WPF uses something called as device
independent Pixles which is 196 of the inch you know rather than using the pixels you know which can be changed by the end user. so ABCDE F and G are the reasons you know why you would
like to choose WPF over Winforms so I hope that you enjoyed this video so
this was just a start of video to make you understanding you know why WPF and in
the coming videos you know where you can to go and run through like you know 15-20 labs for WPF in a very will get a better understanding of WPF so hope that you enjoyed this video in
this video we are trying to understand You know why WPF is better than Winforms thank you so much