提交 8db24e15 编写于 作者: D Dan Siegel

chore: adding back in missing API from migration

上级 fe330993
......@@ -229,6 +229,15 @@ namespace Prism.Regions
}
}
/// <summary>
/// Add a View by name.
/// </summary>
/// <param name="viewName"></param>
/// <returns></returns>
/// <remarks>Xamarin.Forms is in maintenance mode. This feature is not being supported.</remarks>
/// <exception cref="NotImplementedException"></exception>
public IRegionManager Add(string viewName) => throw new NotImplementedException();
/// <overloads>Adds a new view to the region.</overloads>
/// <summary>
/// Adds a new view to the region.
......
......@@ -265,7 +265,7 @@ public class Region : BindableBase, IRegion, ITargetAwareRegion
{
if (view is not VisualElement visualElement)
{
throw new Exception("The view must inherit from VisualElement.");
throw new UpdateRegionsException("The view must inherit from VisualElement.");
}
if (ItemMetadataCollection.FirstOrDefault(x => x.Item == view) != null)
......
......@@ -38,6 +38,14 @@ namespace Prism.Regions
/// <value>The comparison to use.</value>
Comparison<object> SortComparison { get; set; }
///<overloads>Adds a new view to the region.</overloads>
/// <summary>
/// Adds a new view to the region.
/// </summary>
/// <param name="viewName">The view to add.</param>
/// <returns>The <see cref="IRegionManager"/> that is set on the view. It will be the current region manager when using this overload.</returns>
IRegionManager Add(string viewName);
///<overloads>Adds a new view to the region.</overloads>
/// <summary>
/// Adds a new view to the region.
......
using System;
using System.Runtime.Serialization;
namespace Prism.Regions.Behaviors
{
/// <summary>
///
/// </summary>
[Serializable]
public partial class RegionCreationException
{
/// <summary>
/// Initializes a new instance of the <see cref="RegionCreationException"/> class with serialized data.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
protected RegionCreationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
using System;
namespace Prism.Regions.Behaviors
{
/// <summary>
/// Represents errors that occured during region creation.
/// </summary>
public partial class RegionCreationException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="RegionCreationException"/>
/// </summary>
public RegionCreationException()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RegionCreationException"/> class with a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public RegionCreationException(string message)
: base(message)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RegionCreationException"/> class with a specified error message and a reference
/// to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="inner">The exception that is the cause of the current exception, or a null reference
/// (Nothing in Visual Basic) if no inner exception is specified.</param>
public RegionCreationException(string message, Exception inner)
: base(message, inner)
{
}
}
}
......@@ -32,6 +32,7 @@ namespace Prism.Regions
private object _context;
private IRegionManager _regionManager;
private IRegionNavigationService _regionNavigationService;
private IContainerProvider _container;
private Comparison<object> _sort;
......@@ -41,6 +42,7 @@ namespace Prism.Regions
public Region()
{
Behaviors = new RegionBehaviorCollection(this);
_container = ContainerLocator.Container;
_sort = DefaultSortComparison;
}
......@@ -226,6 +228,18 @@ namespace Prism.Regions
}
}
/// <overloads>Adds a new view to the region.</overloads>
/// <summary>
/// Adds a new view to the region.
/// </summary>
/// <param name="viewName">The view to add.</param>
/// <returns>The <see cref="IRegionManager"/> that is set on the view if it is a <see cref="DependencyObject"/>. It will be the current region manager when using this overload.</returns>
public IRegionManager Add(string viewName)
{
var view = _container.Resolve<object>(viewName);
return Add(view, viewName, false);
}
/// <overloads>Adds a new view to the region.</overloads>
/// <summary>
/// Adds a new view to the region.
......@@ -234,7 +248,7 @@ namespace Prism.Regions
/// <returns>The <see cref="IRegionManager"/> that is set on the view if it is a <see cref="DependencyObject"/>. It will be the current region manager when using this overload.</returns>
public IRegionManager Add(object view)
{
return this.Add(view, null, false);
return Add(view, null, false);
}
/// <summary>
......@@ -250,7 +264,7 @@ namespace Prism.Regions
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.StringCannotBeNullOrEmpty, "viewName"));
}
return this.Add(view, viewName, false);
return Add(view, viewName, false);
}
/// <summary>
......@@ -262,8 +276,8 @@ namespace Prism.Regions
/// <returns>The <see cref="IRegionManager"/> that is set on the view if it is a <see cref="DependencyObject"/>.</returns>
public virtual IRegionManager Add(object view, string viewName, bool createRegionManagerScope)
{
IRegionManager manager = createRegionManagerScope ? this.RegionManager.CreateRegionManager() : this.RegionManager;
this.InnerAdd(view, viewName, manager);
IRegionManager manager = createRegionManagerScope ? RegionManager.CreateRegionManager() : RegionManager;
InnerAdd(view, viewName, manager);
return manager;
}
......@@ -273,11 +287,11 @@ namespace Prism.Regions
/// <param name="view">The view to remove.</param>
public virtual void Remove(object view)
{
ItemMetadata itemMetadata = this.GetItemMetadataOrThrow(view);
ItemMetadata itemMetadata = GetItemMetadataOrThrow(view);
ItemMetadataCollection.Remove(itemMetadata);
if (view is DependencyObject dependencyObject && Regions.RegionManager.GetRegionManager(dependencyObject) == this.RegionManager)
if (view is DependencyObject dependencyObject && Regions.RegionManager.GetRegionManager(dependencyObject) == RegionManager)
{
dependencyObject.ClearValue(Regions.RegionManager.RegionManagerProperty);
}
......@@ -300,7 +314,7 @@ namespace Prism.Regions
/// <param name="view">The view to activate.</param>
public virtual void Activate(object view)
{
ItemMetadata itemMetadata = this.GetItemMetadataOrThrow(view);
ItemMetadata itemMetadata = GetItemMetadataOrThrow(view);
if (!itemMetadata.IsActive)
{
......@@ -314,7 +328,7 @@ namespace Prism.Regions
/// <param name="view">The view to deactivate.</param>
public virtual void Deactivate(object view)
{
ItemMetadata itemMetadata = this.GetItemMetadataOrThrow(view);
ItemMetadata itemMetadata = GetItemMetadataOrThrow(view);
if (itemMetadata.IsActive)
{
......@@ -334,7 +348,7 @@ namespace Prism.Regions
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.StringCannotBeNullOrEmpty, "viewName"));
}
ItemMetadata metadata = this.ItemMetadataCollection.FirstOrDefault(x => x.Name == viewName);
ItemMetadata metadata = ItemMetadataCollection.FirstOrDefault(x => x.Name == viewName);
if (metadata != null)
{
......@@ -351,7 +365,7 @@ namespace Prism.Regions
/// <param name="navigationCallback">A callback to execute when the navigation request is completed.</param>
public void RequestNavigate(Uri target, Action<NavigationResult> navigationCallback)
{
this.RequestNavigate(target, navigationCallback, null);
RequestNavigate(target, navigationCallback, null);
}
/// <summary>
......@@ -362,22 +376,22 @@ namespace Prism.Regions
/// <param name="navigationParameters">The navigation parameters specific to the navigation request.</param>
public void RequestNavigate(Uri target, Action<NavigationResult> navigationCallback, INavigationParameters navigationParameters)
{
this.NavigationService.RequestNavigate(target, navigationCallback, navigationParameters);
NavigationService.RequestNavigate(target, navigationCallback, navigationParameters);
}
private void InnerAdd(object view, string viewName, IRegionManager scopedRegionManager)
{
if (this.ItemMetadataCollection.FirstOrDefault(x => x.Item == view) != null)
if (ItemMetadataCollection.FirstOrDefault(x => x.Item == view) != null)
{
throw new InvalidOperationException(Resources.RegionViewExistsException);
}
ItemMetadata itemMetadata = new ItemMetadata(view);
var itemMetadata = new ItemMetadata(view);
if (!string.IsNullOrEmpty(viewName))
{
if (this.ItemMetadataCollection.FirstOrDefault(x => x.Name == viewName) != null)
if (ItemMetadataCollection.FirstOrDefault(x => x.Name == viewName) != null)
{
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, Resources.RegionViewNameExistsException, viewName));
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.RegionViewNameExistsException, viewName));
}
itemMetadata.Name = viewName;
}
......@@ -388,7 +402,7 @@ namespace Prism.Regions
Regions.RegionManager.SetRegionManager(dependencyObject, scopedRegionManager);
}
this.ItemMetadataCollection.Add(itemMetadata);
ItemMetadataCollection.Add(itemMetadata);
}
private ItemMetadata GetItemMetadataOrThrow(object view)
......@@ -396,7 +410,7 @@ namespace Prism.Regions
if (view == null)
throw new ArgumentNullException(nameof(view));
ItemMetadata itemMetadata = this.ItemMetadataCollection.FirstOrDefault(x => x.Item == view);
ItemMetadata itemMetadata = ItemMetadataCollection.FirstOrDefault(x => x.Item == view);
if (itemMetadata == null)
throw new ArgumentException(Resources.ViewNotInRegionException, nameof(view));
......
......@@ -17,6 +17,9 @@ namespace Prism.Forms.Regions.Mocks
{
Behaviors = new MockRegionBehaviorCollection();
}
public IRegionManager Add(string viewName) => throw new NotImplementedException();
public IRegionManager Add(object view)
{
MockViews.Items.Add(view);
......
......@@ -33,6 +33,8 @@ namespace Prism.Forms.Regions.Mocks
public string Name { get; set; }
public IRegionManager Add(string viewName) => throw new NotImplementedException();
public IRegionManager Add(object view)
{
_views.Add(view);
......
......@@ -14,6 +14,9 @@ namespace Prism.Wpf.Tests.Mocks
{
Behaviors = new MockRegionBehaviorCollection();
}
public IRegionManager Add(string viewName) => throw new NotImplementedException();
public IRegionManager Add(object view)
{
MockViews.Items.Add(view);
......
......@@ -36,6 +36,8 @@ namespace Prism.Wpf.Tests.Mocks
public string Name { get; set; }
public IRegionManager Add(string viewName) => throw new NotImplementedException();
public IRegionManager Add(object view)
{
this.views.Add(view);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册