Windowsphone7 data binding usage

Source: Internet
Author: User

If we have customized a usercontrol, we may need to define some dependency attributes unique to this user control.

However, in some cases, we may want to reuse the dependency attribute of the parent control. For example, if a control is called mycontrol, the root container in the control is layoutroot. In XAML, I want to define it as follows: <UC: mycontrol background = "white"/>, and then the layoutroot background is assigned white.

One way is to redefine the dependency attribute of background to overwrite the original background attribute, register the propertychanged event, and assign the background value to layoutroot when the event is triggered.

Another method is simpler. layoutroot can bind elementname to the value of mycontrol's background to change the background.

ImplementedCodeAs follows:

<Usercontrol X: class = "testproject. controls. mycontrol "xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "xmlns: D =" http://schemas.microsoft.com/expression/blend/2008 "xmlns: MC =" http://schemas.openxmlformats.org/markup-compatibility/2006 "MC: ignorable = "D" background = "black" X: Name = "parentctl"> <grid X: Name = "layoutroot" background = "{binding background, elementname = parentctl} "/> </usercontrol>

We can use it like this:

 
<UC: mycontrol X: Name = "mycontrol" background = "white"/>

If we only define mycontrol but do not define the value of background, it uses the default value (the default value in this example is black, as shown in the Code ).

Related Article

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.