Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
fix flowpanel handle null children and safe number animations
Greedeks3c3ca4f1930d
diff --git a/.Source/GTweak/Assets/UserControls/FlowPanel.cs b/.Source/GTweak/Assets/UserControls/FlowPanel.csindex 64e266c5..d26d3ab1 100644--- a/.Source/GTweak/Assets/UserControls/FlowPanel.cs+++ b/.Source/GTweak/Assets/UserControls/FlowPanel.cs@@ -120,17 +120,29 @@ namespace GTweak.Assets.UserControlsif (EqualizeItemSize){Size constraint = new Size(ItemWidth, double.PositiveInfinity);- foreach (UIElement child in visible)+ for (int i = 0; i < visible.Count; i++){- child?.Measure(constraint);+ UIElement child = visible[i];++ if (child != null)+ {+ try { child.Measure(constraint); }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }+ }}}else{Size constraint = new Size(double.PositiveInfinity, double.PositiveInfinity);- foreach (UIElement child in visible)+ for (int i = 0; i < visible.Count; i++){- child?.Measure(constraint);+ UIElement child = visible[i];++ if (child != null)+ {+ try { child.Measure(constraint); }+ catch (Exception ex) { ErrorLogging.LogDebug(ex); }+ }}}@@ -469,7 +481,8 @@ namespace GTweak.Assets.UserControlsfor (int columnCount = maxPossibleColumns; columnCount >= 1; columnCount--){List<FlowItemGroup> columns = TryDistributeToColumns(columnCount, availableHeight, visibleChildren);- if (columns != null && CalculateTotalWidth(columns) <= availableWidth && columns.Count > 0)++ if (columns != null && columns.Count > 0 && CalculateTotalWidth(columns) <= availableWidth){return columns;}diff --git a/.Source/GTweak/Utilities/Animation/NumberAnimation.cs b/.Source/GTweak/Utilities/Animation/NumberAnimation.csindex 111b0755..983c2a50 100644--- a/.Source/GTweak/Utilities/Animation/NumberAnimation.cs+++ b/.Source/GTweak/Utilities/Animation/NumberAnimation.cs@@ -7,13 +7,14 @@ namespace GTweak.Utilities.Animation{internal static class NumberAnimation{- internal static readonly DependencyProperty ValueProperty = DependencyProperty.RegisterAttached("Value", typeof(int), typeof(NumberAnimation), new PropertyMetadata(0, OnValueChanged));+ internal static readonly DependencyProperty ValueProperty =+ DependencyProperty.RegisterAttached("Value", typeof(int), typeof(NumberAnimation), new PropertyMetadata(0, OnValueChanged));- private static readonly DependencyProperty AnimatedValueProperty = DependencyProperty.RegisterAttached("AnimatedValue", typeof(int), typeof(NumberAnimation), new PropertyMetadata(0, OnAnimatedValueChanged));+ private static readonly DependencyProperty AnimatedValueProperty =+ DependencyProperty.RegisterAttached("AnimatedValue", typeof(int), typeof(NumberAnimation), new PropertyMetadata(0, OnAnimatedValueChanged));internal static void SetValue(DependencyObject dObject, int value) => dObject?.SetValue(ValueProperty, value);-- internal static int GetValue(DependencyObject dObject) => dObject?.GetValue(ValueProperty) as int? ?? 0;+ internal static int GetValue(DependencyObject dObject) => (int)(dObject?.GetValue(ValueProperty) ?? 0);private static void SetAnimatedValue(DependencyObject dObject, int value) => dObject?.SetValue(AnimatedValueProperty, value);@@ -21,25 +22,32 @@ namespace GTweak.Utilities.Animation{if (dObject is TextBlock textBlock){- int newValue = (e.NewValue as int?) ?? 0;+ int newValue = e.NewValue is int val ? val : 0;+ int oldValue = e.OldValue is int old ? old : 0;- if (!textBlock.IsLoaded)+ if (newValue != oldValue || !textBlock.IsLoaded){- SetAnimatedValue(textBlock, newValue);- return;+ if (!textBlock.IsLoaded)+ {+ textBlock.BeginAnimation(AnimatedValueProperty, null);+ SetAnimatedValue(textBlock, newValue);+ return;+ }++ try+ {+ Int32Animation int32Anim = new Int32Animation+ {+ From = oldValue,+ To = newValue,+ Duration = TimeSpan.FromSeconds(0.5),+ EasingFunction = new QuadraticEase { EasingMode = EasingMode.EaseOut }+ };+ Timeline.SetDesiredFrameRate(int32Anim, 60);+ textBlock.BeginAnimation(AnimatedValueProperty, int32Anim);+ }+ catch { SetAnimatedValue(textBlock, newValue); }}-- int oldValue = (e.OldValue as int?) ?? 0;-- Int32Animation int32Anim = new Int32Animation- {- From = oldValue,- To = newValue,- Duration = TimeSpan.FromSeconds(0.5),- EasingFunction = new QuadraticEase { EasingMode = EasingMode.EaseOut }- };- Timeline.SetDesiredFrameRate(int32Anim, 60);- textBlock.BeginAnimation(AnimatedValueProperty, int32Anim);}}@@ -47,8 +55,8 @@ namespace GTweak.Utilities.Animation{if (dObject is TextBlock textBlock){- textBlock.Text = string.Format(" {0}", e.NewValue?.ToString() ?? string.Empty);+ textBlock.Text = $" {(int)(e.NewValue ?? 0)}";}}}-}+}\ No newline at end of filediff --git a/.Source/GTweak/Utilities/Managers/NotificationManager.cs b/.Source/GTweak/Utilities/Managers/NotificationManager.csindex ab4f28be..e4e9d0f4 100644--- a/.Source/GTweak/Utilities/Managers/NotificationManager.cs+++ b/.Source/GTweak/Utilities/Managers/NotificationManager.cs@@ -29,7 +29,7 @@ namespace GTweak.Utilities.Managers["TglButton12"] = NoticeAction.Logout,["TglButton20"] = NoticeAction.Restart,["TglButton22"] = NoticeAction.Logout,- ["TglButton23"] = NoticeAction.Restart,+ ["TglButton23"] = NoticeAction.Restart};internal static readonly Dictionary<string, NoticeAction> SysActions = new Dictionary<string, NoticeAction>()