Reputation: 3417
I have a problem with mahapps , the ShowProgressAsync method is displayed but does not show the loading pellets in the bottom . I think it is a problem that the rendering remains synchronous .
Can anyone give me a solution ? I struggle to find the problem .
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>
Codebehind:
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;
}
}
}
They should come out in the bottom of the shot that flow, but remain blocked
Upvotes: 1
Views: 4183
Reputation: 812
Your Working Code should not block the UI thread in order to let the ProgressWindow to display
var controller = await this.ShowProgressAsync("Please wait", "Doing Something...");
// Your code here
await controller.CloseAsync();
if your code will block the UI Thread, wrap it inside a new task
var controller = await this.ShowProgressAsync("Please wait", "Doing Something...")
await Task.Run(() =>
{
// Your code here
}
await controller.CloseAsync();
Upvotes: 1
Reputation: 15
Some code that I've been using to bookend async operations is this...
var x = await this.ShowProgressAsync("Please wait", "Doing Something...");
// Your Code Here.
await x.CloseAsync().ConfigureAwait(false);
If you just want it to appear for say 1 second, then you use...
var x = await this.ShowProgressAsync("Please wait", "Waiting for 1 second.");
await Task.Delay(1000);
await x.CloseAsync().ConfigureAwait(false);
Upvotes: 0
Reputation: 125
Do you mean that you want to set the progressbar as indeterminate? If that's the case, you are missing a method call right after the ShowProgressAsync
private async void Button_Click(object sender, RoutedEventArgs e)
{
x = await this.ShowProgressAsync("test", "loading", false) as ProgressDialogController;
x.SetIndeterminate();
}
If what you want is to show the actual progress, you should use the method SetProgress
of x to report the progress with values from 0 to 1.
Upvotes: 2