DependencyProperty attached properties for Wf,wpf,silverlight

Source: Internet
Author: User
Tags static class silverlight

Note that the DependencyProperty attached property, not the binding property

First look at a hypothesis,

How to extend a member of a class without modifying a class (inheritance is not possible)

This is not possible in the traditional OO design, but in NET3.0 (c#3.0,vb.net9.0) provides an extension method to implement this function

Look at the following example:

Scene: I often have to use the results of the number 2, how to easily achieve

class Program
{
static void Main(string[] args)
{
double v1 = 123;
double p1 = v1.zzzzz();
System.Console.WriteLine(p1);

//--
double p2=(1234567890.123).zzzzz();
System.Console.WriteLine(p2);
}
}

static class myExtension
{
public static double zzzzz(this double d)
{
return d/2 ;
}
}

This is the extension method that adds the [Zzzzz] method to [double] without modifying the structure.

That's the way LINQ works.

Method can do that, what about the attribute?

Upgrade the requirements, I think an object in an environment automatically more than a few attributes, in another environment and automatically more than a few other attributes

How to do it,

Let's take a look at Silverlight.

Scene: Provides a container, the container is divided into two rows, into the container in the meaning of the control can set the properties of additional properties [MyTag], [MyTag] Property set to [a] on the left, set to [b] on the right

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.