2016-01-29 38 views
0

在一個WPF應用程序,我們有必要有時創建一個包含在一個框架頁面的新選項卡後..WPF - 破壞頁面卸載已運行

一旦頁面被打開(初始化一次),它還是似乎停留在導航歷史記錄中,並試圖加載當時可能不相關的數據。

我已經試過的方法,包括NavigationService.RemoveBackEntry萬千,但它仍然存在:-(

這是如何的標籤/頁面被打開

Private Sub CashFlow_Edit(sender As Object, e As RoutedEventArgs) 
    Try 
     Dim DGV As DGVx = ReportsCashFlow_Grid.FindName("CashFlow_DGV") 
     e.Handled = True 
     IsNewRecord = False 

     If DGV.SelectedItems.Count = 1 Then 
      Dim row As System.Data.DataRowView = DGV.SelectedItems(0) 
      Form_ID = row("ID") 
      Dim vName As String = row("Name") 
      Dim vTab As STC_Tabx = Application.Current.MainWindow.FindName(TabName) 
      Dim TabControl As STCx = Application.Current.MainWindow.FindName("AccountingReports_TabControl") 
      If Not vTab Is Nothing Then 
       vTab.Close() 
      End If 
      Dim MCFrame As New Frame 
      Dim MCTab As New STC_Tabx 
      With MCTab 
       .Name = TabName 
       .Header = " " & vName & " " 
       .ImageSource = ReturnImageAsString("Edit.png", 16) 
       .CloseButtonVisibility = DevComponents.WpfEditors.eTabCloseButtonVisibility.Visible 
       .TabToolTip = "View or edit the " & vName & " template" 
       .Content = MCFrame 
      End With 
      RemoveHandler MCTab.Closing, AddressOf TabControl_TabClosing 
      AddHandler MCTab.Closing, AddressOf TabControl_TabClosing 

      Dim vGrid As Grid = Application.Current.MainWindow.FindName("MainGrid_Accounting") 
      RegisterControl(vGrid, MCTab) 
      TabControl.Items.Add(MCTab) 
      Dim MCPage As New ReportCashFlow_Page 
      MCFrame.NavigationService.Navigate(MCPage) 
      LoadedTabs(TabName) 
      MCTab.IsSelected = True 


     End If 

    Catch ex As Exception 
     EmailError(ex) 
    End Try 
End Sub 

回答

0

這不是代碼,我想幹淨一點,但它的工作原理 - 創建一個全局布爾 - 當打開的選項卡/頁子是卡萊d它被設置爲true,如果這是真的,加載事件將只運行加載代碼 - 最後它被設置爲false。

Private Sub ReportCashFlow_Page_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded 
    Try 


     If IsNewTab = False Then 
      Exit Sub 
     End If 
'Run all the loading code here 


    Catch ex As Exception 
     EmailError(ex) 
    Finally 
     IsNewTab = False 
     Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, CType(Sub() CashFlow_LoadBudget(), SendOrPostCallback), Nothing) 
     Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, CType(Sub() ToggleReserve(), SendOrPostCallback), Nothing) 
    End Try 
End Sub 
0

要刪除所有的示例回條目做這樣的事情:

while(NavigationService.CanGoBack) 
{ 
    NavigationService.RemoveBackEntry(); 
} 
+0

試過 - 沒有效果 – gchq