Windows Phone 7: Where to implement AppBar event handlers?
I have an AppBar that is used in many places throughout my application:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentatio开发者_StackOverflow社区n"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<shell:ApplicationBar x:Name="FavoritesBar" IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="appbar.favs.rest.png" Text="favorites" Click="AppBarFavButton_Click" />
</shell:ApplicationBar>
</ResourceDictionary>
Where do I need to implement the AppBarFavButton_Click
handler? In the code-behind for each control that uses it?
In the regular *.cs
source file that stands behind the page where the AppBar is placed.
Presumably the "favourites" button performs an action on the currently selected/displayed item on each of the different pages. As the action is specific to each page you'll need to have something on that page to handle the button click.
However, each method could in turn pass the selected item to a single object which adds the item ot the list of favourites.
It just depends on how your application works and has been put together.
Right Click on the AppBarFavButton_Click
, select Navigate to Event Handler
. An empty function body will be created in the corresponding cs file.
精彩评论