This article is a mirror article of machine translation, please click here to jump to the original article.

View: 30556|Reply: 0

[WPF] How to use RelativeSource binding in WPF

[Copy link]
Posted on 4/22/2020 1:37:09 PM | | |
When specifying a binding source in WPF, one way to do this is to use RelativeSource.

This means that the current element and the binding source are positional.

The first relationship: Self

To give the simplest example: in a StackPanel, there is a TextBlock.

If you want the width and height of the textbox to be the same, you can do this by setting the attribute Height="{Binding RelativeSource={RelativeSource Self},Path=Width}".


The second relation: TemplatedParent

For example, write a style for a Button and modify the Button to be an elliptical type. At the same time, the background color of the ellipse must be the same as that of the button.

In this example, TemplateParent refers to the Button


The third relationship: AncestorType

Specifies that the binding source is a parent element


In this example, the background color of the Label is the same as the background color of the Grid.





Previous:mysql adds a value or string to the original value
Next:QA and its testing work
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com