Bladeren bron

ui update

Robert 3 jaren geleden
bovenliggende
commit
a7d46e7ea2
2 gewijzigde bestanden met toevoegingen van 46 en 11 verwijderingen
  1. 33 7
      Bellwether/Pages/ucFrontPage.xaml.cs
  2. 13 4
      Bellwether/UIComponent/RecAnimation.cs

+ 33 - 7
Bellwether/Pages/ucFrontPage.xaml.cs

@@ -16,6 +16,8 @@ using System.Windows.Media.Animation;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using System.Linq;
+using System.Globalization;
 
 namespace Bellwether.Pages
 {
@@ -88,15 +90,39 @@ namespace Bellwether.Pages
         {
             var solarInfo = GetSolarInfo();
 
-            uxCapacity.Text = solarInfo.Capacity.ToString();
+            if (solarInfo is null)
+            {
+                DisplayEmptySolarInfo();
+                return;
+            }
+            DisplaySolarInfo(solarInfo);
+        }
+
+        private void DisplayEmptySolarInfo()
+        {
+            const string emptyNumber = "---";
+            uxCapacity.Text = emptyNumber;
+
+            uxEnergy_Today.Text = emptyNumber;
+            uxCO2EmissionSaved_Today.Text = emptyNumber;
+            uxEquivalentTreesPlanted_Today.Text = emptyNumber;
+
+            uxEnergy_ThisYear.Text = emptyNumber;
+            uxCO2EmissionSaved_ThisYear.Text = emptyNumber;
+            uxEquivalentTreesPlanted_ThisYear.Text = emptyNumber;
+        }
+
+        private void DisplaySolarInfo(SolarInfoModel solarInfo)
+        {
+            uxCapacity.Text = solarInfo.Capacity.ToString("#,##0");
 
-            uxEnergy_Today.Text = solarInfo.Energy_Today.ToString();
-            uxCO2EmissionSaved_Today.Text = solarInfo.CO2EmissionSaved_Today.ToString("0.000");
-            uxEquivalentTreesPlanted_Today.Text = solarInfo.EquivalentTreesPlanted_Today.ToString("0.000");
+            uxEnergy_Today.Text = solarInfo.Energy_Today.ToString("#,##0");
+            uxCO2EmissionSaved_Today.Text = solarInfo.CO2EmissionSaved_Today.ToString("#,##0");
+            uxEquivalentTreesPlanted_Today.Text = solarInfo.EquivalentTreesPlanted_Today.ToString("#,##0");
 
-            uxEnergy_ThisYear.Text = solarInfo.Energy_ThisYear.ToString();
-            uxCO2EmissionSaved_ThisYear.Text = solarInfo.CO2EmissionSaved_ThisYear.ToString("0.000");
-            uxEquivalentTreesPlanted_ThisYear.Text = solarInfo.EquivalentTreesPlanted_ThisYear.ToString("0.000");
+            uxEnergy_ThisYear.Text = solarInfo.Energy_ThisYear.ToString("#,##0");
+            uxCO2EmissionSaved_ThisYear.Text = solarInfo.CO2EmissionSaved_ThisYear.ToString("#,##0");
+            uxEquivalentTreesPlanted_ThisYear.Text = solarInfo.EquivalentTreesPlanted_ThisYear.ToString("#,##0");
         }
 
         private void UpdateDateTimeInfo()

+ 13 - 4
Bellwether/UIComponent/RecAnimation.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.Threading.Tasks;
 using System.Timers;
 using System.Windows.Controls;
 using System.Windows.Media;
@@ -54,10 +55,18 @@ namespace Bellwether.UIComponent
             {
                 aniIndex = 0;
             }
-            Dispatcher.Invoke(() => {
-                //this.Source = bitmaps[aniIndex++];
-                this.Source = new BitmapImage(new Uri(sourceString));
-            });
+            try
+            {
+                Dispatcher.Invoke(() =>
+                {
+                    //this.Source = bitmaps[aniIndex++];
+                    this.Source = new BitmapImage(new Uri(sourceString));
+                });
+            }
+            catch(TaskCanceledException except)
+            {
+                
+            }
         }
     }
 }