我正在动态添加网格,每个网格都有一些控件。当进程开始添加网格时,需要几秒钟。为了缩短这个加载时间,我已经附加了一个加载器,但它没有工作。
这是我的代码:
loader.Visibility = Visibility.Visible;
loader.IsEnabled = true;
btnBack.Visibility = Visibility.Hidden;
SetDownArrow();
Application.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Background,
new Action(() => DoTimeConsumingWork())
);
答案 0 :(得分:0)
以下代码为我工作
private void ExecuteCommand(object obj)
{
LabelVisibility = Visibility.Visible;
Application.Current.Dispatcher.Invoke((Action)(() => { }), DispatcherPriority.Render);
//// Do your code here
LabelVisibility = Visibility.Collapsed;
}