本文整理汇总了C#中IRegion.Add方法的典型用法代码示例。如果您正苦于以下问题:C# IRegion.Add方法的具体用法?C# IRegion.Add怎么用?C# IRegion.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRegion
的用法示例。
在下文中一共展示了IRegion.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadContent
/// <summary>
/// Gets the view to which the navigation request represented by <paramref name="navigationContext"/> applies.
/// </summary>
/// <param name="region">The region.</param>
/// <param name="navigationContext">The context representing the navigation request.</param>
/// <returns>
/// The view to be the target of the navigation request.
/// </returns>
/// <remarks>
/// If none of the views in the region can be the target of the navigation request, a new view
/// is created and added to the region.
/// </remarks>
/// <exception cref="ArgumentException">when a new view cannot be created for the navigation request.</exception>
public object LoadContent(IRegion region, NavigationContext navigationContext)
{
if (region == null)
throw new ArgumentNullException(nameof(region));
if (navigationContext == null)
throw new ArgumentNullException(nameof(navigationContext));
string candidateTargetContract = this.GetContractFromNavigationContext(navigationContext);
var candidates = this.GetCandidatesFromRegion(region, candidateTargetContract);
var acceptingCandidates =
candidates.Where(
v =>
{
var navigationAware = v as INavigationAware;
if (navigationAware != null && !navigationAware.IsNavigationTarget(navigationContext))
{
return false;
}
var frameworkElement = v as FrameworkElement;
if (frameworkElement == null)
{
return true;
}
navigationAware = frameworkElement.DataContext as INavigationAware;
return navigationAware == null || navigationAware.IsNavigationTarget(navigationContext);
});
var view = acceptingCandidates.FirstOrDefault();
if (view != null)
{
return view;
}
view = this.CreateNewRegionItem(candidateTargetContract);
region.Add(view);
return view;
}
示例2: LoadContent
/// <summary>
/// Gets the view to which the navigation request represented by <paramref name="navigationContext"/> applies.
/// </summary>
/// <param name="region">The region.</param>
/// <param name="navigationContext">The context representing the navigation request.</param>
/// <returns>The view to be the target of the navigation request.</returns>
/// <exception cref="ArgumentException">When a new view cannot be created for the navigation request.</exception>
public virtual object LoadContent( IRegion region, NavigationContext navigationContext )
{
if ( region == null )
{
throw new ArgumentNullException ( "region" );
}
if ( navigationContext == null )
{
throw new ArgumentNullException ( "navigationContext" );
}
_logger.Debug ( "Navigation request - Region: {0} - Uri: {1}", region.Name, navigationContext.Uri );
var candidateTargetContract = GetContractFromNavigationContext ( navigationContext );
var candidates = GetCandidatesFromRegion ( region, candidateTargetContract );
var acceptingCandidates =
candidates.Where (
v =>
{
var navigationAware = v as INavigationAware;
if ( navigationAware != null && !navigationAware.IsNavigationTarget ( navigationContext ) )
{
return false;
}
var frameworkElement = v as FrameworkElement;
if ( frameworkElement == null )
{
return true;
}
navigationAware = frameworkElement.DataContext as INavigationAware;
return navigationAware == null || navigationAware.IsNavigationTarget ( navigationContext );
} );
var view = acceptingCandidates.FirstOrDefault ();
if ( view != null )
{
return view;
}
view = CreateNewRegionItem ( candidateTargetContract );
var createScopedRegion = region.Behaviors.ContainsKey ( "CreateScopedRegionBehavior" );
var regionManager = region.Add ( view, null, createScopedRegion );
TrySetRegionManager ( view, regionManager );
return view;
}