Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

MVVM Light Toolkit and Windows Phone : Bindable AppBar

0.00/5 (No votes)
22 Aug 2014 1  
This tip/trick shows you how to add bindable AppBar with MVVM Light Toolkit in Windows Phone 8

Introduction

A big problem when choosing to develop with MVVM in Windows Phone is that the native Application Bar is not bindable, so we can't get/set attributes or commands.

So, the following code snippets will show you how to add a bindable AppBar in Windows phone 8 using MVVM Light Toolkit.

Background

  • Windows Phone
  • MVVM
  • Nuget Packages

Using the code

Thanks to the CodePlex open source project "Bindable Application Bar", we can get the control that will help us achieving our goal.

P.S : There are many solutions like the Bindable AppBar Appliation project, but I choose this one beacause I think it's the easiest one.

Let's add some code!

1. Adding Nuget Package

We can add a reference to that project via its Nuget Package.

 

2. Adding Reference :

Then, we add the reference in our View.

xmlns:bar="clr-namespace:BindableApplicationBar;assembly=BindableApplicationBar"

 

3. Adding AppBar :

Finally, we add the AppBar control. We can use it the same way as we use the native AppBar.

<bar:Bindable.ApplicationBar>
    <bar:BindableApplicationBar >
        <bar:BindableApplicationBarButton IconUri="/Assets/AppBar/add.png"
                                          Command="{Binding ButtonClick}"
                                          Text="Button" />
            <bar:BindableApplicationBar.MenuItems>
            <bar:BindableApplicationBarMenuItem Command="{Binding MenuItemClick}"
                                                Text="Menu Item" />
        </bar:BindableApplicationBar.MenuItems>
    </bar:BindableApplicationBar>
</bar:Bindable.ApplicationBar>

 

That's it! I hope it was helpful.

History

This is the first version of this tip/trick. If you have any problem/question, feel free to comment.

You're welcome. Enjoy!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here