【问题标题】:How to use busy indicator in wpf如何在 wpf 中使用忙碌指示器
【发布时间】:2015-11-28 05:01:58
【问题描述】:

我在框架内的页面需要一些时间才能加载,这意味着控件首次出现在页面上需要一些时间。我应该在我的主 window.cs 文件中的哪个位置设置 IsBusy = true。我不知道如何使用忙碌指示器。我应该何时将其切换为 true 或 false。请指导我应该如何使用它?提前致谢。

【问题讨论】:

    标签: wpf wpftoolkit busyindicator


    【解决方案1】:

    通常,您会在开始执行大量繁重处理之前设置繁忙指示器,这取决于您的代码。

    它通常会在您生成后台线程以执行大量工作之前让 UI 说它现在很忙,当线程完成时“不忙” UI。

    【讨论】:

      【解决方案2】:

      用忙碌指示符包裹你Xaml。假设您使用的是MVVM

        <xctk:BusyIndicator BusyContent="{Binding BusyText}" IsBusy="{Binding IsBusy}">
          <Grid>
             <!--Your controls and content here-->
          </Grid>
      </xctk:BusyIndicator>
      

      在你的viewmodel

          /// <summary>
          /// To handle the Busy Indicator's state to busy or not
          /// </summary>
          private bool _isBusy;
          public bool IsBusy
          {
              get
              {
                  return _isBusy;
              }
              set
              {
                  _isBusy = value;
                  RaisePropertyChanged(() => IsBusy);
              }
          }
      
          private string _busyText;
          //Busy Text Content
          public string BusyText
          {
              get { return _busyText; }
              set
              {
                  _busyText = value;
                  RaisePropertyChanged(() => BusyText);
              }
          }
      

      命令和命令处理程序

          //A Command action that can bind to a button
          private RelayCommand _myCommand;
          public RelayCommand MyCommand
          {
              get
              {
                  return _myCommand??
                         (_myCommand= new RelayCommand(async () => await CommandHandler(), CanExecuteBoolean));
              }
          }
      
      internal async Task CommandHandler()
          {
             Isbusy = true;
             BusyText = "Loading Something...";
             Thread.Sleep(3000); // Do your operation over here
             Isbusy = false;
          }
      

      【讨论】:

        猜你喜欢
        • 2011-05-20
        • 1970-01-01
        • 2017-05-25
        • 2014-10-04
        • 2011-09-11
        • 2018-11-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多