我有一个ListView ,其中包含许多要在搜索中加载的项目。 我想为用户提供更丰富的用户界面,以便在加载时, 我会显示一个旋转圆圈(从AJAX等待中获知) 。
我意识到我必须进入Threads或其他东西,但是因为我以前从未在WPF中做过这些,所以我确信在WPF(或简单的BackgroundWorker)中有比Threads更好的东西。
无论如何,关键是在加载时显示该动画。 任何想法? 谢谢!
I Have a ListView with many Items that is to be loaded in search. And I'd like to provide user the richer user interface so that when loading, I'd display a rotating circle (known from AJAX waiting).
I realize that I'll have to go into Threads or something, but as I've never done this before in WPF, I'm sure there is something better than Threads in WPF (or a simpe BackgroundWorker).
Anyways, the point is to display that animation while loading. Any idea? Thanks!
最满意答案
好的,我现在有了一个有效的解决方案。
我有一个包含该动画的UserControl 。 它位于我的XAML代码中的某个位置,如下所示: <customControls:LoadingAnimation x:Name="LoadingAnimation" /> 。 通过调用neede加载此控件
LoadingAnimation.Show();现在当我点击一个Button来完成耗时的工作时,在我调用BeginInvoke()之前,我加载了这个动画。
然后,当努力工作完成后,我调用LoadingAnimation.Hide(). 很简单! 我为其他人添加代码:
private void SearchClick(object sender, RoutedEventArgs e) { LoadingAnimation.Show(); new StringDelegate(DoSearch).BeginInvoke("TextToSearch", null, null); } private void DoSearch(string searchText) { object result = /* Do the time consuming work */ Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ResultDelagate(UpdateUserInterface), result); } private void UpdateUserInterface(object result) { LoadingAnimation.Hide(); DataContext = result as /* what you want */; }OK I've got a working solution now.
I have a UserControl that contains that animation. It is located somewhere in my XAML code like this: <customControls:LoadingAnimation x:Name="LoadingAnimation" />. This control is loaded when neede by calling
LoadingAnimation.Show();Now when I click on a Button to do the time-consuming work, before I call BeginInvoke() I load that animation.
Then when the hard work is finished I call LoadingAnimation.Hide(). Very simple! I add code for the others:
private void SearchClick(object sender, RoutedEventArgs e) { LoadingAnimation.Show(); new StringDelegate(DoSearch).BeginInvoke("TextToSearch", null, null); } private void DoSearch(string searchText) { object result = /* Do the time consuming work */ Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ResultDelagate(UpdateUserInterface), result); } private void UpdateUserInterface(object result) { LoadingAnimation.Hide(); DataContext = result as /* what you want */; }更多推荐
Threads,WPF,电脑培训,计算机培训,IT培训"/> <meta name="description"
发布评论