views:

347

answers:

1

Hi, I am building a custom splitbutton that consists of two overlapping buttons, and popup - like this (image shows some generic splitbutton):

SplitButton

My SplitButton opens popup whan a right side with arrow is clicked, and executes SplitButton.Command when a main button is clicked.

In my case however sometimes the default action cannot execute, and in those cases, when a main button is clicked, I'd like to open the popup instead.

I have accomplished it, but the problem is this:

  • the SplitButton is subclassed from ToggleButton
  • in a ControlTemplate, I have a ToggleButton (the bottom one), and Button (shorter, overlaid on the top)
  • Button.Command="{TemplateBinding Command}" (so I can do <SplitButton Command="{Binding MyDefaultAction}">...)
  • problem: when a command cannot execute, the whole SplitButton gets disabled.

I'd like to keep having the same command, but to override the button's behavior so that it doesn't become disabled when Command.CanExecute() returns false. How can I do this?

Thank you!

A: 

Hi,

Command is a dependency property and I'm pretty sure it is inherited by any control beneath it in the visual tree. So for the button you don't want disabled, set the command property to a different command or setting it to null may also work.

Alternatively,

Create your own dependency property...like this one

Dependency Propert

Leigh Shayler
Well, the problem is that I still want the button to execute a given command, I only don't want it to become disabled when the command cannot execute. However, I looked at implementation in ButtonBase (with Reflector), and disabling the button is done by private methods - so I cannot override them.I'll probably have to rip out the needed functionality from Reflector's disassemble view, and create an ICommand DP that will be under my control. Thanks for the idea.
Tomáš Kafka