Skip to content

Commit

Permalink
Merge pull request #1709 from PrismLibrary/WPF-IDestructible
Browse files Browse the repository at this point in the history
[WPF] Added support for IDestructible
  • Loading branch information
brianlagunas authored Feb 22, 2019
2 parents 982d21f + df7414c commit d476877
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions Source/Prism/Prism.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<ItemGroup>
<Compile Condition=" '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'netcoreapp3.0' " Remove="Navigation/**" />
<Compile Include="Navigation/IDestructible.cs" />
<Compile Update="Properties\Resources.Designer.cs" DesignTime="True" AutoGen="True" DependentUpon="Resources.resx" />
<EmbeddedResource Update="Properties\Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Source/Wpf/Prism.Wpf.Tests/BootstrapperFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void ConfigureDefaultRegionBehaviorsShouldAddSevenDefaultBehaviors()

bootstrapper.CallConfigureDefaultRegionBehaviors();

Assert.Equal(7, bootstrapper.DefaultRegionBehaviorTypes.Count());
Assert.Equal(8, bootstrapper.DefaultRegionBehaviorTypes.Count());
}

private static void CreateAndConfigureServiceLocatorWithDefaultRegionBehaviors()
Expand Down
2 changes: 2 additions & 0 deletions Source/Wpf/Prism.Wpf/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ protected virtual IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()

defaultRegionBehaviorTypesDictionary.AddIfMissing(AutoPopulateRegionBehavior.BehaviorKey,
typeof(AutoPopulateRegionBehavior));

defaultRegionBehaviorTypesDictionary.AddIfMissing(IDestructibleRegionBehavior.BehaviorKey, typeof(IDestructibleRegionBehavior));
}

return defaultRegionBehaviorTypesDictionary;
Expand Down
1 change: 1 addition & 0 deletions Source/Wpf/Prism.Wpf/PrismApplicationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ protected virtual void ConfigureDefaultRegionBehaviors(IRegionBehaviorFactory re
regionBehaviors.AddIfMissing(RegionMemberLifetimeBehavior.BehaviorKey, typeof(RegionMemberLifetimeBehavior));
regionBehaviors.AddIfMissing(ClearChildViewsRegionBehavior.BehaviorKey, typeof(ClearChildViewsRegionBehavior));
regionBehaviors.AddIfMissing(AutoPopulateRegionBehavior.BehaviorKey, typeof(AutoPopulateRegionBehavior));
regionBehaviors.AddIfMissing(IDestructibleRegionBehavior.BehaviorKey, typeof(IDestructibleRegionBehavior));
}
}

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

0 comments on commit d476877

Please sign in to comment.