CheckBox проверка и снятие отметки анимации занимает много времени - PullRequest
0 голосов
/ 02 марта 2020

Когда пользователь нажимает на флажок, флажок проверяется через 3 секунды из-за того, что загружается большой объем данных методом LoadShowGuidData (), который я вызываю внутри метода ShowGuid (), используя this.dispatcher.BeginInvoke (), который не эффективно решить проблему. флажок должен быть отмечен сразу после нажатия пользователем, а затем данные должны быть загружены.

  • XAML-код:
 <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>
  • ViewModel из UserControl:
        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;
            }
        }
...