Windows phone 8 在Application.Resources中动态添加Applicationbar

Windows phone 8 在Application.Resources中动态添加Applicationbar,windows-phone-8,application-bar,application-resource,Windows Phone 8,Application Bar,Application Resource,谁能告诉我怎么做下面的事情。我参考了很多网站。但什么都帮不了我 <phone:PhoneApplicationPage.Resources> <shell:ApplicationBar x:Key="DefaultAppBar" IsVisible="True"> <shell:ApplicationBarIconButton x:Name="mnuAdd" IconUri="/icons/appbar.add.rest.png" IsEna

谁能告诉我怎么做下面的事情。我参考了很多网站。但什么都帮不了我

<phone:PhoneApplicationPage.Resources>
    <shell:ApplicationBar x:Key="DefaultAppBar" IsVisible="True">
        <shell:ApplicationBarIconButton x:Name="mnuAdd" IconUri="/icons/appbar.add.rest.png" IsEnabled="True" Text="Add" Click="mnuAdd_Click"/>
    </shell:ApplicationBar>
    <shell:ApplicationBar x:Key="SingleSelectionAppBar" IsVisible="True">
        <shell:ApplicationBarIconButton x:Name="mnuPin" IconUri="/icons/appbar.pushpin.png" IsEnabled="True" Text="Pin" Click="mnuPin_Click" />
        <shell:ApplicationBarIconButton x:Name="mnuDelete" IconUri="/icons/appbar.delete.rest.png" IsEnabled="True" Text="Delete" Click="mnuDelete_Click"/>
        <shell:ApplicationBarIconButton x:Name="mnuEdit" IconUri="/icons/appbar.edit.rest.png" IsEnabled="True" Text="Edit" Click="mnuEdit_Click"/>
    </shell:ApplicationBar>
    <shell:ApplicationBar x:Key="MultiSelectionAppBar" IsVisible="True">
        <shell:ApplicationBarIconButton x:Name="mnuDeleteMulti" IconUri="/icons/appbar.delete.rest.png" IsEnabled="True" Text="Delete" Click="mnuDelete_Click"/>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.Resources>

简单的解决方案,但我没有搜索好。无论如何,在这里添加解决方案

语法:

Application.Current.Resources.Add (name, value)
样本

ApplicationBar = (Microsoft.Phone.Shell.ApplicationBar)Resources["SingleSelectionAppBar"];
Application.Current.Resources.Add("DefaultAppBar", AppBar1);

Application.Current.Resources.Add("SingleSelectionAppBar", AppBar2);

Application.Current.Resources.Add("MultiSelectionAppBar", AppBar3);