Click here to Skip to main content
15,910,118 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hi
I have a scenario where i need to write multiple commands for the same button. Can anybody help me please?

C#
<grid>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Command="{Binding ClickedCommand1}" Command="{Binding ClickedCommand2}" Margin="220,138,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
    </grid>


I have written the above code and its giving me error command already exists.

Thanks
s. Keshaavan
Posted
Updated 18-Jan-12 22:48pm
v2
Comments
Jephunneh Malazarte 19-Jan-12 4:16am    
why you need to add multiple command nk?
Sergey Alexandrovich Kryukov 19-Jan-12 4:41am    
You are right. As I say in my answer -- no reason for that. This is just a very inadequate question; OP needs to learn the very basic stuff but is writing XAML instead.
--SA
Jephunneh Malazarte 19-Jan-12 9:21am    
I agree with you SA... sorry wasn't able to read your answer before i clicked submit almost at the same time i guess hehehehe... :)

You never need "multiple commands". You just need several different methods called on a click, say, methods A, B and C. A "command" is actually a delegate instance. It should be some named or anonymous delegate instance with the following simple implementation: call A, B and C. :-)

Simple, isn't it?

—SA
 
Share this answer
 
Comments
Jephunneh Malazarte 19-Jan-12 9:23am    
I agree, the idea is to make the code simple yet elegant :) got my 5! you nailed it for nk hehehe.
Sergey Alexandrovich Kryukov 19-Jan-12 12:00pm    
Right. Thank you, Jephunneh.
--SA
You need MultiBinding

Read these pages :
http://www.switchonthecode.com/tutorials/wpf-tutorial-using-multibindings[^]

http://msdn.microsoft.com/en-us/library/system.windows.data.imultivalueconverter.aspx[^]

use Google to find more info on this topic.

Hope it helps.
 
Share this answer
 
Use a flag when first hit add 1 and so
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Jan-12 4:41am    
Huh?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900