Relative Source in WPF

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys so in this video we will see what is relative source in WPF a relative source is a markup extension a mark of extension is used to obtain a value that is not a specific sample type so what does that mean let's go to visual studio I have this text box you can see it from the visual now let's try it the text property and then the curly braces binding so you see binding it's a markup extension static resource you see this static resource it's a markup extension dynamic resource it's a marker extension let's take any one binding and then let's say light any art that she property as of now for scape and let's assume this it is coming from our Bitteroot class so what is happening here now the text property of this textbox is getting data from this first name and to achieve this this markup extension is helping me some amount of extension helps to get the data from this property okay so the examples of markup extensions are binding static resource dynamic resource X called static and so is the relative source okay now the most important question in what scenario I will be using this related source now to understand this we need to understand what all various modes are they're interrelated source the first mode is the self mode there are four and the self code in self mode I would use this mode when I want to bind the property of an object to the property of the same object so what does that mean let's come again to the visual studio now here I have this text box and I have this width and height property now I want to make a scenario where my height should always be equal to its width if I'll see you then you will say that okay we can achieve this light I can give it a name at txt a text box and then I can use I can just find this tied to the width how I can just use the binding then element name then text and then I can get the part and then we will see with you see I achieved it and the reason it is Fame is clear if I change the bit 200 then I never see but in this case we are always object to give the name of the textbox see if I want to change this to text 1 then I have to change it in the binding media also it is always static ok I don't want to have in this way I want to have this always dynamic so how to achieve this then okay let's remove this all and let's see if the related so now in this case so finding then related to the source and relating source cells and then you can get the path again and save it again we achieved it this is it to 200 you see here it is the team now this is very powerful not only this we can also make use of converter say yeah say I will give you a scenario that my height should always be half of the width then how will you do so now in this radius phone you can use the converter the converter can get this width and then return the half of Thurid okay now let's come back to the slide now the second second mode is fine ancestor in this mode we will be binding the property of the given object to order the property of its related parent so what does that mean let's come to the vision studio and then let's commend this ok and then let's uncomment this app already have a piece of code to save time ok so in this example I have three borders when under another and then finally I have a textbox what I want to do I want to bind the text of this text block to any one of the borders name as you can see all these three borders have given the name how to do so we can do so using latex source finance system now so text and then finding translated source again red sauce and then mind ancestor and then ancestor type okay which kind of ancestor I want to find I want to find the body and then you can give the and sister level and it said - I'm not finished yet I need to give the path also property I want to bind the main property so I want to bind the name to the text of any one of the and sosa parent so as of now I've given the level two that's why I'm I can see grant parent pada which is of second bottom it will kind come from your one two and three you can play it around quickly cf3 this is a great client iron butter and you have one you can see a band model okay no no jump on to the third mode which is done plated parent so click so I want to use this in a scenario where I want to bind a property on the template a parent okay so let's see this in action in Visual Studio for this again I have a piece of poor let me commend the previous film and then now let's look into the template a parent mode its uncomment it so here I have a button and then I have used a control template of the button with control template I can change how I control looks like the weeds would look of the control so I have changed control from normal to or ellipse I have this root property now if I'll give the background to say black then you see it is not working why because I have already over it emit with the local property film but I want to achieve this I want to bind this background it is field property I want to control the background from the button itself I can achieve this using will be a tip source and template parent okay so let's achieve it binding then relative source and related source and then it did bat it and then again you can get the path but but I'm gonna tell you the background you see black you can create a long butt and then we say that I've bounded this background TOEFL okay now let's go to the last won't she just stay down now this is very unbiased one and it is less used mood and this is used in Sanada where I want to find the PV state item sama item collection let's see this in action again for this I have done some prerequisite okay so I have this item class which has a data property I have created a list ever added three lists here three items in the list 100 130 and 150 and then I've set the data context to this collection okay now let me comment the old chin sample and then come to the next one and this new example let me uncommon this I have this list box and I have bound the item source with collection itself whatever is the data context I want to have an item source then I have changed how item should be displayed by default items in an item list box is displayed vertically I change it to hurt him and then I just wrote our data template how my data will be presented on to the screen so I've used here here it is very important to notice that I've used text box and 11 now the text box is found with the data normal data but the level is bound with the previous data using relative source I've used somewhat previous item now let's see this in action and then you would understand it by default okay okay so yeah it is coming I guess a bit slow at my end seems Kings so now I have this three item you can see the textbox is born with the actual data 100 130 150 and the label is the downward our control 101 31 100 from this previous data then you 138 from this data in the first one the West will give you 0 that's why it is empty kept empty so it is used to find with our previous data from our collection ok let's come back to the slide so with this we have finished with all the modes and we are there
Info
Channel: High-Tech
Views: 1,116
Rating: undefined out of 5
Keywords: Relative source, relativesource, modes in wpf, binding, markup, markup extension, wpf, xaml, c#, dot net
Id: c7vPP_FikHw
Channel Id: undefined
Length: 9min 6sec (546 seconds)
Published: Thu Apr 09 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.