簡體   English   中英

如何在Windows Phone 8.1中更改共享的應用程序欄的標簽

[英]How to change the label of shared App bar in windows phone 8.1

我正在開發Windows Phone 8.1應用。 我在頁面之間使用了共享應用程序欄。 在某個時間點,我需要更改全局應用程序欄的標簽或圖標。 這可能嗎?

您的想法會有所幫助。

WP8.1的BottomAppBar是CommandBar ,您將在其中找到PrimaryCommands屬性 ,其中可能有AppBarButtons 例如,如果您要更改標簽圖標Icon)或其他任何東西),則應該可以這樣做:

// change the label of the first button
((BottomAppBar as CommandBar).PrimaryCommands[0] as AppBarButton).Label = "New Label";

如果要經常更改AppBarButton的參數,以使其變得更容易,則可以編寫一個簡單的擴展方法:

/// <summary>
/// Get AppBarButton of AppBar - extension method
/// </summary>
/// <param name="index">index of target AppBarButton</param>
/// <returns>AppBarButton of desired index</returns>
public static AppBarButton PButton(this AppBar appBar, int index) { return (appBar as CommandBar).PrimaryCommands[index] as AppBarButton; }

當然與上面相同,但是使用起來卻很簡單:

BottomAppBar.PButton(0).Label = "New label";

如果您將應用程序欄存儲在“資源”中,則可以通過以下代碼進行訪問:

var commandBar = Application.Current.Resources["YouResourceKeyForAppBar"] as AppBar;

現在,您可以對其進行引用,並且可以修改其中的項目。 如果您以其他方式實現了SharedApp,請編輯問題並提供更多信息。

借助Windows.UI.ViewManagement命名空間中的8.1庫(即StatusBarApplicationView的標題),也許我可以建議其他解決方案

這不會幫助解決這種情況,但是對於其他正在查看此帖子的人來說,可能會使事情變得更簡單。

var titleName = "TITLE";

var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
statusBar.ProgressIndicator.Text = titleName;

var applicationView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
applicationView.Title = titleName;

然后要顯示和隱藏,請控制:

await statusBar.ProgressIndicator.ShowAsync();
await statusBar.ProgressIndicator.HideAsync();

不幸的是,您只能在此處設置標題。 我認為您不能為StatusBar設置自定義樣式。

public MainPage()

{this.InitializeComponent();

Loaded += MainPage_Loaded;
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
CommandBar bottomCommandBar = this.BottomAppBar as CommandBar;
AppBarButton appbarButton_0 = bottomCommandBar.PrimaryCommands[0] as AppBarButton;
appbarButton_0.Label = "settings";
appbarButton_0.Icon = new SymbolIcon(Symbol.Setting);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM