using System;
using System.Windows;
using Microsoft.Practices.Composite.Presentation.Regions;
using Microsoft.Practices.Composite.Regions;
namespace Mammoth.Presentation.Infrastructure.Common
{
public static class RegionManagerExtensions
{
public static void AttachNewRegion(this IRegionManager regionManager, object regionTarget, string regionName)
{
if (regionManager.Regions.ContainsRegionWithName(regionName))
throw new ArgumentException("Region already exists.", regionName);
RegionManager.SetRegionManager((DependencyObject) regionTarget, regionManager);
RegionManager.SetRegionName((DependencyObject) regionTarget, regionName);
}
}
}
As you can see, this is a very simple extension method that extends the IRegionManger interface. Inside, I simply set the region manager and the region name on the desired UI element.
This solution is very simple, still it works fine (at least for me). If you have any troubles with it, let me know.
No comments:
Post a Comment