I want to remove the behaviors at runtime later .
What is the C# syntax to separate the added behavior from the UIElement?
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
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();
}