WindowsPhone - How do you fire an event "inside" another?

3

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

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"/>
    
asked by anonymous 24.07.2014 / 04:32

1 answer

3

Since SelectionChanged and Click are events with different parameters, you can not call the 2nd form you showed, via XAML. You can, if it suits you, call the method from another method, 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 looks 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'm passing null in the "SelectionChangedEventArgs and", so if you were using "and" for something, you'll throw an exception. Anyway, to reuse this code, this is how it can be done. If you're using the "and" argument and you want to make it work, then there's a bit more work to do. Instead of passing null on the method call, pass new SelectionChangedEventArgs (...), and you have to pass the added and removed item listings, but I do not think this is your case.

    
11.08.2014 / 22:23