Binding Modes In WPF

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys so in this video we will talk about binding modes in WPF we have four modes one time one way one way to source and two way we will talk about these binding modes one by one in detail but before that let us understand what is binding in WPF so binding in WPF requires two things the first is source and the second is started now the source can be a normal CLR property or it can be a dependency property but the target must be a dependency property and then finally what we bind is the data which is there under these properties now it's your wondering what is dependency property then let me give you a brief about it because it's very very important concept in WPF let's come back to visual studio and I have a class and if I'll tell you how do you write on normal property then you will say that prop full and then tap tab this is how I write a property here my property is a wrapper which wraps this my member variable now a dependency property in WPF is written like prop DP then tab tab here my property property is the dependency property but this time the CL property my property is wrapping that dependency property my property property as you can see from here so get getting and setting on these this property will give you the dependency property now all those important concepts which is there in WPF like binding like style like data template like control template all these things are possible because of this dependency property in D you can see here at squiggly this is because any class where you are writing a dependency property must inherit from dependency object okay because get value and set value is coming out from the dependency object class only okay now let's remove this and let's remove this also because this was just for understanding now all those standard controls that you see in WPF the filter / textbox level button and let's take text box for example and you have this text property if you navigate to this property then you can see that this text property is a normal solid property but this property wraps the text property independency property and also this text box class if you'll keep on navigating to the parent then you can see that this is inheriting from dependency object class also as I said that it is mandatory that your class must inherit from dependency object okay now let's come back to the slide and let's talk about the moods now one by one now the first mode is the one time mode in one time mode we are updating the target from the source but only one time later on if you'll run the application then updating the source will not update the target okay that's how you can see here if the source is having a data then it will update the target the moment you run the application but later I hope you update the source again with data one the target will not be updated let's come back to visual studio to see this in action I have this text box as you can see this from the visual and I have this slide up I want to bind sliders value property let's give value initial value first that give me three I want to bind this value property to the text of the textbox okay so how to do so let me give the name to a slider and then let me bind the text property so use binding markup extension and admin name slider and then you need to give the path to which property you want to bind to I want to bind the value property and then mode okay you can see here there are four modes and there is one extra mode default we'll talk about this at the very last point of this video but let's concentrate on for the one time mode let's write one time so here my source is this value and target is the text property so initial value is three it will update the target when I run the application and later on my source changing the source should not update the target let's run this and see this in action okay so yeah you can see here three is there in the text works let's move the source it is not updating the target and target will update anything not have any influence on the source okay now let's come back to the slide again and let's see another mode for the next mode is when we mood again you can see from the arrow that here also the source is updating the target but every time you are updating the source the target will be updated as you can see that the source is having a data target will updated we change the source data one again the target will be updated to data one this is how it works but target has again no insurance on source changing target will no will not be having any impact on source let's come back to visual studio again to see this in action okay now this time let's change this to 1 V and then run again see this in action Here I am moving my slider and you can see here the target is getting updated seen the target will not be having any impact and so so so source is updating the target okay so let's come back to the slide and to see let's see the next mode the next mode is 1 b2 source as you can see this from the arrow again here target is updating the source every time you update the target the source will be updated but source updating the source will not have any impact on target let's come back to visual studio to see this in action let's try here right here one way to source and then let's remove this I don't need this now let's keep it at default value which is 0 for slider ok now let's try it something you have 5 you see it got updated so let's try it something online it is updated now you change the source target has do impact but you write here something like three it is updating so target is updating the source in 1b to source okay now let's come back to the slide again and let's talk about yeah you can also see from this animation that target is having beta then source is having also having the data not target is changed to read of in the source again update themselves to data one okay now let's come back to the last mode which is two-way mode now as the name suggests the source is having the data and then it will update the target if target is having the data and it will update the source so it is - we just come back to the slide to see this in action now let's change this to to V and then let's run it see this in action let's write something your 6 and then tab that's yeah pull the slider you can see here so source and target are updating themselves as I said I will be talking about this default mode in very last so this default mode okay so the text property of textbox is having a default mode which is two-way binding to it I'll run this now and you can see that will change here write something of 5 then it is updating the source change the slider it is updating the target okay and if you are wondering why it is default then again this is because of dependency property and we can just set the metadata when we are writing our dependency property as I said we can write a dependency property like this and then you have this property metadata you can also have a framework property metadata and if I'll navigate to this class then there are over loads of there are lots of constructors and I have also this flavor property metadata options in one of the constructor so navigate here I can see here bind to way by default so when the text property was written dependency property was written for the textbox then the default mode was set there only they don't like that only okay now let's come back to slide so with this we are finished with this and I think you have understood all those concepts one thing one thing that if you have liked this video then please do not forget to subscribe and like because I have made a very hard work to make you understand these concepts through the slides and presentation thank you for watching have a nice day bye bye
Info
Channel: High-Tech
Views: 677
Rating: undefined out of 5
Keywords: Binding Modes, Binding, one way, two way, one way to source, one time, wpf, c#, xaml, Binding Modes in wpf
Id: VLwu9CO8fks
Channel Id: undefined
Length: 9min 35sec (575 seconds)
Published: Sat Apr 18 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.