1
Vote

Duplicates with INotifyPropertyChanged

description

When binding ButtonsSource or MenuItemsSource to a viewmodel implementing INotifyPropertyChanged, duplicate buttons and menu items appear when the bound property changes. This occurs because the existing buttons/items are not removed prior to the addition of the new buttons/items. While the BindableApplicationBar members GenerateButtonsFromSource() and GenerateMenuItemsFromSource() each call a Clear() method, they are not clearing the wrapped Microsoft.Phone.Shell.ApplicationBar. To correct these problems, add the following to each, respectively, after the initial clear call:
    if (applicationBar != null)
        this.applicationBar.Buttons.Clear();
    if (applicationBar != null)
        this.applicationBar.MenuItems.Clear(); 

comments

xyzzer wrote Nov 14, 2013 at 6:04 PM

I've added suggested fixes and pushed the code back to CodePlex.
Also pushed a NuGet package here: http://www.nuget.org/packages/bindableapplicationbar

I haven't tested it thoroughly since I don't do Windows Phone development these days and don't have the time. Let me know if it works.

billvo wrote Nov 15, 2013 at 2:38 PM

The new code, with the exception of the project file, works for me. I'm stuck on Windows 7 / Windows Phone 7 due to a hardware issue. The latest project file references the Windows Phone 8 SDK, so I substituted the old project file.

Perhaps, if you release, you might identify this as a Windows Phone 8 build and preserve a separate Windows Phone 7 build.