public AccessHandler(DependencyObject obj) { bool authorize = GetCheck(obj); BehaviorCollection behaviors = Interaction.GetBehaviors(obj); AccessBehavior authorizationBehavior = behaviors.SingleOrDefault(x => x is AccessBehavior) as AccessBehavior; if (authorizationBehavior != null && !authorize) { behaviors.Remove(authorizationBehavior); } else if (authorizationBehavior == null && authorize) { authorizationBehavior = new AccessBehavior(); var binding = BindingOperations.GetBinding(obj, TextBox.TextProperty); if (binding != null) { BindingOperations.SetBinding(authorizationBehavior, AccessBehavior.VMBoundedProperty, binding); } binding = BindingOperations.GetBinding(obj, ItemsControl.ItemsSourceProperty); if (binding != null) { BindingOperations.SetBinding(authorizationBehavior, AccessBehavior.VMBoundedProperty, binding); } binding = BindingOperations.GetBinding(obj, ButtonBase.CommandProperty); if (binding != null) { BindingOperations.SetBinding(authorizationBehavior, AccessBehavior.VMBoundedProperty, binding); } behaviors.Add(authorizationBehavior); } }