TemplateBinding and binding

Source: Internet
Author: User

TemplateBinding is a lightweight version of the binding that loses many of the features of a mature version of the binding, such as inheriting content references (inheritence context referencing), RelativeSource references, as well as dynamic type conversions through the ivalueconverter/typeconverter mechanism. It supports only the frameworkelements generated by the template , and its data source reference points to the parent element in the template. The main purpose of TemplateBinding is to have a built-in template that binds the properties of templated elements, which in this case is much more efficient than the mature binding.

The following two binding effects are the same

<textblock text= "{TemplateBinding MyText}"/>

<textblock text= "{Binding path=mytext, Mode=oneway, Relativesource={relativesource templatedparent}"/>

In addition to the above, the binding supports the following bindings

A relative data source extension is required to bind the target object to an object that has a correlation with the target object itself. For example

<window x:class="Yingbao.Chapter2.RelativeEx.AppWin"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"Title="Relative Binding"height=" -"Width=" -"> <stackpanel orientation="Horizontal"HorizontalAlignment="Center"> <textblock fontsize=" -"text="{BindingRelativesource={relativesource self}, path=fontsize}"/><textblock margin="10,1,1,5"Fontsize=" -"text="{BindingRelativesource={relativesource ancestortype={x:type StackPanel}}, Path=orientation}"/></StackPanel> </Window>

In this example, the author uses two relative data source extensions, the first TextBlock text is bound to its own font size, and the second TextBlock's text is bound to the orientation property of its parent node StackPanel.

TemplateBinding and binding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.