`

禁用按钮是要在整个事件结束后才会响应(转载)

 
阅读更多
禁用按钮是要在整个事件结束后才会响应
public class WpfApplication
    {
        private static DispatcherOperationCallback exitFrameCallback = new DispatcherOperationCallback(ExitFrame);
 
        public static void DoEvents()
        {
            DispatcherFrame nestedFrame = new DispatcherFrame();
            DispatcherOperation exitOperation = Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, exitFrameCallback, nestedFrame);
 
            Dispatcher.PushFrame(nestedFrame);
            if (exitOperation.Status != DispatcherOperationStatus.Completed)
            {
                exitOperation.Abort();
            }
        }
 
        private static Object ExitFrame(Object state)
        {
            DispatcherFrame frame = state as DispatcherFrame;
            frame.Continue = false;
            return null;
        }
    }




private void button_Click(object sender, RoutedEventArgs e)
        {
            button.IsEnabled = false;
            WpfApplication.DoEvents();
            i++;
            button.Content = i.ToString();
            System.Threading.Thread.Sleep(2000);
            button.IsEnabled = true;
        }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics