Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 选中和取消选中动画需要时间_C#_Wpf_Data Binding - Fatal编程技术网

C# 选中和取消选中动画需要时间

C# 选中和取消选中动画需要时间,c#,wpf,data-binding,C#,Wpf,Data Binding,当用户单击复选框时,复选框会在3秒钟后被选中,因为LoadShowGuidData()方法正在加载大量数据,我正在ShowGuid()方法中使用“this.dispatcher.BeginInvoke()”调用该方法,但该方法对解决问题无效我想要的是,用户单击后应立即选中复选框,然后加载数据。 XAML代码: UserControl的ViewModel: public ICommand ShowGuidCommand { 得到 { 返回新的ControlCommand(this.Sh

当用户单击复选框时,复选框会在3秒钟后被选中,因为LoadShowGuidData()方法正在加载大量数据,我正在ShowGuid()方法中使用“this.dispatcher.BeginInvoke()”调用该方法,但该方法对解决问题无效我想要的是,用户单击后应立即选中复选框,然后加载数据。

  • XAML代码:

  • UserControl的ViewModel:
public ICommand ShowGuidCommand
{
得到
{
返回新的ControlCommand(this.ShowGuid,null);
}
}
public void ShowGuid(对象变量)
{
string errMsg=string.Empty;
尝试
{
如果(!this.DataLayerLocal.CheckManagerRunning())
{
返回;
}
this.dispatcher.BeginInvoke(新操作(()=>
this.LoadShowGuidData(this.ShowGuidIsChecked));
}
捕获(自定义异常cex)
{
如果(!string.IsNullOrEmpty(errMsg))
{
DisplayMessageBox(errMsg,Properties.Resources.ControlsCaption);
}
}           
}
公共无效加载ShowGuidData(布尔复选框状态)
{
Mouse.OverrideCursor=游标。等待;
string errMsg=string.Empty;
尝试
{               
this.varValues=this.DataLayerLocal.GetVariablesInformation(this.ProcedurePath,
checkBoxStatus?1:0,out errMsg);
这个.NewLineRemover();
this.VariableList=this.varValues;
this.Sort();
}
捕获(自定义异常cex)
{
如果(!string.IsNullOrEmpty(errMsg))
{
DisplayMessageBox(errMsg,Properties.Resources.ControlsCaption);
}
}
最后
{
Mouse.OverrideCursor=null;
}
}

您可能应该考虑异步方法,这样您的事件可以继续进行,同时加载数据。@AnantJain:为什么要调用
BeginInvoke
?该命令在UI线程上调用。您应该使用
Task.Run
在后台线程上执行
LoadShowGuidData
。这就是我想知道如何在此场景中使用Task的原因。我使用BeginInvoke只是为了表明它没有如问题中所述工作。
 <DockPanel Margin="2">
     <CheckBox Content="{x:Static p:Resources.checkBoxShowGUID}" Margin="2,0" 
     IsChecked="{Binding ShowGuidIsChecked,IsAsync=True,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  
     Command="{Binding ShowGuidCommand}" HorizontalAlignment="Right" VerticalContentAlignment="Center"/>
 </DockPanel>
        public ICommand ShowGuidCommand
        {
            get
            {
                return new ControlCommand<object>(this.ShowGuid, null);
            }
        }

        public void ShowGuid(object variable)
        {
            string errMsg = string.Empty;

            try
            {
                if (!this.DataLayerLocal.CheckManagerRunning())
                {
                    return;
                }

                this.dispatcher.BeginInvoke(new Action(() => 
                this.LoadShowGuidData(this.ShowGuidIsChecked)));

            }
            catch (CustomException cex)
            {
                if (!string.IsNullOrEmpty(errMsg))
                {
                    DisplayMessageBox(errMsg, Properties.Resources.ControlsCaption);
                }
            }           
        }

        public void LoadShowGuidData(bool checkBoxStatus)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            string errMsg = string.Empty;
            try
            {               
                this.varValues = this.DataLayerLocal.GetVariablesInformation(this.ProcedurePath, 
                checkBoxStatus ? 1 : 0, out errMsg);
                this.NewLineRemover();
                this.VariableList = this.varValues;
                this.Sort();
            }
            catch (CustomException cex)
            {
                if (!string.IsNullOrEmpty(errMsg))
                {
                    DisplayMessageBox(errMsg, Properties.Resources.ControlsCaption);
                }
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }