Cancel event on (Toggle)Button

Hi wpf gurus

My customer wants me to show the user a message when he has no access to specific functionality.
I tried to convince him to just disable the control when access is denied, but that was no option.

So, for instance, I have a toggleButton (preferably, it should work for any UIElement).
I check for the rights of the user, in the Click eventHandler.


Code Snippet

private void ToggleButton_Click(object sender, RoutedEventArgs ea)
{
if (User has rights)
// do normal stuff
else
{
ea.Handled = true;

// show "No rights" message
}
}


When access is denied, I somehow want to cancel the rest of the processing. I want to avoid that the IsChecked property still changes after the click.

I've tried something with setting the Handled property on true, but that didn't do the job. Is there any way to stop the standard event handling?

It somehow feels like bad practice, but I don't have a (better) solution.

Regards, Jowen

[1228 byte] By [captBiele] at [2008-1-9]
# 1

you need to use the preview events for this....PreviewMouseLeftButtonDown

have a look here
http://msdn2.microsoft.com/en-us/library/ms752279.aspx

regards

MarlonGrech at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2
Tnx for your reply Marlon.

I've heard about these preview events, but I was hoping for another solution I could use inside the normal Click eventHandler. Then I'd have all the logic in a central place. Now I have to add these preview events to every control, but ok......
It seems as if I have no other choice....

regards

captBiele at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified