WindowRegionAdaptor add WindowStartupLocation support

Dec 16, 2009 at 7:58 AM

Hi,

easy but useful thing I just did to add startup location support to the WindowRegionAdaptor...

So I added a property and assigned it in the constructor

        public Style WindowStyle { get; set; }
        public WindowStartupLocation WindowStartupLocation { get; set; }

        private class WindowRegionBehavior
        {
            private readonly WeakReference _ownerWeakReference;
            private readonly WeakReference _regionWeakReference;
            private readonly Style _windowStyle;
            private readonly WindowStartupLocation _windowStartupLocation;

            internal WindowRegionBehavior(Window owner, IRegion region, Style windowStyle, WindowStartupLocation windowStartupLocation)
            {
                _ownerWeakReference = new WeakReference(owner);
                _regionWeakReference = new WeakReference(region);
                _windowStyle = windowStyle;
                _windowStartupLocation = windowStartupLocation;
            }

Then assign it in Views_CollectionChanged:
window.WindowStartupLocation = _windowStartupLocation;
And now in your Bootstrapper when you configure your RegionAdaptorMappings you can specify CentreScreen, CentreOwner or Manual...
            if (regionAdapterMappings != null && factory != null)
            {
                regionAdapterMappings.RegisterMapping(typeof(Window), new WindowRegionAdapter(factory) { 
                    WindowStyle = (Style)Application.Current.FindResource("WindowTemplate"), 
                    WindowStartupLocation=WindowStartupLocation.CenterScreen });
            }

Cheers,
<font size="2">
Tony.
</font>
Dec 16, 2009 at 8:00 AM

I didn't get littler and littler on purpose there :)