Limit visibility of Silverlight / WPF behavior

In Silverlight (and probably WPF) when I define System.Windows.Interactivity.Behavior<T> , for example. a ItemsControl e.g.

 public class SomeAwesomaticBehavior : Behavior<ItemsControl> { } 

it will appear in the Visual Studio XAML editor (and probably in the Designer too) even for regular, non-control elements and will throw unpleasant exceptions at runtime. This contradicts the attached properties, which will be displayed only for certain types.

Is there a way to limit visibility? Perhaps some kind of magic attribute (although that would be a redundant declaration)?

If there is no way today, I hope it will be so in the future? Because this, of course, confuses colleagues and designers when there are many Behaviors who have nothing to do with the current object.

Update: I registered user service items.

Silverlight: http://dotnet.uservoice.com/forums/4325-silverlight-feature-suggestions/suggestions/1224253-restrict-behavior-visibility?ref=title

WPF: http://dotnet.uservoice.com/forums/40583-wpf-feature-suggestions/suggestions/1224259-restrict-behavior-visibility?ref=title

+6
wpf silverlight xaml behavior
source share
1 answer

@HeRz you're right, there is no way to filter behavior by their target type. Blend (and probably vs designer) uses reflection to find all the types you create that inherit from the base Behavior type and display them in the asset list.

Blend will prevent drag and drop behavior or trigger on an element that it is not intended. This should help prevent their misuse.

Usually I try to write behavior as reusable pieces of code that are not case-specific. These are just tools with specific goals.

+3
source share

All Articles