forked from PrismLibrary/Prism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
982d21f
commit df7414c
Showing
5 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Source/Wpf/Prism.Wpf/Regions/Behaviors/IDestructibleRegionBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Prism.Common; | ||
using Prism.Navigation; | ||
using System; | ||
using System.Collections.Specialized; | ||
|
||
namespace Prism.Regions.Behaviors | ||
{ | ||
public class IDestructibleRegionBehavior : RegionBehavior | ||
{ | ||
public const string BehaviorKey = "IDestructibleRegionBehavior"; | ||
|
||
protected override void OnAttach() | ||
{ | ||
Region.Views.CollectionChanged += Views_CollectionChanged; | ||
} | ||
|
||
private void Views_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) | ||
{ | ||
if (e.Action == NotifyCollectionChangedAction.Remove) | ||
{ | ||
foreach (var item in e.OldItems) | ||
{ | ||
Action<IDestructible> invocation = destructible => destructible.Destroy(); | ||
MvvmHelpers.ViewAndViewModelAction(item, invocation); | ||
} | ||
} | ||
} | ||
} | ||
} |