Hey atAll!
Often found answers here, but now it`s my first time ;)
We use the MVVM pattern in conjunction with DelegateCommands. So normally I bind a command to the button like this:
<Button Command="{Binding SetXYZActivatedCommand}" />
I need to execute different commands when the button is pressed and when the button is released again. My idea was the following:
        <Button Grid.Row="3" x:Name="TestButtonObj" Content="asdlknm">
        <Button.Template>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border x:Name="border" CornerRadius="80" Background="LightBlue">
                    <ContentPresenter Name="content" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="border" Property="Background" Value="Aqua" />
                        <Setter TargetName="content" Property="Content" Value="Pressed" />
                    </Trigger>
                    <Trigger Property="ClickMode" Value="Press">
                        <Setter TargetName="TestButtonObj" Property="Command" Value="{Binding SetPttDeactivatedCommand}" />
                    </Trigger>
                    <Trigger Property="ClickMode" Value="Release">
                        <Setter Property="Button.Command" Value="{Binding SetPttActivatedCommand}" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Button.Template>
    </Button>
The problem is that TestButtonObj is unknown. Ok I have accepted, that I cannot access the parent object. Without TargetName="TestButtonObj" it compiles, but the command is not executed. Mhhhh...
Ok I tried the following, but it cannot work... CommandBinding is not a dependency property (hopefully you get me out of this labyrinth)
<Button Grid.Row="2" Content="CommandBindings">
<Button.CommandBindings>
    <CommandBinding Command="{Binding SetPttActivatedCommand}" />
</Button.CommandBindings>
At this point I stuck. I don`t know if the way was completly wrong. I read the whole day docs about commands and binding, but I don't get the clue. I hope, someone can show me the way.
I posted also here today morning: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/cc68b10c-4e1c-4344-9f00-710185d4b1b0 If I get an answer, I will post it here too.
Thank you so much (in advance), Totti