|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Threading;
using System.Windows.Threading;
namespace ObjectPresentation
{
public class SuspendedButton : Button
{
#region SuspendTime
public TimeSpan SuspendTime
{
get { return (TimeSpan)GetValue(SuspendTimeProperty); }
set { SetValue(SuspendTimeProperty, value); }
}
public static readonly DependencyProperty SuspendTimeProperty =
DependencyProperty.Register("SuspendTime", typeof(TimeSpan), typeof(SuspendedButton), new UIPropertyMetadata(TimeSpan.Zero));
#endregion
#region BeforeClick
public static readonly RoutedEvent BeforeClickEvent = EventManager.RegisterRoutedEvent(
"BeforeClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SuspendedButton));
public event RoutedEventHandler MethodResultShown
{
add { AddHandler(BeforeClickEvent, value); }
remove { RemoveHandler(BeforeClickEvent, value); }
}
#endregion
protected override void OnClick()
{
RaiseEvent(new RoutedEventArgs(SuspendedButton.BeforeClickEvent));
TimeSpan time = SuspendTime;
ThreadPool.QueueUserWorkItem(new WaitCallback(o =>
{
Thread.Sleep(time);
Dispatcher.BeginInvoke(DispatcherPriority.Normal,
new ThreadStart(() =>
{
base.OnClick();
}));
}));
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.