2013-03-19 58 views
0

任何人都可以告訴我如何動態地執行下列操作。我引用了很多網站。但沒有任何幫助我。在應用程序中動態添加應用程序欄。資源

<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> 

我們可以get the resource dynamically如下。但如何在runtine

ApplicationBar = (Microsoft.Phone.Shell.ApplicationBar)Resources["SingleSelectionAppBar"]; 

回答

0

簡單的解決方案添加,但我沒有搜查好。無論如何,然後將溶液這裏

語法:

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

樣品

Application.Current.Resources.Add("DefaultAppBar", AppBar1); 

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

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