protected override void OnNavigatedFrom(NavigationEventArgs e) { // Dispose resources this.Resources.Clear(); this.Loaded -= FilteringLoaded; this.sfDataGrid.CurrentCellRequestNavigate -= OnSfDataGridCurrentCellRequestNavigate; this.sfDataGrid.Dispose(); this.sfDataGrid.ItemsSource = null; NavigationCacheMode = NavigationCacheMode.Disabled; base.OnNavigatedFrom(e); } |
<i:Interaction.Behaviors>
<i:BehaviorCollection>
<local:Behaviour />
</i:BehaviorCollection>
</i:Interaction.Behaviors>
public class Behaviour : DependencyObject, IBehavior
{
Page page;
public DependencyObject AssociatedObject
{
get
{
return page;
}
}
public void Attach(DependencyObject associatedObject)
{
page = associatedObject as Page;
page.Unloaded += Page_Unloaded;
}
private void Page_Unloaded(object sender, RoutedEventArgs e)
{
var grid = (page.Content as Grid).Children[0] as SfDataGrid;
grid.Dispose();
grid.ItemsSource = null;
}
public void Detach()
{
page.Unloaded -= Page_Unloaded;
}
}
|