Click here to Skip to main content
15,881,588 members
Articles / Desktop Programming / WPF

Building a Docking Window Management Solution in WPF

Rate me:
Please Sign up or sign in to vote.
4.28/5 (25 votes)
1 Jan 2011CPOL8 min read 186.9K   15.7K   83  
A docking window solution using WPF as part of Synergy toolkit
///
/// Copyright(C) MixModes Inc. 2010
/// 

using System;
using System.ComponentModel;
using System.Windows;

namespace MixModes.Synergy.VisualFramework.Framework
{
    /// <summary>
    /// Wrapper class that creates a wrapper for DependencyPropertyDescriptor
    /// </summary>
    public class ObservableDependencyProperty
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ObservableDependencyPropertyCollection&lt;T&gt;.ObservableDependencyProperty"/> class.
        /// </summary>
        /// <param name="targetType">Type of the target</param>
        /// <param name="dependencyProperty">Dependency property.</param>
        /// <param name="OnDependencyPropertyChanged">Dependency property changed callback</param>
        public ObservableDependencyProperty(Type targetType,
                                 DependencyProperty dependencyProperty,
                                 DependencyPropertyChangedEventHandler OnDependencyPropertyChanged)
        {
            _descriptor = DependencyPropertyDescriptor.FromProperty(dependencyProperty, targetType);
            _dependencyProperty = dependencyProperty;
            _onDependencyPropertyChanged = OnDependencyPropertyChanged;
        }

        /// <summary>
        /// Enables property monitoring for a dependency object
        /// </summary>
        /// <param name="dependencyObject">The dependency object</param>
        public void AddValueChanged(DependencyObject dependencyObject)
        {
            _oldValue = dependencyObject.GetValue(_dependencyProperty);
            _descriptor.AddValueChanged(dependencyObject, OnValueChanged);
        }

        /// <summary>
        /// Disables property monitoring for a dependency object
        /// </summary>
        /// <param name="dependencyObject">The dependency object.</param>
        public void RemoveValueChanged(DependencyObject dependencyObject)
        {
            _descriptor.RemoveValueChanged(dependencyObject, OnValueChanged);
        }

        /// <summary>
        /// Called when value of dependency property has changed
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnValueChanged(object sender, EventArgs args)
        {
            if (_changeEventInProgress)
            {
                return;
            }

            _changeEventInProgress = true;

            object oldValue = _oldValue;
            _oldValue = (sender as DependencyObject).GetValue(_dependencyProperty);

            _onDependencyPropertyChanged(sender,
                new DependencyPropertyChangedEventArgs(_dependencyProperty,
                                                       oldValue,
                                                       _oldValue));

            _changeEventInProgress = false;
        }

        // Private members
        private DependencyPropertyChangedEventHandler _onDependencyPropertyChanged;
        private DependencyPropertyDescriptor _descriptor;
        private DependencyProperty _dependencyProperty;
        private bool _changeEventInProgress = false;
        private object _oldValue;
    }
}

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)


Written By
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

Comments and Discussions