Posted 15 years ago
by sbarry
I have buttons in the ribbon that represent a toggle state (bold, italic, etc.). I have noticed that when the button's checked state is false, when clicking on the button there is a bit of flashing that happens. The same behavior happens in the ribbon samples as well. I believe it's because the Execute is fired after the mouse up, so the button doesn't stay pressed when you let the mouse up. Then, the execute is fired, followed by the can execute with causes the button to go into the checked state.
I would like the button to not show an unchecked state on the mouse up. Instead, could the command execute be fired before the button is unchecked in the mouse up event?
Microsoft Word and other Office products exhibit the behavior I'm looking for. Thanks!
Here is the code that handles the check state:[Modified at 12/04/2009 09:40 AM]
I would like the button to not show an unchecked state on the mouse up. Instead, could the command execute be fired before the button is unchecked in the mouse up event?
Microsoft Word and other Office products exhibit the behavior I'm looking for. Thanks!
Here is the code that handles the check state:
private void ExecuteBoldCommand(object sender, ExecutedRoutedEventArgs e)
{
// This happens after the mouse up event and the button always has
// an unchecked state when this code executes. Subsequent
// CanExecuteBoldCommand will set state to checked (if it should be)
// causing the flickering.
DoBoldExecute();
}
private void CanExecuteBoldCommand(object sender, CanExecuteRoutedEventArgs e)
{
CheckableCommandParameter checkableParameter = e.Parameter as CheckableCommandParameter;
if (checkableParameter != null)
{
if (_style != null)
{
checkableParameter.IsChecked = IsFontStyleOn(StyleProperties.Bold);
}
else
{
checkableParameter.IsChecked = false;
}
checkableParameter.Handled = true;
}
if (_style == null)
{
e.CanExecute = false;
}
else
{
e.CanExecute = ExecutionUtility.CanExecuteBoldCommand();
}
}