Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Building a Docking Window Management Solution in WPF

, 1 Jan 2011
A docking window solution using WPF as part of Synergy toolkit
Synergy.zip
MixModes.Synergy.Resources
bin
Debug
MixModes.Synergy.Resources.dll
MixModes.Synergy.Resources.pdb
MixModes.Synergy.Resources.csproj.user
MixModes.Synergy.Resources.csproj.vspscc
MixModes.Synergy.Resources.vsdoc
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
GenerateResource-ResGen.read.1.tlog
GenerateResource-ResGen.write.1.tlog
GenerateResource.read.1.tlog
MixModes.Synergy.Resources.dll
MixModes.Synergy.Resources.g.resources
MixModes.Synergy.Resources.pdb
MixModes.Synergy.Resources.Resources.Language.resources
TempPE
Properties
Resources
Close.png
DockBottom.png
DockCenter.png
DockHexagon.png
DockLeft.png
DockRight.png
DockTop.png
Error.png
Maximize.png
Minimize.png
NewProject.png
Restore.png
SplitBottom.png
SplitLeft.PNG
SplitRight.png
SplitTop.png
MixModes.Synergy.Themes
bin
Debug
MixModes.Synergy.Resources.dll
MixModes.Synergy.Resources.pdb
MixModes.Synergy.Themes.dll
MixModes.Synergy.Themes.pdb
MixModes.Synergy.Themes.csproj.vspscc
MixModes.Synergy.Themes.vsdoc
obj
Debug
Aero.NormalColor.baml
Brushes.baml
Buttons.baml
DesignTimeResolveAssemblyReferencesInput.cache
DockPane.baml
GenerateResource-ResGen.read.1.tlog
GenerateResource-ResGen.write.1.tlog
Images.baml
MixModes.Synergy.Themes.dll
MixModes.Synergy.Themes.g.resources
MixModes.Synergy.Themes.pdb
MixModes.Synergy.Themes.Properties.Resources.resources
MixModes.Synergy.Themes_MarkupCompile.cache
ResizableAdorner.baml
ResolveAssemblyReference.cache
TabItems.baml
TempPE
Text.baml
Themes.baml
ToolTips.baml
WindowParts.baml
Windows.baml
Properties
Settings.settings
MixModes.Synergy.Utilities
bin
Debug
MixModes.Synergy.Utilities.dll
MixModes.Synergy.Utilities.pdb
MixModes.Synergy.Utilities.csproj.vspscc
MixModes.Synergy.Utilities.vsdoc
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
MixModes.Synergy.Utilities.dll
MixModes.Synergy.Utilities.pdb
TempPE
Properties
MixModes.Synergy.VisualFramework
Adorners
Behaviors
bin
Debug
de
Microsoft.Expression.Interactions.resources.dll
System.Windows.Interactivity.resources.dll
en
Microsoft.Expression.Interactions.resources.dll
System.Windows.Interactivity.resources.dll
es
Microsoft.Expression.Interactions.resources.dll
System.Windows.Interactivity.resources.dll
fr
Microsoft.Expression.Interactions.resources.dll
System.Windows.Interactivity.resources.dll
it
Microsoft.Expression.Interactions.resources.dll
System.Windows.Interactivity.resources.dll
ja
Microsoft.Expression.Interactions.resources.dll
System.Windows.Interactivity.resources.dll
ko
Microsoft.Expression.Interactions.resources.dll
System.Windows.Interactivity.resources.dll
Microsoft.Expression.Interactions.dll
MixModes.Synergy.Resources.dll
MixModes.Synergy.Resources.pdb
MixModes.Synergy.Themes.dll
MixModes.Synergy.Themes.pdb
MixModes.Synergy.Utilities.dll
MixModes.Synergy.Utilities.pdb
MixModes.Synergy.VisualFramework.dll
MixModes.Synergy.VisualFramework.pdb
System.Windows.Interactivity.dll
WPFToolkit.dll
WPFToolkit.pdb
zh-Hans
Microsoft.Expression.Interactions.resources.dll
System.Windows.Interactivity.resources.dll
zh-Hant
Microsoft.Expression.Interactions.resources.dll
System.Windows.Interactivity.resources.dll
Commands
Controls
Converters
Extensions
Framework
MixModes.Synergy.VisualFramework.csproj.user
MixModes.Synergy.VisualFramework.csproj.vspscc
MixModes.Synergy.VisualFramework.vsdoc
obj
Debug
Controls
NotificationToolTipContent.baml
DesignTimeResolveAssemblyReferencesInput.cache
MixModes.Synergy.VisualFramework.dll
MixModes.Synergy.VisualFramework.g.resources
MixModes.Synergy.VisualFramework.pdb
MixModes.Synergy.VisualFramework_MarkupCompile.cache
MixModes.Synergy.VisualFramework_MarkupCompile.lref
ResolveAssemblyReference.cache
TempPE
Themes
Generic.baml
Windows
WindowsManager.baml
Properties
Themes
ViewModels
Views
Windows
Synegy
bin
Debug
de
System.Windows.Interactivity.resources.dll
en
System.Windows.Interactivity.resources.dll
es
System.Windows.Interactivity.resources.dll
fr
System.Windows.Interactivity.resources.dll
it
System.Windows.Interactivity.resources.dll
ja
System.Windows.Interactivity.resources.dll
ko
System.Windows.Interactivity.resources.dll
MixModes.Synergy.Resources.dll
MixModes.Synergy.Resources.pdb
MixModes.Synergy.Themes.dll
MixModes.Synergy.Themes.pdb
MixModes.Synergy.Utilities.dll
MixModes.Synergy.Utilities.pdb
MixModes.Synergy.VisualFramework.dll
MixModes.Synergy.VisualFramework.pdb
Synegy.exe
Synegy.pdb
Synegy.vshost.exe
Synegy.vshost.exe.manifest
System.Windows.Interactivity.dll
zh-Hans
System.Windows.Interactivity.resources.dll
zh-Hant
System.Windows.Interactivity.resources.dll
obj
x86
Debug
App.baml
DesignTimeResolveAssemblyReferencesInput.cache
GenerateResource-ResGen.read.1.tlog
GenerateResource-ResGen.write.1.tlog
MainWindow.baml
ResolveAssemblyReference.cache
Resources
MainWindowMenus.baml
Synegy.exe
Synegy.g.resources
Synegy.pdb
Synegy.Properties.Resources.resources
Synegy_MarkupCompile.cache
TempPE
Views
NewProjectWindow.baml
Properties
Settings.settings
Resources
SplashScreen.jpg
Synegy.csproj.user
Synegy.csproj.vspscc
Synegy.vsdoc
Views
///
/// Copyright(C) MixModes Inc. 2010
/// 

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Reflection;
using System.Windows;

namespace MixModes.Synergy.VisualFramework.Framework
{
    /// <summary>
    /// Observable dependency property collection
    /// </summary>
    /// <typeparam name="T">Type of objects whose property is desired to be monitored</typeparam>
    public class ObservableDependencyPropertyCollection<T> : ObservableCollection<T> where T : DependencyObject
    {
        /// <summary>
        /// Occurs when dependency property has changed
        /// </summary>
        public event DependencyPropertyChangedEventHandler DependencyPropertyChanged;

        /// <summary>
        /// Initializes a new instance of the <see cref="ObservableDependencyPropertyCollection&lt;T&gt;"/> class.
        /// All the dependency properties in the inheritance hierarchy is monitored for changes
        /// </summary>
        public ObservableDependencyPropertyCollection()
        {
            MonitorAllDependencyProperties();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ObservableDependencyPropertyCollection&lt;T&gt;"/> class.
        /// All the dependency properties in the inheritance hierarchy is monitored for changes
        /// </summary>
        /// <param name="list">Collection whose dependency properties are to be monitored</param>
        public ObservableDependencyPropertyCollection(List<T> list)
            : base(list)
        {
            MonitorAllDependencyProperties();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ObservableDependencyPropertyCollection&lt;T&gt;"/> class.
        /// Only dependency properties specified in properties are monitored
        /// </summary>
        /// <param name="properties">Dependency properties to monitor in collection</param>
        public ObservableDependencyPropertyCollection(params DependencyProperty[] properties)
        {
            MonitorExplicitDependencyProperties(properties);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ObservableDependencyPropertyCollection&lt;T&gt;"/> class
        /// Only dependency properties specified in properties are monitored
        /// </summary>
        /// <param name="list">Collection whose dependency properties are to be monitored</param>
        /// <param name="properties">Dependency properties to monitor in collection</param>
        public ObservableDependencyPropertyCollection(List<T> list, params DependencyProperty[] properties)
            : base(list)
        {
            MonitorExplicitDependencyProperties(properties);
        }

        /// <summary>
        /// Monitors explicit dependency properties
        /// </summary>
        /// <param name="properties">Dependency properties to monitor in collection</param>
        private void MonitorExplicitDependencyProperties(params DependencyProperty[] properties)
        {
            foreach (DependencyProperty property in properties)
            {
                CreateDescriptor(property);
            }
        }

        /// <summary>
        /// Monitors all dependency properties.
        /// </summary>
        private void MonitorAllDependencyProperties()
        {
            FieldInfo[] fieldInfos = typeof(T).GetFields(BindingFlags.Public |
                                                         BindingFlags.Static |
                                                         BindingFlags.FlattenHierarchy);

            foreach (FieldInfo fieldInfo in fieldInfos)
            {
                if (fieldInfo.FieldType == typeof(DependencyProperty))
                {
                    CreateDescriptor(fieldInfo.GetValue(null) as DependencyProperty);
                }
            }
        }

        /// <summary>
        /// Creates the descriptor for property change callback
        /// </summary>
        /// <param name="property">Dependency property whose descriptor is to be created</param>
        private void CreateDescriptor(DependencyProperty property)
        {
            ObservableDependencyProperty descriptor = new ObservableDependencyProperty(typeof(T), property, OnDependencyPropertyChanged);
            _descriptors.Add(descriptor);
        }

        /// <summary>
        /// Raises the <see cref="E:CollectionChanged"/> event.
        /// </summary>
        /// <param name="args">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs"/> 
        /// instance containing the event data.</param>
        protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs args)
        {
            base.OnCollectionChanged(args);

            if (args.NewItems != null)
            {
                foreach (DependencyObject obj in args.NewItems)
                {
                    foreach (ObservableDependencyProperty descriptor in _descriptors)
                    {
                        descriptor.AddValueChanged(obj);
                    }
                }
            }

            if (args.OldItems != null)
            {
                foreach (DependencyObject obj in args.OldItems)
                {
                    foreach (ObservableDependencyProperty descriptor in _descriptors)
                    {
                        descriptor.RemoveValueChanged(obj);
                    }
                }
            }
        }

        /// <summary>
        /// Called when dependency property of an item in collection has changed
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="args">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance 
        /// containing the event data.</param>
        protected void OnDependencyPropertyChanged(object item, DependencyPropertyChangedEventArgs args)
        {
            if (DependencyPropertyChanged != null)
            {
                DependencyPropertyChanged(item, args);
            }
        }        

        // Private members
        private List<ObservableDependencyProperty> _descriptors = new List<ObservableDependencyProperty>();
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ashish Kaila
Software Developer (Senior) MixModes Inc. | Research In Motion
Canada Canada
Ashish worked for Microsoft for a number of years in Microsoft Visual Studio (Architect edition) and Windows Live division as a developer. Before that he was a developer consultant mainly involved in distributed service development / architecture. His main interests are distributed software architecture, patterns and practices and mobile device development.
 
Currently Ashish serves as a Technical Lead at RIM leading next generation BlackBerry media experience and also runs his own company MixModes Inc. specializing in .NET / WPF / Silverlight technologies. You can visit MixModes at http://mixmodes.com or follow it on Twitter @MixModes
 
In his free time he is an avid painter, hockey player and enjoys travelling. His blog is at: http://ashishkaila.serveblog.net
Follow on   Twitter

| Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 1 Jan 2011
Article Copyright 2010 by Ashish Kaila
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid