views:

156

answers:

1

I have a scenario where a control has an event wired up in XAML, say a Button.Click.

Somewhere else in my code, a security check is applied which mean I need to disable said event, but I do not have access to the normal -= syntax to remove it.

How else can I remove or disable this event?

Thanks, Dave

+1  A: 

Data bind the IsEnabled property of the button to your model class / DataContext, which can be updated by your code anywhere.

If you require more control, consider having a dictionary or list of "approved" buttons that have a token for the click event, or for the underlying business object. In your Click event, check if the token/object/special thing is present before continuing.

Jeff Wilcox
Thanks Jeff. I actually have the IsEnabled stuff done, however, I need more fidelity that just IsEnabled. In a DataGrid, for example, I need to apply security for specific events ...
Dave
Updated to reflect that.
Jeff Wilcox
Hi Jeff, what I am actually doing is making use of Attached Properties that call out security claims/requirements needed for each control. That way I can decorate my XAML with the requirements rather than resorting to Code Behind.I've actually ended up hooking into my commands in the ViewModel that in turn regulate access to those commands."Next Time" I may consider a factory pattern to add the event handlers, which in turn manages access, so I can just not add the handler if it's not appropriate.Thanks for your advice/help.Dave
Dave