2014-02-26 57 views
0

我正在開發Windows Phone 8應用。我有兩頁,一頁有一個應用程序欄,第二頁有三個應用程序欄,根據情況隱藏和取消隱藏。除非我實施本地化,否則一切都是正確的。我遵循以下鏈接並在ApplicationBar中將頁面內的本地化應用於頁面並運行。但是,當我將相同的方式本地化應用到具有多個應用條的第二頁時,一切都失敗了。沒有任何應用程序欄可見。如何在Windows Phone 8的頁面內全球化多個ApplicationBars應用

根據該鏈接我的代碼click here to see link

private void myfucntion() 
{ 
    ApplicationBar = new ApplicationBar(); 
    ApplicationBarIconButton btnSortGridView = new ApplicationBarIconButton(new Uri("Images/grid.png", UriKind.Relative)); 
    btnSortGridView.Text = AppResources.library_gridview; 
    ApplicationBar.Buttons.Add(btnSortGridView); 
    btnSortGridView.Click += btnSortGridView_Click; 
    ApplicationBarIconButton btnSortListView = new ApplicationBarIconButton(new Uri("/Images/list.png", UriKind.Relative)); 
    btnSortListView.Text = AppResources.library_listview; 
    btnSortListView.Click += btnSortListView_Click; 
    ApplicationBar.Buttons.Add(btnSortListView); 
} 

你可以看到上面是應用程序任務的應用程序任務的對象();當我按下F12(見定義)重定向到我的PhoneApplicationPage [從元數據]及以下屬性與同名分配

public IApplicationBar ApplicationBar { get; set; } 

所以想說如果我有一個有localizatino應用程序任務欄比上述方法將工作,但如果我有不止一個ApplicationBar比這種方法不會工作。請給我你寶貴的建議。提前致謝。

+0

那麼,你總是可以使用一個應用程序欄,你手動填寫控件。 –

+1

你想創建一個ApplicationBar的另一個實例嗎?如果這樣更改'ApplicationBar = new ApplicationBar();'ApplicationBar secondBar = new ApplicationBar();' –

+0

@ShawnKendrot我也試過你的建議方法,但它不工作。 –

回答

0

通過爲新變量創建新實例,可以完成創建第二個ApplicationBar。確切地說你的代碼是設置ApplicationBar的頁面實例(如你所看到的那樣)。在代碼中,指定新的實例變量「secondBar」

private ApplicationBar CreateSecondBar() 
{ 
    ApplicationBar secondBar = new ApplicationBar(); 
    ApplicationBarIconButton btnSortGridView = new ApplicationBarIconButton(new Uri("Images/grid.png", UriKind.Relative)); 
    btnSortGridView.Text = AppResources.library_gridview; 
    btnSortGridView.Click += btnSortGridView_Click; 
    secondBar.Buttons.Add(btnSortGridView); 

    ApplicationBarIconButton btnSortListView = new ApplicationBarIconButton(new Uri("/Images/list.png", UriKind.Relative)); 
    btnSortListView.Text = AppResources.library_listview; 
    btnSortListView.Click += btnSortListView_Click; 
    secondBar.Buttons.Add(btnSortListView); 

    return secondBar; 
} 

然後,當你想改變我們的應用程序任務欄的頁面本身,你調用該方法,並從那裏設置。

var secondBar = CreateSecondBar(); 
// maybe you store this in a member variable "_secondBar" to be used whenever you need it 

// using the this keyword to distinguish between the property, and the class 
this.ApplicationBar = secondBar; 
+0

問題的回答你是對的,在我的場景中,需求是不同的,所以我在做的是設置可見性真假,並且在diff-2事件中調用我所有的appbars。 –