0

私はWindows Phone 8アプリに取り組んでいます。私は 2 つのページを持っています。1 つには 1 つのアプリケーション バーがあり、2 つ目には 3 つのアプリケーション バーがあり、状況に応じて非表示と非表示を切り替えます。ローカリゼーションを実装していない限り、すべてが正しかった。次のリンクをたどって、ページとその実行中の ApplicationBar にローカライズを適用しました。しかし、複数のapplicationBarを持つ2番目のページに同じ方法のローカライズを適用すると、すべてが失敗します。アプリケーションバーは表示されません。

このリンクによる私のコードは、ここをクリックしてリンクを表示します

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);
}

上記でわかるように、ApplicationBar は ApplicationBar(); のオブジェクトです。F12を押すと(定義を参照)、[メタデータから] PhoneApplicationPageにリダイレクトされ、次のプロパティが同じ名前で割り当てられました

public IApplicationBar ApplicationBar { get; set; }

したがって、上記のアプローチよりも localizatino を持つ単一の ApplicationBar がある場合は機能しますが、複数の ApplicationBar がある場合、このアプローチは機能しません。貴重なご意見をお聞かせください。前もって感謝します。

4

1 に答える 1

0

新しい変数に新しいインスタンスを作成することで、2 番目の ApplicationBar を作成できます。現在、コードは ApplicationBar のページ インスタンスを設定しています (go to definition で見られるように)。コードで、新しいインスタンスを変数「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;
}

次に、ページ自体の ApplicationBar を変更する場合は、メソッドを呼び出してそこから設定します。

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;
于 2014-03-03T06:06:32.733 に答える