2016-02-16 19 views
1

我有一個mahapps的問題,ShowProgressAsync方法顯示,但不顯示在底部加載粒料。我認爲這是一個問題,渲染保持同步。mahapps ShowProgressAsync不顯示加載程序異步 - WPF(C#)

任何人都可以給我一個解決方案嗎?我很難找到問題。

的XAML:

<controls:MetroWindow x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:local="clr-namespace:WpfApplication1" 
     mc:Ignorable="d" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <Button Content="Clicca" Width="150" Click="Button_Click" Height="50"></Button> 
    </Grid> 
</controls:MetroWindow> 

代碼隱藏:

using MahApps.Metro.Controls; 
using MahApps.Metro.Controls.Dialogs; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 

namespace WpfApplication1 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : MetroWindow 
    { 
     ProgressDialogController x; 
     public MainWindow() 
     { 
      InitializeComponent(); 
     } 

     private async void Button_Click(object sender, RoutedEventArgs e) 
     { 
      x = await this.ShowProgressAsync("test","loading", false) as ProgressDialogController; 
     } 
    } 
} 

他們應該站出來在出手的那流動的底部,但仍受阻

+0

我也有同樣的問題。即使在調用x.SetIndeterminate()時,不確定的欄也是不可見的。 – Beachwalker

回答

2

做你的意思是你想設置進度條爲不確定的?如果是這樣的話,你缺少一個方法調用右後ShowProgressAsync

private async void Button_Click(object sender, RoutedEventArgs e) 
    { 
     x = await this.ShowProgressAsync("test", "loading", false) as ProgressDialogController; 
     x.SetIndeterminate(); 
    } 

如果你想要的是顯示實際的進展,你應該使用X的方法SetProgress報告與價值觀的進步從0到1.

0

,我一直在使用來bookend異步操作的某些代碼是這樣的......

var x = await this.ShowProgressAsync("Please wait", "Doing Something..."); 
// Your Code Here. 
await x.CloseAsync().ConfigureAwait(false); 

如果你只是希望它的出現例如1秒,那麼你用...

var x = await this.ShowProgressAsync("Please wait", "Waiting for 1 second."); 
await Task.Delay(1000); 
await x.CloseAsync().ConfigureAwait(false); 
0

你的工作代碼不應該阻止用戶界面線程,以便讓ProgressWindow顯示

var controller = await this.ShowProgressAsync("Please wait", "Doing Something..."); 
// Your code here 
await controller.CloseAsync(); 

,如果你的代碼將阻止用戶界面線程,它包裝到一個新任務中

var controller = await this.ShowProgressAsync("Please wait", "Doing Something...") 
await Task.Run(() => 
{ 
    // Your code here 
} 
await controller.CloseAsync();