我将 WPFProgressBar
的 Is indeterminate 设置为 True 并将 Visibility 设置为 Hidden。在事件处理程序中,我试图在ObservableCollection
更新 a 时使 ProgressBar 可见(以及 ListView ,其 ItemsSource 是ObservableCollection
)。我希望DoEvents(
) fromSystem.Windows.Forms.Application
可以使它可见,但事实并非如此。我注意到SetPBarHelper(() => { ..} )
通常比 ListView 显示视觉变化更早完成。
如何使ProgressBar
Visible 内部事件处理程序代码?
即使已完成添加项目,如何判断我ListView
的是否仍在更新?ObserableCollection
<ProgressBar x:Name="GeneralProgressBar" Width="300" Height="15" IsIndeterminate="True" Visibility="Hidden"/>
private void SetPBar(bool isVisible)
{
if (isVisible)
GeneralProgressBar.Visibility = System.Windows.Visibility.Visible;
else
GeneralProgressBar.Visibility = System.Windows.Visibility.Hidden;
}
private void SetPBarHelper(Action handler)
{
SetPBar(true); // try to make ProgressBar visible
System.Windows.Forms.Application.DoEvents();
handler(); // use the event handling, which run database query
SetPBar(false); // try to make ProgressBar disappear
}
private void CommandForumImagesBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
SetPBarHelper(() =>
{
if (e.Parameter == null)
return;
var vm = e.Parameter as ForumViewModel;
if (vm != null)
{
}
});
}
public sealed class ImageGroupCollection : ObservableCollection<ImageGroup>
{
public ImageGroupCollection() : base() { }
public void Update(DateTime start, DateTime end)
{
ClearItems();
var list = MyDatabase.GetRecords(start, end);
if (list != null)
{
foreach (var g in list)
{
Add(g);
}
}
}
}