The quest for a Bindable ApplicationBar – Part 3

This is it – for now at least. The BindableApplicationBar meets all the original requirements and while I found some new ones that might be achievable – it might already be in many ways the richest solution to the problem.

DataContext Changes

I made one significant change to how the DataContexts of these controls are bound to the page DataContext – instead of creating a separate helper property and using the FlexibleDataContextChangedHelper – I decided to just bind the DataContext of the bar to the DataContext of the page and bind the DataContexts of the buttons and menu items to the DataContext of the bar. It seems to be working OK in my testing so far.

ButtonsSource, ButtonTemplate, MenuItemsSource, MenuItemTemplate

The BindableApplicationBar now allows binding to a collection of view models for both the buttons and menu items. You can specify a ButtonTemplate and/or MenuItemTemplate to define how the buttons and menu items are bound to your view models or just rely on the ones from the default style of the BindableApplicationBar. I had to change the base class of the BindableApplicationBar from FrameworkElement to Control to allow using the DefaultStyleKey, which adds even more properties that are not used, but it is the best solution I could come up with.

Mixed Button and MenuItem Definition Sources

You can now define your buttons and menu items just defining the ApplicationBar properties in XAML or code behind, by adding BindableApplicationBarButton/MenuItem elements to the BindableApplicationBar Buttons or MenuItems collections (most likely in XAML, though doing that in code should still be possible) as well as binding the Buttons/MenuItems-Source properties to view model collections and do all these things together if you so wish!

Button and MenuItem Limits

So, you can now add or remove buttons and menu items by changing a collection in a view model, but it is also up to the view model to keep the number of buttons and menu items within the limits. It seems like right now you can have up to 4 ApplicationBarIconButtons and up to 50 ApplicationBarMenuItems in an ApplicationBar. If you add these using multiple ways as I mentioned earlier – you can easily make a mistake when checking the limits, so be warned and do not try adding too many buttons to your application bar! Smile

Now on codeplex

It turns out using codeplex is easy and fun, so since the project has grown a bit – instead of just publishing it on DropBox – I put it on codeplex, so try it out and let me know how it works for you!

http://bindableapplicationb.codeplex.com/

Posts regarding Bindable ApplicationBar

  1. The quest for a Bindable ApplicationBar – Part 1
  2. The quest for a Bindable ApplicationBar – Part 2
  3. The quest for a Bindable ApplicationBar – Part 3
  4. BindableApplicationBar RC1 + Windows Phone Prism Application Template
  5. BindableApplicationBar for Windows Phone – Now On NuGet
Advertisements
Tagged , , , , , , , , ,

4 thoughts on “The quest for a Bindable ApplicationBar – Part 3

  1. […] The quest for a Bindable ApplicationBar – Part 3 […]

  2. […] The quest for a Bindable ApplicationBar – Part 3 […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: