Skip to content

Instantly share code, notes, and snippets.

@kokudori
Created March 22, 2015 00:19
Show Gist options
  • Save kokudori/ec8cfa127b96a6c3906c to your computer and use it in GitHub Desktop.
Save kokudori/ec8cfa127b96a6c3906c to your computer and use it in GitHub Desktop.
TriggerAction後のCanCloseの変化に対応したLivetのWindowCloseCancelBehavior
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