NEW FEATURE: Bindable SiteMaps based ApplicationBar for WP7

49 views
Skip to first unread message

Rishi Oberoi

unread,
Jan 19, 2011, 8:01:43 AM1/19/11
to nro...@googlegroups.com
I've just added a behavior that enables you to create ApplicationBar using SiteMapNodes; there are couple of reasons for this, one is to make the ApplicationBar bindable, second, is to allow you to control the ApplicationBar from your VM, and third, this should allow me to abstract away one more phone specific features to enable full use of nRoute's navigation infrastructure (more on this later). 

The xaml for using this behavior is something like:
    <nSiteMaps:SiteMaps.Primary>
     <nSiteMaps:NodesCollection>
     <nSiteMaps:CommandNode Title="Refresh" IconPath="/Images/expand.png" CommandBinding="{Binding RefreshCommand}" />
         <nSiteMaps:CommandNode Title="Search" IconPath="/Images/menuenabled.png"  CommandBinding="{Binding SearchCommand}"/>
</nSiteMaps:NodesCollection>
    </nSiteMaps:SiteMaps.Primary>

    <nSiteMaps:SiteMaps.Secondary>
     <nSiteMaps:NodesCollection>
     <nSiteMaps:CommandNode Title="Settings" CommandBinding="{Binding MessageCommand}" CommandParameter="Show Settings" />
         <nSiteMaps:CommandNode Title="About" CommandBinding="{Binding MessageCommand}" CommandParameter="Show About" />
</nSiteMaps:NodesCollection>
    </nSiteMaps:SiteMaps.Secondary>

    <i:Interaction.Behaviors>
     <nBehaviors:BridgeViewModelBehavior/>
     <nBehaviors:BridgeApplicationBarBehavior/>
    </i:Interaction.Behaviors>
So basically above, you declare two sets of "SiteMaps" - a primary and a secondary one. Then the BridgeApplicationBar Behavior turns the Primary SiteMap to the AppBar's Buttons and Secondary SiteMap to the AppBar's MenuItems. Also the nodes can be NavigationNodes or ControllerActionNodes or even your own custom node types - so it's quite flexible. 

Now, if you wanted, you can also source the entire nodes from elsewhere, like from the App.xaml declaration or your VM. Consider: 
<phone:PhoneApplicationPage ...
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     nSiteMaps:SiteMaps.Primary="{Binding PrimaryNodes}"     nSiteMaps:SiteMaps.Secondary="{StaticResource ApplicationsSiteMapNodes}">
<i:Interaction.Behaviors>
<nBehaviors:BridgeViewModelBehavior/>
<nBehaviors:BridgeApplicationBarBehavior/>
</i:Interaction.Behaviors>
...
</phone:PhoneApplicationPage>
Now, as of now this is not fully finished, but does anyone have an opinion on if this is good, bad, or ugly? 

Also FYI, the Primary and Secondary SiteMaps will also be available in both WPF and SL, the idea being (as Garth wanted) that you can expose a set of functionality in a standardized way that can be integrated in the shell or be used to source a menu. Further, like with SiteMaps this functionality could come from a db or be created in real-time etc.

Cheers,
Rishi
Reply all
Reply to author
Forward
0 new messages