本文整理汇总了C#中Microsoft.Practices.Prism.Regions.Region类的典型用法代码示例。如果您正苦于以下问题:C# Region类的具体用法?C# Region怎么用?C# Region使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Region类属于Microsoft.Practices.Prism.Regions命名空间,在下文中一共展示了Region类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WhenRegionConstructed_SortComparisonIsDefault
public void WhenRegionConstructed_SortComparisonIsDefault()
{
IRegion region = new Region();
Assert.IsNotNull(region.SortComparison);
Assert.AreEqual(region.SortComparison, Region.DefaultSortComparison);
}
示例2: WhenNavigatingWithQueryString_ViewIsActivated
public void WhenNavigatingWithQueryString_ViewIsActivated()
{
// Prepare
object view = new object();
Uri viewUri = new Uri(view.GetType().Name + "?MyQuery=true", UriKind.Relative);
IRegion region = new Region();
region.Add(view);
string regionName = "RegionName";
RegionManager regionManager = new RegionManager();
regionManager.Regions.Add(regionName, region);
var serviceLocatorMock = new Mock<IServiceLocator>();
serviceLocatorMock.Setup(x => x.GetInstance<IRegionNavigationJournalEntry>()).Returns(new RegionNavigationJournalEntry());
IServiceLocator serviceLocator = serviceLocatorMock.Object;
RegionNavigationContentLoader contentLoader = new RegionNavigationContentLoader(serviceLocator);
IRegionNavigationJournal journal = new Mock<IRegionNavigationJournal>().Object;
RegionNavigationService target = new RegionNavigationService(serviceLocator, contentLoader, journal);
target.Region = region;
// Act
bool isNavigationSuccessful = false;
target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Result == true);
// Verify
Assert.IsTrue(isNavigationSuccessful);
bool isViewActive = region.ActiveViews.Contains(view);
Assert.IsTrue(isViewActive);
}
示例3: WhenViewExistsAndDoesNotImplementINavigationAware_ThenReturnsView
public void WhenViewExistsAndDoesNotImplementINavigationAware_ThenReturnsView()
{
// Arrange
var serviceLocatorMock = new Mock<IServiceLocator>();
var region = new Region();
var view = new TestView();
region.Add(view);
var navigationContext = new NavigationContext(null, new Uri(view.GetType().Name, UriKind.Relative));
var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);
// Act
var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);
// Assert
Assert.AreSame(view, returnedView);
}
示例4: WhenRegionHasMultipleViews_ThenViewsWithMatchingFullTypeNameAreConsidered
public void WhenRegionHasMultipleViews_ThenViewsWithMatchingFullTypeNameAreConsidered()
{
// Arrange
var serviceLocatorMock = new Mock<IServiceLocator>();
var region = new Region();
var view1 = new TestView();
var view2 = "view";
region.Add(view1);
region.Add(view2);
var navigationContext = new NavigationContext(null, new Uri(view2.GetType().FullName, UriKind.Relative));
var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object);
// Act
var returnedView = navigationTargetHandler.LoadContent(region, navigationContext);
// Assert
Assert.AreSame(view2, returnedView);
}
示例5: RemoveInexistentViewThrows
public void RemoveInexistentViewThrows()
{
IRegion region = new Region();
object view = new object();
region.Remove(view);
Assert.AreEqual(0, region.Views.Cast<object>().Count());
}
示例6: RemoveInexistentViewThrows
public void RemoveInexistentViewThrows()
{
IRegion region = new Region();
object view = new object();
Assert.ThrowsException<ArgumentException>(() => region.Remove(view));
Assert.AreEqual(0, region.Views.Cast<object>().Count());
}
示例7: CanAddAndRetrieveNamedViewInstance
public void CanAddAndRetrieveNamedViewInstance()
{
IRegion region = new Region();
object myView = new object();
region.Add(myView, "MyView");
object returnedView = region.GetView("MyView");
Assert.IsNotNull(returnedView);
Assert.AreSame(returnedView, myView);
}
示例8: CanAddContentToRegion
public void CanAddContentToRegion()
{
IRegion region = new Region();
Assert.AreEqual(0, region.Views.Cast<object>().Count());
region.Add(new object());
Assert.AreEqual(1, region.Views.Cast<object>().Count());
}
示例9: CanRemoveContentFromRegion
public void CanRemoveContentFromRegion()
{
IRegion region = new Region();
object view = new object();
region.Add(view);
region.Remove(view);
Assert.AreEqual(0, region.Views.Cast<object>().Count());
}
示例10: LoadContent_NoPermission_InvalidOperationException
public void LoadContent_NoPermission_InvalidOperationException()
{
var view = new object();
var mockServiceLocator = new Mock<IContainer>();
mockServiceLocator.Setup(sl => sl.Resolve<object>(It.IsAny<string>())).Returns(view);
var mockAccessControlManager = new Mock<IAccessControlManager>();
mockAccessControlManager.Setup(acm => acm.CanAccess(It.IsAny<ResourceRequest>())).Returns(false);
var region = new Region();
var secureRegionNavigationContentLoader = new SecureRegionNavigationContentLoader(mockServiceLocator.Object, mockAccessControlManager.Object);
secureRegionNavigationContentLoader.LoadContent(region, new NavigationContext(new Mock<IRegionNavigationService>().Object, new Uri("http://testuri/", UriKind.Absolute)));
}
示例11: RegionExposesCollectionOfContainedViews
public void RegionExposesCollectionOfContainedViews()
{
IRegion region = new Region();
object view = new object();
region.Add(view);
var views = region.Views;
Assert.IsNotNull(views);
Assert.AreEqual(1, views.Cast<object>().Count());
Assert.AreSame(view, views.Cast<object>().ElementAt(0));
}
示例12: MissingCandidateViewCreatesViewInRegion
public void MissingCandidateViewCreatesViewInRegion()
{
this.ConfigureMockServiceLocator();
// We cannot access the UnityRegionNavigationContentLoader directly so we need to call its
// GetCandidatesFromRegion method through a navigation request.
IRegion testRegion = new Region();
Assert.AreEqual(0, testRegion.Views.Count());
Assert.AreEqual(0, testRegion.ActiveViews.Count());
testRegion.RequestNavigate("MockView1");
Assert.AreEqual(1, testRegion.Views.Count());
Assert.AreEqual(1, testRegion.ActiveViews.Count());
}
示例13: WhenAttached_ThenAddsViewsRegisteredToTheRegion
public void WhenAttached_ThenAddsViewsRegisteredToTheRegion()
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(AutoPopulateExportedViewsBehavior).Assembly));
catalog.Catalogs.Add(new TypeCatalog(typeof(View1), typeof(View2)));
var container = new CompositionContainer(catalog);
var behavior = container.GetExportedValue<AutoPopulateExportedViewsBehavior>();
var region = new Region() { Name = "region1" };
region.Behaviors.Add("", behavior);
Assert.AreEqual(1, region.Views.Cast<object>().Count());
Assert.IsTrue(region.Views.Cast<object>().Any(e => e.GetType() == typeof(View1)));
}
示例14: RegisterNewWindowRegion
/// <summary>
/// Creates a new <see cref="IRegion"/> and registers it in the default <see cref="IRegionManager"/>
/// attaching to it a <see cref="DialogActivationBehavior"/> behavior.
/// </summary>
/// <param name="regionName">The name of the <see cref="IRegion"/>.</param>
/// <param name="windowStyle">The style to apply to the window region.</param>
public static void RegisterNewWindowRegion(string regionName, Style windowStyle)
{
// Creates a new region and registers it in the default region manager.
// Another option if you need the complete infrastructure with the default region behaviors
// is to extend DelayedRegionCreationBehavior overriding the CreateRegion method and create an
// instance of it that will be in charge of registering the Region once a RegionManager is
// set as an attached property in the Visual Tree.
var regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
if (regionManager != null)
{
IRegion region = new Region();
var behavior = new WindowDialogActivationBehavior {WindowStyle = windowStyle};
region.Behaviors.Add(DialogActivationBehavior.BehaviorKey, behavior);
region.Behaviors.Add(RegionActiveAwareBehavior.BehaviorKey, new RegionActiveAwareBehavior());
regionManager.Regions.Add(regionName, region);
}
}
示例15: ShouldFindCandidateViewWithFriendlyNameInRegion
public void ShouldFindCandidateViewWithFriendlyNameInRegion()
{
this.ConfigureMockServiceLocator();
// We cannot access the MefRegionNavigationContentLoader directly so we need to call its
// GetCandidatesFromRegion method through a navigation request.
IRegion testRegion = new Region();
MockView2 view = new MockView2();
testRegion.Add(view);
testRegion.Deactivate(view);
testRegion.RequestNavigate("SomeView");
Assert.IsTrue(testRegion.Views.Contains(view));
Assert.IsTrue(testRegion.Views.Count() == 1);
Assert.IsTrue(testRegion.ActiveViews.Count() == 1);
Assert.IsTrue(testRegion.ActiveViews.Contains(view));
}