(X) Hide this
    • Login
    • Join
      • Generate New Image
        By clicking 'Register' you accept the terms of use .

Rob Relyea from the Avalon team has a cool intro t...

(0 votes)
0 comments   /   aggregated from house of mirrors on Feb 10, 2006   /   original article
Categories:   General
Rob Relyea from the Avalon team has a cool intro to 'attached properties', but sadly he doesn't go into the real fun you can have with attached properties. Basically they let you store data on arbitrary DependencyObjects, but the key is that they provide a callback whenever that data changes. Suddenly, this sealed to the hilt behemoth of an API can be extended.

My current side project is to create my own set of extensible events and actions, but since EventTrigger and TriggerAction are sealed and give us non-Avalon folks no love, enter attached properties:


<Rectangle Name='RedRect' Width='100' Height='66.6' Fill='Red'>
<evt:Triggers.Triggers>
<evt:PropertyTrigger Trigger='{Binding ElementName=RedRect, Path=IsMouseOver}' Value='True'>
<evt:SetterAction Property='IsActive' Value='True' Target='{Binding}'/>
<evt:MethodAction Method='Play' Target='{Binding ElementName=VideoFrame}'/>
evt:PropertyTrigger>
evt:Triggers.Triggers>
Rectangle>


So Triggers.Triggers is an attached property of a collection of Trigger objects. All that needs to be done is propagate the source object through the resulting tree to make it available for triggers to hook themselve up and implement a few simple triggers and actions.

Voila- suddenly you can do something in Xaml with those events other than Play/Pause/Stop/Seek storyboards!

In the next few days I'll go into some details about the trigger/action design, but the basic princible is to allow Xaml to play a larger role in the View part of a Model-View UI separation.

The source.

Subscribe

Comments

No comments

Add Comment

Login to comment:
  *      *