【问题标题】:how to disable Application Bar Icon Button while processing other functions in windows phone application如何在处理 Windows Phone 应用程序中的其他功能时禁用应用程序栏图标按钮
【发布时间】:2017-02-26 01:22:12
【问题描述】:

reference

我有如下代码

private void btnSave_Click(object sender, EventArgs e){

(ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = false;

if (backstatus == false)
    {
    backstatus = true;
            myPopup.IsOpen = true;
            Dispatcher.BeginInvoke(delegate()
            {
        // some big code which take five minits to execute
    }
} }

在点击该按钮时,它处于启用模式。执行后将禁用该功能。

但我需要在处理其他功能时禁用它。

【问题讨论】:

  • 你能把场景说得清楚一点吗?
  • 当我点击保存按钮时,它需要一些时间来保存,而它正在加载我想要禁用的那个按钮,它是启用的。保存数据后,该按钮被禁用。但我想在加载时间之前禁用该按钮。

标签: c# xaml c#-4.0 windows-phone-8 windows-phone-8.1


【解决方案1】:

您可以使用 MVVM 方式并将视图模型中的命令绑定到应用程序栏按钮。或者,对长进程使用 await async 而不是 dispatcher.begininvoke()

【讨论】:

  • 我已经使用 MVVM 来实现该功能,
  • 我在 Dispatcher 中使用了 CustomerVM.SaveCustomer() 函数,该函数在 Customer View 模型类中实现
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多