Adam Calderon

Thoughts About .NET That Sometimes Hurt My Brain

Attached Events in Silverlight == false

As I am digging more and more into Silverlight I find more and more features I have come to love in WPF that are just not there. One feature is Attached Events. In WPF I can do something like this in XAML.

<StackPanel Height="25"  Orientation="Horizontal"  ButtonBase.Click="StackPanelCommon_Click">
    <Button Name="Yes" Margin="5,0,5,0" Content="Yes"/>
    <Button Name="No" Margin="5,0,5,0" Content="No"/>
    <Button Name="Cancel" Margin="5,0,5,0" Content="Cancel"/>
</StackPanel>

In this scenario the StackPanelCommon_Click handler will handle the click event for the Yes, No and Cancel buttons. Inside this handler I can add code to determine the particular button selected and implement logic accordingly (see below).

private void StackPanelCommon_Click(object sender, RoutedEventArgs e)
{
  Button button = e.Source as Button;
  if(button != null)
  {
    switch (button.Name)
    {
      case "Yes":
        //some logic goes here
        break;
      case "No":
        //some logic goes here
        break;
      case "Cancel":
        //some logic goes here
        break;
    }
  }
}

But when I try this in Silverlight I get the following error.

SilverlightAttachedEventError

So what the heck is going on here? It turns out that UIElement does not support the AddHandler method which allows you to add handlers to the UIElement.

I hope in future versions Microsoft can add this into Silverlight to help promote more concise coding approaches since the alternative is similar to the old days gone by.

 

 

Comments

Music_Mp3_CogyMadyidolo said:

Hello to all :) I can’t understand how to add your site in my rss reader. Help me, please

# February 4, 2009 7:55 PM

Assemaden said:

Hey Folks

How do I <a href=http://www.esnips.com><b>Download Free Music</b></a> from <a href=http://www.esnips.com><b>eSnips.com</b></a>?  All my friends have the hottest music & ringtones from there yet I still haven't figured it out ! :)

Any other <b>Esnips Members</b> here who can walk me through this?  

Btw - For those of you who don't know, eSnips offers <a href=http://esnips.com><b>Wallpapers</b></a> etc.

# June 23, 2009 4:59 AM

Assemaden said:

Greetings

How do I <a href=http://www.esnips.com><b>Download Free Music</b></a> from <a href=http://www.esnips.com><b>eSnips.com</b></a>?  All my friends have the hottest music & ringtones from there yet I still haven't figured it out ! :)

Any other <b>Esnips Members</b> here who can walk me through this?  

Btw - For those of you who don't know, eSnips offers <a href=http://esnips.com><b>Free RingTones</b></a> etc.

# June 23, 2009 2:29 PM

Assemaden said:

Hello

How do I <a href=http://www.esnips.com><b>Download Free Music</b></a> from <a href=http://www.esnips.com><b>eSnips.com</b></a>?  All my friends have the hottest music & ringtones from there yet I still haven't figured it out ! :)

Any other <b>Esnips Members</b> here who can walk me through this?  

Btw - For those of you who don't know, eSnips offers <a href=http://esnips.com><b>Free Mobile Applications</b></a> etc.

# June 23, 2009 5:57 PM

vadya said:

WfPmtM this http://www.google.com is google

# June 27, 2009 4:38 AM

Toimediemyday said:

wmlkki 9967 cnekrjvef <a href=members.ebay.co.uk/.../eBayISAPI.dll>kamagra</a>">members.ebay.co.uk/.../eBayISAPI.dll 3222  jhf mvf buy kamagra online in UK members.ebay.co.uk/.../eBayISAPI.dll buy kamagra online :) ckjdsjak 92871 <a href=members.ebay.co.uk/.../eBayISAPI.dll>buy kamagra online</a> 12603 hgdcvd

# June 29, 2009 3:03 PM

DitSteemo said:

ehgc jsh 94279 enkrjvfd <a href=members.ebay.co.uk/.../eBayISAPI.dll>buy">members.ebay.co.uk/.../eBayISAPI.dll levitra online</a> 55364 djh c buy levitra online in UK members.ebay.co.uk/.../eBayISAPI.dll levitra buy :) wttwd 50526 <a href=members.ebay.co.uk/.../eBayISAPI.dll>levitra</a> 44416 vbrtbrt

# June 30, 2009 2:22 AM

aniliatuh said:

Hey

I need some help... I registered for an account at <a href=http://www.esnips.com><b>eSnips.com</b></a> and now Im trying to figure out how to upload files ..

Any other Esnips Members can walk me through this?  

Btw - For those of you who don't know, eSnips offers <a href=http://esnips.com><b>Free Software Downloads</b></a> etc.

# June 30, 2009 2:56 AM

aniliatuh said:

Hi All,

I need some help... I registered for an account at <a href=http://www.esnips.com><b>eSnips.com</b></a> and now Im trying to figure out how to upload files ..

Any other Esnips Members can walk me through this?  

Btw - For those of you who don't know, eSnips offers <a href=http://esnips.com><b>Wallpapers</b></a> etc.

# June 30, 2009 6:37 PM

aniliatuh said:

Hey

I need some help... I registered for an account at <a href=http://www.esnips.com><b>eSnips.com</b></a> and now Im trying to figure out how to upload files ..

Any other Esnips Members can walk me through this?  

Btw - For those of you who don't know, eSnips offers <a href=http://esnips.com><b>Wallpapers</b></a> etc.

# July 1, 2009 1:19 AM

grisacrotbaro said:

jdkj 50325  vjkfd fv <a href=members.ebay.co.uk/.../eBayISAPI.dll>buy">members.ebay.co.uk/.../eBayISAPI.dll levitra online</a> 67647 csdc buy levitra online in UK members.ebay.co.uk/.../eBayISAPI.dll levitra buy :) wqiunx 83499 <a href=members.ebay.co.uk/.../eBayISAPI.dll>levitra</a> 6108 vbrtbrt

# July 2, 2009 12:38 AM

hycleliny said:

dvjkfd fv 2755  vjkfd fv <a href=members.ebay.co.uk/.../eBayISAPI.dll>buy">members.ebay.co.uk/.../eBayISAPI.dll kamagra</a> 26057  cjhf vmfdh v buy kamagra online in UK members.ebay.co.uk/.../eBayISAPI.dll buy kamagra online :) wttwd 95141 <a href=members.ebay.co.uk/.../eBayISAPI.dll>kamagra</a> 35838 enkrjvfd

# July 2, 2009 7:06 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)