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
{
...
public CustomButton()
{
...
}
}
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.
source
share