MahApps Progress Ring not showing up when Refreshing data

71 Views Asked by At

I'm trying to show a progress spinner when I hit a refresh to get new data in a table. The spinner appears for like a second but the task takes about like a solid 10 seconds. I want the spinner to show for that ten seconds. The spinner does show up but appears and disappears within a second. I'm just lost and probably over looking something that I'm not understanding. I'm using MahhApps: ProgressSpinner, WPF, and .NET 4.7.2. Code as follows:

MainView.xaml


<mahapps:MetroWindow
    x:Class="TFEmployeeTrainingTracker.View.MainView"
    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:local="clr-namespace:TFEmployeeTrainingTracker.View"
    xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="Employee Training Tracker"
    Width="800"
    Height="450"
    BorderThickness="0"
    DataContext="{Binding MainScreen, Source={StaticResource Locator}}"
    GlowBrush="Black"
    Icon="/Asset/Business-Man.ico"
    ResizeMode="CanResizeWithGrip"
    ShowIconOnTitleBar="True"
    WindowStartupLocation="CenterScreen"
    WindowState="Maximized"
    WindowStyle="None"
    WindowTransitionsEnabled="False"
    mc:Ignorable="d">
    <DockPanel>
        <Ribbon
            x:Name="MainRibbon"
            DockPanel.Dock="Top"
            IsEnabled="{Binding MenuEnabled}"
            SelectedIndex="0">
            <Ribbon.ApplicationMenu>
                <RibbonApplicationMenu Visibility="Collapsed" />
            </Ribbon.ApplicationMenu>
            <RibbonTab Header="Home" KeyTip="H">
                <RibbonGroup x:Name="SiteGroup" Header="Site">
                    <!-- <RibbonButton Some Ribbon Button /> -->
                </RibbonGroup>
                <RibbonGroup x:Name="DataGroup" Header="Data">
                    <!-- <RibbonButton Some Ribbon Button /> -->
                    <RibbonButton
                        Command="{Binding RefreshDataCmd}"
                        KeyTip="R"
                        Label="Refresh"
                        SmallImageSource="/Asset/Image/Command-Refresh.png" />
                </RibbonGroup>
                
            </RibbonTab>
        </Ribbon>
        <mahapps:ProgressRing
            Grid.Row="5"
            Grid.Column="1"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            IsActive="{Binding IsProgressRingActive}" />
    </DockPanel>
</mahapps:MetroWindow>

MainViewModel.cs


public async Task RefreshData()
{
    //My idea was to add a spinner for the main view when hitting a refresh
    //Sadly it does not show
    //this.IsProgressRingActive = true;

    DataFileParser parser = new DataFileParser();
    await Task.Run(() => parser.ParseDataFile(Global.DataFileName)); 
    await parser.UpdateData();
    if (CurrentView.GetType() == typeof(DataViewModel))
    {

        await ServiceLocator.Current.GetInstance<DataViewModel>().LoadData();
    }

    //this.IsProgressRingActive = false;
}

Which in turn the above code will call this method in this file:

DataViewModel.cs


public async Task LoadData()
{
    // This is the original spinner that would appear for like a second
    // When it takes like 10 seconds to get the data
    this.IsDataProgressRingActive = true;

    DataCollection.Clear();
    IEnumerable<DataModel> datas = (await this.dataRepo.GetData(Global.ActiveSite, false,false)).OrderBy(f => f.dataID);
    foreach (DataModel data in datas )
    {
        DataCollection.Add(data);
    }
    this.IsDataProgressRingActive = false;
}

I tried to be generic as possible. I hope this made sense.

0

There are 0 best solutions below