Reputation: 1318
How can I bind EventToCommand programmatically to an ApplicationBar Button or MenuItem in Windows Phone 8? I'm currently using MVVM light and it works perfectly for all elements I can add in XAML.
Normally, I would define the ApplicationBar from Xaml and could bind from there EventToCommand in Expression Blend. But starting with WP8, Microsoft deciced to prefer an localizable ApplicationBar which will be created programmatically, as it cannot be bind that easily to different languages.
What is necessary to reproduce the same behaviour as if I would push a Button to execute EventToCommand? Is this even possible or encouraged regarding the MVVM pattern? What are my alternatives?
Upvotes: 1
Views: 799
Reputation: 16092
You can use the same old WP7 AppBar in WP8. LocalizableAppBar is just a recommendation on how to localize the AppBar.
Either way, you're likely weren't using EventToCommand on the AppBar since it doesn't support DataBinding. You'll need to use a Bindable AppBar for that. Either write a homegrown one or use one of the many OSS solutions for that, such as: AppBarUtils, BindableApplicationBar, Cimbalino or others.
Localizing one of the aforementioned ApBars will be a lot simpler since you can then databind the text to the ViewModel and use whatever text you'd like.
Upvotes: 3