• WPF ScrollViewer嵌套的DataGrid、ListBox等控件的鼠标滚动事件无效,子控件拦截父控件滚动效果解决办法


    注册子控件的PreviewMouseWheel,然后在滚动的时候设置控件的 IsHitTestVisible = false,因为这个参数设为false之后子控件里面的TextBox,CheckBox会失效,所以在停止滚动后要把参数设回来。代码如下

     private void girdOrder_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
            {
                RetryUtil.TimeOutAction(200, () =>
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        this.IsHitTestVisible = false;
                    });
                },
                () =>
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        this.IsHitTestVisible = true;
                    });
    
                });
            }

    下面是TimeOutAction的代码片

    /// <summary>
            /// 
            /// </summary>
            /// <param name="TS">超时等待时长ms</param>
            /// <param name="OnAction">执行任务</param>
            /// <param name="TimeAction">超时处理任务</param>
            public static void TimeOutAction(int TS, Action OnAction, Action TimeAction)
            {
                CancellationTokenSource cts = new CancellationTokenSource(TS);
                cts.Token.Register(() =>
                {//等待设置时间后执行
                    TimeAction();
                });
                Task.Factory.StartNew(() =>
                {//立即执行
                    while (!cts.Token.IsCancellationRequested)
                    {
                        OnAction();
                        Task.Delay(TS).Wait();
                    }
                }, cts.Token);
            }
  • 相关阅读:
    asp.net 自定义文本框
    单机运行k8s以及e2e
    编译k8s1.3的代码
    etcd的简单使用
    How Tencent Tests Software
    ps引发的血案
    配置IDE查看kubernetes源码
    读书笔记<<不懂带人,你就自己干到死>>
    书摘<<互联网世界观>>
    读书笔记《异类》
  • 原文地址:https://www.cnblogs.com/siazon/p/13445856.html
Copyright © 2020-2023  润新知