I'm having trouble implementing IActiveAware on a viewmodel.
Is there any sample showing how to do this?
Thanks.
Peter
I'm having trouble implementing IActiveAware on a viewmodel.
Is there any sample showing how to do this?
Thanks.
Peter
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.
Please log in to a validated account to post comments.