0

現在直面しているこの奇妙な問題があります。

WPF ページ ナビゲーションに基づいて WPF アプリケーションを作成しました。ボタンはほとんどなく、ボタンのクリックに応じて、ユーザーはそれぞれの WPF ページに移動します。

これらの WPF ページには、タブ コントロールがあり、selectionchanged イベント ハンドラーを使用していくつかのタスクを実行しました。

さて本題ですが、

特定のページに移動しようとすると、ページが完全にロードされる前でも selectionchanged イベントも実行されます。windows.loaded を使用しようとしました (以前の質問 -ここに提供された回答に基づいて) - 運がありません.

[WPF ナビゲーション フレームワークを使用しています]

どういうわけか、selectionchanged イベントが 2 回実行されています。

これが起こらないようにするにはどうすればよいですか?

4

1 に答える 1

1

これらと発射の違いを確認SelectionChange.AddedItemsして見つける必要があると思います。SelectionChange.RemovedItemsページSelectionChange.RemovedItems==0を選択すると、tabItem をクリックして選択すると、SelectionChange.RemovedItems==1. もしそうなら、ただ書いてください:

if (SelectionChange.RemovedItems==0)
return;

Edit1: 最初のコメントを参照してください。

編集 2

void tablcontrol_SelectionChange(object sender, SelectionChangedEventArgs e)
{
     if (e.RemovedItems.Count == 0)
     {
          // I guess this is the event that happens when a page is selected
          // in this case just a TabItem is added to the selection 
          // and nothing is removed, so do nothing
          return; 
     }

     // if you are here, it means that this is another selection changed event
     // so Perform those tasks that you mentioned in your question
}
于 2012-12-22T09:52:50.233 に答える