locked
Sending arguments on events (tomha) - 3/20/2006 6:49 AM PST RRS feed

  • Question

  • By: tomha

    Hi,
    Is it possible to send arguments with an event in EID? I have several 
    buttons with similar functions and I don't want to make a separate methos for 
    each of them. I would like to have one method that takes an argument (such as 
    button-id). This method can then process all button clicks.
    
    Anyone knows how this works?
    
    Thanks,
    Tomas
    Monday, February 18, 2008 10:18 PM

Answers

  • By: Unni Ravindranathan (MS)

    The click handler has a sender that should let you know which of the Buttons 
    sent the event. For example:
    
    <Button x:Name="ButtonA" Click="OnClick"/>
    <Button x:Name="ButtonB" Click="OnClick"/>
    
    private void OnClick(object sender, RoutedEventArgs e)
    {
        Button senderButton = sender as Button;
        if(senderButton != null)
        {
            if(senderButton.Name == "ButtonA")
            {
            }
            else if(senderButton.Name == "ButtonB")
            {
            }
        }
    }
    
    Is this what you were looking for, or did I misunderstand your question?
    
    Thanks,
    -Unni
    
    -- 
    This posting is provided "AS IS" with no warranties, and confers no rights.
    
    "tomha" <tomha@discussions.microsoft.com> wrote in message 
    news:5B4310EE-F4F4-4450-B5B2-8749F7F92021@microsoft.com...
    > Hi,
    > Is it possible to send arguments with an event in EID? I have several
    > buttons with similar functions and I don't want to make a separate methos 
    > for
    > each of them. I would like to have one method that takes an argument (such 
    > as
    > button-id). This method can then process all button clicks.
    >
    > Anyone knows how this works?
    >
    > Thanks,
    > Tomas 
    
    
    
    Tuesday, February 19, 2008 12:58 AM

All replies

  • By: Unni Ravindranathan (MS)

    The click handler has a sender that should let you know which of the Buttons 
    sent the event. For example:
    
    <Button x:Name="ButtonA" Click="OnClick"/>
    <Button x:Name="ButtonB" Click="OnClick"/>
    
    private void OnClick(object sender, RoutedEventArgs e)
    {
        Button senderButton = sender as Button;
        if(senderButton != null)
        {
            if(senderButton.Name == "ButtonA")
            {
            }
            else if(senderButton.Name == "ButtonB")
            {
            }
        }
    }
    
    Is this what you were looking for, or did I misunderstand your question?
    
    Thanks,
    -Unni
    
    -- 
    This posting is provided "AS IS" with no warranties, and confers no rights.
    
    "tomha" <tomha@discussions.microsoft.com> wrote in message 
    news:5B4310EE-F4F4-4450-B5B2-8749F7F92021@microsoft.com...
    > Hi,
    > Is it possible to send arguments with an event in EID? I have several
    > buttons with similar functions and I don't want to make a separate methos 
    > for
    > each of them. I would like to have one method that takes an argument (such 
    > as
    > button-id). This method can then process all button clicks.
    >
    > Anyone knows how this works?
    >
    > Thanks,
    > Tomas 
    
    
    
    Tuesday, February 19, 2008 12:58 AM
  • By: tomha

    Yes, it answered my question. Thanks!
    Tuesday, February 19, 2008 12:59 AM