This is a short post in which i will explain how on Windows phone 8 to bind the application bar button or menu item, first this is only a fix for the BindableApplicationbar which supports windows phone 7 only, i just made it support windows 8 no features added or anything.
i have uploaded the dll file here so it can be accessible easily here is the link to download
http://sdrv.ms/RApUal
i have uploaded the dll file here so it can be accessible easily here is the link to download
http://sdrv.ms/RApUal
now that you got the link lets check how we gonna use it
you can refer to BinableApplicationbar
or check out the code here that i actually used in my app and i already read it there !
- Add a reference to the BindableApplicationBar library here is the link again http://sdrv.ms/RApUal
- Add XML namespace declaration in your page's XAML:
xmlns:bar="clr-namespace:BindableApplicationBar;assembly=BindableApplicationBar" - Set Bindable.ApplicationBar property on your page code as in the snippet below:
<phone:PhoneApplicationPage>…<bar:Bindable.ApplicationBar><bar:BindableApplicationBar></bar:BindableApplicationBar></bar:Bindable.ApplicationBar></phone:PhoneApplicationPage> - Bind properties of the BindableApplicationBar to your view model. Available properties:
- BackgroundColor
- BindableOpacity
- Buttons (also the default Content property – you can just put BindableApplicationBarButton XML elements inside of the BindableApplicationBar XML element).
BindableApplicationBarButton properties:- Command
- CommandParameter
- IconUri
- IsEnabled
- Text (note that the control can only fit up to about 11 characters and will trim anything over that limit)
- ButtonsSource (alternative to Buttons – allows to bind to a collection of view models in a similar fashion to ListBox.ItemsSource)
- ButtonTemplate (used with ButtonsSource in a similar way ListBox.ItemTemplate is used with ListBox.ItemsSource)
- ForegroundColor
- IsMenuEnabled
- IsMenuVisible
- IsVisible
- MenuItems (similar to Buttons, but for BindableApplicationBarMenuItem elements and needs to be specified explicitly as <BindableApplicationBar.MenuItems/>).
BindableApplicationBarMenuItem properties:- Command
- CommandParameter
- IsEnabled
- Text (note the text can fit about 28 digit glyph-wide characters and will trim anything over that limit)
- MenuItemsSource
- MenuItemTemplate
- Mode
- Note ApplicationBar limitations – the total number of buttons defined through either the regular ApplicationBar, BindableApplicationBar.Buttons or BindableApplicationBar.ButtonsSource can’t be higher than 4. MenuItems max out at 50. If you go over – you will get an InvalidOperationException with a message like “Too many items in list”.
<bar:Bindable.ApplicationBar>
<bar:BindableApplicationBar
IsVisible="{Binding BarIsVisible}"
IsMenuVisible="{Binding IsMenuVisible,
Mode=TwoWay}"
IsMenuEnabled="{Binding IsMenuEnabled}"
ForegroundColor="{Binding ForegroundColor,
Converter={StaticResource DoubleToColorConverter}}"
BackgroundColor="{Binding BackgroundColor,
Converter={StaticResource DoubleToColorConverter}}"
BindableOpacity="{Binding Opacity}"
Mode="{Binding Mode}"
MenuItemsSource="{Binding MenuItems}"
ButtonsSource="{Binding Buttons}">
<!--<bar:BindableApplicationBar.MenuItemTemplate>
<DataTemplate>
<bar:BindableApplicationBarMenuItem
Text="{Binding Text}"
Command="{Binding Command}"
CommandParameter="{Binding CommandParameter}"/>
</DataTemplate>
</bar:BindableApplicationBar.MenuItemTemplate>-->
<bar:BindableApplicationBarButton
Text="{Binding IconButtonText}"
IconUri="{Binding IconUri,
FallbackValue=/Icons/Dark/appbar.add.rest.png}"
IsEnabled="{Binding ButtonIsEnabled}"
/>
<bar:BindableApplicationBarButton
Text="XAML Btn 2"
IconUri="/Icons/Dark/appbar.next.rest.png"
Command="{Binding TestCommand}"
CommandParameter="{Binding TestCommandParameter}"
/>
<bar:BindableApplicationBar.MenuItems>
<bar:BindableApplicationBarMenuItem
Text="{Binding MenuItemText}"
IsEnabled="{Binding MenuItemIsEnabled}"
/>
<bar:BindableApplicationBarMenuItem
Text="XAML MnuIt 2"
Command="{Binding TestCommand2}"
CommandParameter="{Binding TestCommand2Parameter}"
/>
</bar:BindableApplicationBar.MenuItems>
</bar:BindableApplicationBar>
</bar:Bindable.ApplicationBar>
I hope this was any near of a help to you, thanks for reading
I cant add dll as a reference in VS. It says A reference to a higher version or incompatible assembly cannot be added to the project. My phone project has OS 8.0 selected.
ReplyDeleteyou need not to add the dll, get the source code of the project and add it to your solution, as explained above and then you can do the fix that i have shared with you.
Deletesame issue. it looks that this application bar is not suited for wp8. Is there any alternative ?
ReplyDeleteDid you try to the project to it manually ?
DeleteI tapped the iconbutton I bound a command to and nothing happens
ReplyDeleteI mean, when I click or tap the buttons nothings happens, and wasn't so when I use normal phone:applicationbariconbutton
ReplyDelete