Joindre ICommand dans WPF UserControl

J'ai mis en place un simple bouton avec une image:

    <Button Command="{Binding ButtonCommand, ElementName=ImageButtonControl}">
        <StackPanel Orientation="Horizontal">
            <Image Source="{Binding ButtonImage, ElementName=ImageButtonControl}"/>
            <TextBlock Text="{Binding ButtonText, ElementName=ImageButtonControl}" Margin="2,0,0,0"/>
        </StackPanel>
    </Button>

Comme vous pouvez le voir, j'expose un ButtonCommand propriété afin d'être en mesure de joindre un ICommand à ce UserControl:

public partial class ImageButton : UserControl
{
    ///<summary>
    ///The dependency property that gets or sets the source of the image to render.
    ///</summary>
    public static DependencyProperty ImageSourceProperty = 
        DependencyProperty.Register("ButtonImage", typeof(ImageSource), typeof(ImageButton));

    public static DependencyProperty TextProperty =
        DependencyProperty.Register("ButtonText", typeof(string), typeof(ImageButton));

    public static DependencyProperty ButtonCommandProperty =
        DependencyProperty.Register("ButtonCommand", typeof(ICommand), typeof(ImageButton));

    public ImageButton()
    {
        this.DataContext = this;
        InitializeComponent();
    }

    ///<summary>
    ///Gets or sets the button command.
    ///</summary>
    public ICommand ButtonCommand
    {
        get { return (ICommand)GetValue(ImageButton.ButtonCommandProperty); }
        set { SetValue(ImageButton.ButtonCommandProperty, value); }
    }

    ///<summary>
    ///Gets or sets the button image.
    ///</summary>
    public ImageSource ButtonImage
    {
        get { return (ImageSource)GetValue(ImageButton.ImageSourceProperty); }
        set { SetValue(ImageButton.ImageSourceProperty, value); }
    }

    ///<summary>
    ///Gets or sets the button text.
    ///</summary>
    public string ButtonText
    {
        get { return (string)GetValue(ImageButton.TextProperty); }
        set { SetValue(ImageButton.TextProperty, value); }
    }
}

Puis quand je déclare mon bouton ça donne ça:

<uc:ImageButton Grid.Row="1" Grid.Column="0" ButtonCommand="{Binding AttachContextCommand}" ButtonImage="{StaticResource AssociateImage}" ButtonText="Associer"/>

Et badaboom, rien n'arrive jamais quand je clique sur mon ImageButton.
Lorsque je remplace le ImageButton avec un simple bouton, la ICommand est appelé.

J'ai même essayé de simplement s'étend la classe de Bouton et le lier à une ICommand, mais encore une fois, cela n'a pas fonctionné...

Aide appréciée !

Thx.

Est-ce que le bouton est désactivé, ou que vous cliquez dessus et rien ne se passe?
Je clique dessus et la commande n'est jamais appelé...

OriginalL'auteur Roubachof | 2009-03-13