How to implement IActiveAware on viewmodel

Docking/MDI for WPF Forum

Posted 12 years ago by Peter Schregle
Version: 11.2.0553
Avatar

I'm having trouble implementing IActiveAware on a viewmodel.

Is there any sample showing how to do this?

Thanks.

Peter

Comments (1)

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Peter,

Sorry, but we don't currently have any samples like that. Typically, the IActiveAware is implemented on the View, not the View Model. There is a bit of a discussion on this here. In some internal applications, we simply forward the IsActive setting from the View to the associated View Model, assuming it implements IActiveAware. Something like:

public class ViewBase : UserControl, IActiveAware {

	private bool isActive;

	public bool IsActive {
		get {
			return this.isActive;
		}
		set {
			if (this.isActive != value) {
				this.isActive = value;

				var viewModelActiveAware = this.DataContext as IActiveAware;
				if (viewModelActiveAware != null)
					viewModelActiveAware.IsActive = value;

				this.OnIsActiveChanged();
			}
		}
	}

	public event EventHandler IsActiveChanged;

	protected virtual void OnIsActiveChanged() {
		var handler = this.IsActiveChanged;
		if (handler != null)
			handler(this, EventArgs.Empty);
	}
}

But this could be wrapped into an attached behavior as well. 


Actipro Software Support

The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.