How can I be notified when something is hidden ?

May 12, 2009 at 2:33 PM

hi,

this question may seems stupid, but I can't find a way to capture an event when a DockableContent (document or floatingWindow) is hidden. There is no dedicated event and PropertyChanged is not raised because State is a dependencyProperty... Is there a way to capture a modification in a dependencyProperty or something else to do ?

Thanks.

 

Jul 22, 2009 at 7:53 AM

Hi,

I've been having trouble with this aswell. I solved it by using the following code in DockableContent.cs perhaps it is something that could be useful to put in?

Its simply an event for when the DockableContent.State gets changed, the following is put at the top of DockableContent.cs

 

/// <summary>Event arguments for the <see cref="StateChangedEventArgs"/></summary>
public class StateChangedEventArgs : EventArgs
{
    /// <summary>Initialise the event args specifying the old and new <see cref="DockableContentState"/></summary>
    /// <param name="oldState">The old state of the <see cref="DockableContent"/></param>
    /// <param name="newState">The new state of the <see cref="DockableContent"/></param>
    public StateChangedEventArgs(DockableContentState oldState, DockableContentState newState)
    {
        OldState = oldState;
        NewState = newState;
    }

    /// <summary>Gets the old state the <see cref="DockableContent"/> changing states had</summary>
    public DockableContentState OldState { get; private set; }

    /// <summary>Gets the new state the <see cref="DockableContent"/> changing states had</summary>
    public DockableContentState NewState { get; private set; }
}

/// <summary>Handler signature of the <see cref="DockableContent.StateChanged"/> event</summary>
/// <param name="sender">The <see cref="DockableContent"/> signaling the change</param>
/// <param name="args">Arguments for the change</param>
public delegate void StateChangedEventHandler(object sender, StateChangedEventArgs args);

 

And this final bit replaces the DockableContent.State declaration

/// <summary>Event invoked when the <see cref="State"/> property is changed</summary>
public event StateChangedEventHandler StateChanged;

public DockableContentState State
{
    get { return (DockableContentState)GetValue(StatePropertyKey.DependencyProperty); }
    protected set 
    { 
        // Save old value (used for event)
        DockableContentState oldValue = State;

        // Ignore setting of value if no change is being made
        if(oldValue == value)
            return;

        // Set the value
        SetValue(StatePropertyKey, value); 

        // Invoke property change event
        if(StateChanged != null)
            StateChanged(this, new StateChangedEventArgs(oldValue, value));
    }
}


Except for some tweaks, this is a great lib, keep up the good work!