Windowsphone - How does one event "inside" another?

Asked

Viewed 401 times

3

I defined the visibility of my combobox as Collapsed, for visual reasons and since Appbarbutton is more presentable. I want to know if it is possible to call the combobox event by firing an Appbarbutton event?

Something like:

      private void teste_click(object sender, RoutedEventArgs e)
    {
     private void combobox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {   ...

    }  }

or

    <AppBarButton x:Name="teste" HorizontalAlignment="Left" Icon="Undo" Label="" Margin="11.5,12,0,0" Grid.RowSpan="3" VerticalAlignment="Top" Click="combobox1_SelectionChanged" Grid.Column="1"/>
  • 1

    Why call it in? To my knowledge, when an element becomes visible, all the events associated with it become valid, not needing to place an event inside the other. If you want to dynamically assign the event, just put: meuObjeto_MeuHandler += Nome_Do_Handler;

1 answer

3

Since Selectionchanged and Click are events with different parameters, you cannot call it the 2nd way you showed it, via XAML. You can, if it suits you, call the method among other methods, as follows:

private void teste_click(object sender, RoutedEventArgs e)
{
    combobox1_SelectionChanged(this, null);
}

private void combobox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    ...
}

and your XAML would look like this:

    <AppBarButton x:Name="teste" HorizontalAlignment="Left" Icon="Undo" Label="" Margin="11.5,12,0,0" Grid.RowSpan="3" VerticalAlignment="Top" Click="teste_click" Grid.Column="1"/>

In this case I am passing null on "Selectionchangedeventargs and", so if you were using "and" for something, you will play an Exception. Anyway, to repurpose this code, this is how it can be done. If you’re using the "and" argument and you want to make it work, that’s a little more work. Instead of passing null in the method call, pass new Selectionchangedeventargs(...), and you will have to pass the added and removed item listings, but I don’t think this is your case.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.