How to separate behavior from uielement behind the Silverlight code?

In Silverlight 3.0, I added custom behaviors for some UIElements in Code Behind.

I want to remove the behaviors at runtime later .

What is the C# syntax to separate the added behavior from the UIElement?

I guess you’re talking about a behavior that originates from behavior . In Blend SDK Class…

Can you still refer to the behavior when attached?

MyCustomBehavior myBehavior = new MyCustomBehavior();
myBehavior.Attach(myElement);
...
myBehavior.Detach();

Edit

If you no longer refer to the behavior instance when you want to separate the behavior, you can do the following to separate all the behaviors on the DependencyObject:

foreach (var behavior in Interaction.GetBehaviors(myElement))
{
behavior.Detach();
}

In Silverlight 3.0, I added custom behaviors for some UIElements in Code Behind.

I want to remove the behaviors at runtime later.

From UIElement What is the C# syntax to separate the added behavior?

I guess you are talking about a behavior derived from behavior . The classes in the Blend SDK…

Can you still refer to the behavior when attaching?

MyCustomBehavior myBehavior = new MyCustomBehavior();
myBehavior.Attach(myElement);
...
myBehavior.Detach();

Edit

If you no longer refer to the behavior instance when you want to separate the behavior, you can do the following to separate all the behaviors on the DependencyObject:

foreach (var behavior in Interaction.GetBehaviors(myElement))
{
behavior.Detach();
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4083 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.