[英]Dynamically add Applicationbar in Application.Resources
誰能告訴我如何動態執行以下操作。 我已經提到了很多網站。 但沒有任何幫助。
<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
。 但是如何在運行時添加
ApplicationBar = (Microsoft.Phone.Shell.ApplicationBar)Resources["SingleSelectionAppBar"];
簡單的解決方案,但我沒有很好地搜索。 無論如何在這里添加解決方案
句法:
Application.Current.Resources.Add (name, value)
樣品
Application.Current.Resources.Add("DefaultAppBar", AppBar1);
Application.Current.Resources.Add("SingleSelectionAppBar", AppBar2);
Application.Current.Resources.Add("MultiSelectionAppBar", AppBar3);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.