diff options
author | Brian Lagunas <brianlagunas@users.noreply.github.com> | 2017-05-30 23:44:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-30 23:44:08 +0300 |
commit | b25192dd615bbf11c1160954445794f150bde2ee (patch) | |
tree | c7420df994e609d02e7e2ade940463513fcb9e9b | |
parent | de768822f1f3de4326ebe753969aed021f815968 (diff) | |
parent | 088511fe7d92e193c5a5ec6dcb6ed31caf2f98ec (diff) |
Merge pull request #1001 from dvorn/KeepAliveFalseRemoveRegion
KeepAlive False Remove region
6 files changed, 58 insertions, 45 deletions
diff --git a/Source/Wpf/Prism.Wpf.Tests/Mocks/ViewModels/MockViewModel.cs b/Source/Wpf/Prism.Wpf.Tests/Mocks/ViewModels/MockViewModel.cs index cd01ade..49e1fd0 100644 --- a/Source/Wpf/Prism.Wpf.Tests/Mocks/ViewModels/MockViewModel.cs +++ b/Source/Wpf/Prism.Wpf.Tests/Mocks/ViewModels/MockViewModel.cs @@ -21,7 +21,7 @@ namespace Prism.Wpf.Tests.Mocks.ViewModels internal void InvokeOnPropertyChanged() { - this.OnPropertyChanged(() => this.MockProperty); + this.RaisePropertyChanged(nameof(MockProperty)); } } } diff --git a/Source/Wpf/Prism.Wpf.Tests/Regions/Behaviors/RegionMemberLifetimeBehaviorFixture.cs b/Source/Wpf/Prism.Wpf.Tests/Regions/Behaviors/RegionMemberLifetimeBehaviorFixture.cs index d660896..01c16fd 100644 --- a/Source/Wpf/Prism.Wpf.Tests/Regions/Behaviors/RegionMemberLifetimeBehaviorFixture.cs +++ b/Source/Wpf/Prism.Wpf.Tests/Regions/Behaviors/RegionMemberLifetimeBehaviorFixture.cs @@ -70,6 +70,32 @@ namespace Prism.Wpf.Tests.Regions.Behaviors } [TestMethod] + public void WhenIRegionMemberLifetimeItemReturnsKeepAliveFalseCanRemoveFromRegion() + { + // Arrange + var regionItemMock = new Mock<IRegionMemberLifetime>(); + regionItemMock.Setup(i => i.KeepAlive).Returns(false); + + var view = regionItemMock.Object; + + Region.Add(view); + Region.Activate(view); + + // The presence of the following two lines is essential for the test: + // we want to access both ActiveView and Views in that order + Assert.IsTrue(Region.ActiveViews.Contains(view)); + Assert.IsTrue(Region.Views.Contains(view)); + + // Act + // This may throw + Region.Remove(view); + + // Assert + Assert.IsFalse(Region.Views.Contains(view)); + Assert.IsFalse(Region.ActiveViews.Contains(view)); + } + + [TestMethod] public void WhenRegionContainsMultipleMembers_OnlyRemovesThoseDeactivated() { // Arrange diff --git a/Source/Wpf/Prism.Wpf/Prism.Wpf.csproj b/Source/Wpf/Prism.Wpf/Prism.Wpf.csproj index 2b8f51b..79ea76b 100644 --- a/Source/Wpf/Prism.Wpf/Prism.Wpf.csproj +++ b/Source/Wpf/Prism.Wpf/Prism.Wpf.csproj @@ -211,7 +211,6 @@ <Compile Include="Regions\ViewRegistrationException.cs" /> <Compile Include="Regions\ViewRegistrationException.Desktop.cs" /> <Compile Include="Regions\ViewsCollection.cs" /> - <Compile Include="Regions\ViewsCollection.Desktop.cs" /> <Compile Include="Regions\ViewSortHintAttribute.cs" /> <Compile Include="Extensions\ServiceLocatorExtensions.cs" /> <Compile Include="Common\UriParsingHelper.cs" /> diff --git a/Source/Wpf/Prism.Wpf/Regions/Region.cs b/Source/Wpf/Prism.Wpf/Regions/Region.cs index bc9786e..08ec15a 100644 --- a/Source/Wpf/Prism.Wpf/Regions/Region.cs +++ b/Source/Wpf/Prism.Wpf/Regions/Region.cs @@ -122,6 +122,12 @@ namespace Prism.Regions { get { + if (this.views == null) + { + this.views = new ViewsCollection(ItemMetadataCollection, x => true); + this.views.SortComparison = this.sort; + } + if (this.activeViews == null) { this.activeViews = new ViewsCollection(ItemMetadataCollection, x => x.IsActive); diff --git a/Source/Wpf/Prism.Wpf/Regions/ViewsCollection.Desktop.cs b/Source/Wpf/Prism.Wpf/Regions/ViewsCollection.Desktop.cs deleted file mode 100644 index 7a7e9c9..0000000 --- a/Source/Wpf/Prism.Wpf/Regions/ViewsCollection.Desktop.cs +++ /dev/null @@ -1,34 +0,0 @@ - - -using System.Collections; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Linq; - -namespace Prism.Regions -{ - public partial class ViewsCollection - { - private void NotifyAdd(IList items, int newStartingIndex) - { - if (items.Count > 0) - { - OnCollectionChanged(new NotifyCollectionChangedEventArgs( - NotifyCollectionChangedAction.Add, - items, - newStartingIndex)); - } - } - - private void NotifyRemove(IList items, int originalIndex) - { - if (items.Count > 0) - { - OnCollectionChanged(new NotifyCollectionChangedEventArgs( - NotifyCollectionChangedAction.Remove, - items, - originalIndex)); - } - } - } -} diff --git a/Source/Wpf/Prism.Wpf/Regions/ViewsCollection.cs b/Source/Wpf/Prism.Wpf/Regions/ViewsCollection.cs index 02751a0..7519ed1 100644 --- a/Source/Wpf/Prism.Wpf/Regions/ViewsCollection.cs +++ b/Source/Wpf/Prism.Wpf/Regions/ViewsCollection.cs @@ -14,7 +14,7 @@ namespace Prism.Regions /// and filters it to display an <see cref="INotifyCollectionChanged"/> collection of /// <see cref="object"/> elements (the items which the <see cref="ItemMetadata"/> wraps). /// </summary> - public partial class ViewsCollection : IViewsCollection + public class ViewsCollection : IViewsCollection { private readonly ObservableCollection<ItemMetadata> subjectCollection; @@ -62,11 +62,6 @@ namespace Prism.Regions } } - private IEnumerable<object> FilteredItems - { - get { return this.filteredItems; } - } - /// <summary> /// Determines whether the collection contains a specific value. /// </summary> @@ -74,7 +69,7 @@ namespace Prism.Regions /// <returns><see langword="true" /> if <paramref name="value"/> is found in the collection; otherwise, <see langword="false" />.</returns> public bool Contains(object value) { - return this.FilteredItems.Contains(value); + return this.filteredItems.Contains(value); } ///<summary> @@ -85,8 +80,7 @@ namespace Prism.Regions ///</returns> public IEnumerator<object> GetEnumerator() { - return - this.FilteredItems.GetEnumerator(); + return this.filteredItems.GetEnumerator(); } ///<summary> @@ -307,5 +301,27 @@ namespace Prism.Regions return this.comparer(x, y); } } + + private void NotifyAdd(IList items, int newStartingIndex) + { + if (items.Count > 0) + { + OnCollectionChanged(new NotifyCollectionChangedEventArgs( + NotifyCollectionChangedAction.Add, + items, + newStartingIndex)); + } + } + + private void NotifyRemove(IList items, int originalIndex) + { + if (items.Count > 0) + { + OnCollectionChanged(new NotifyCollectionChangedEventArgs( + NotifyCollectionChangedAction.Remove, + items, + originalIndex)); + } + } } }
\ No newline at end of file |