WPF command line custom binding not working

I created a custom button that inherits the Button class. I added some dependency property so that I can specify how the button will look.

The button looks great, and the dependency property also works as I wanted. But, however, the Command property does not work no matter how I try.

Here is my example:

public partial class CustomButton : Button
{
    ... //some dependency property
    public CustomButton()
    {
       ...//do some initialization
       //I tried checking the Command property over here but it seems like always to be NULL?!
    }
}

My xaml:

<Button x:Class="CustomButton"
        xmlns:.....>
   <Button.Resources>
   <Style TargetType="Button" x:Key="CustomButtonStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate  TargetType="{x:Type Button}">
                    <StackPanel Orientation="Horizontal" Background="Transparent" Height="22">
                    ......more things behind...
   </Style>
   </Button.Resources>
   <Button.Style>
   <Style TargetType="{x:Type Button}" BasedOn="{StaticResource CustomButtonStyle}">
   </Style>
   </Button.Style>
</Button>

I used it in my other windows management as follows:

 <Controls:CustomButton Command="{Binding NewCommand}" ToolTip="AddNew"/>

The command is always not executed, why? Did I miss something? Please help. Thank.

+3
source share
1 answer

. StackPanel Red, Transparent , .

0

All Articles