Created
March 22, 2015 00:19
-
-
Save kokudori/ec8cfa127b96a6c3906c to your computer and use it in GitHub Desktop.
TriggerAction後のCanCloseの変化に対応したLivetのWindowCloseCancelBehavior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel; | |
using Livet.Behaviors; | |
namespace Sample.Behaviors | |
{ | |
sealed class WindowClosingCancelBehavior : WindowCloseCancelBehavior | |
{ | |
CancelEventArgs cancel; | |
readonly DependencyPropertyDescriptor descriptor; | |
public WindowClosingCancelBehavior() | |
{ | |
descriptor = DependencyPropertyDescriptor.FromProperty(CanCloseProperty, typeof(WindowCloseCancelBehavior)); | |
} | |
protected override void OnAttached() | |
{ | |
AssociatedObject.Closing += (sender, e) => | |
{ | |
if (cancel == null) | |
descriptor.AddValueChanged(this, (self, _) => cancel.Cancel = !CanClose); | |
cancel = e; | |
}; | |
base.OnAttached(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment