diff --git a/Terminal.Gui/App/CWP/CWPPropertyHelper.cs b/Terminal.Gui/App/CWP/CWPPropertyHelper.cs
index cfe7d68a0..2ea94ce97 100644
--- a/Terminal.Gui/App/CWP/CWPPropertyHelper.cs
+++ b/Terminal.Gui/App/CWP/CWPPropertyHelper.cs
@@ -22,7 +22,10 @@ public static class CWPPropertyHelper
/// The type of the property value, which may be a nullable reference type (e.g.,
/// ?).
///
- /// The current property value, which may be null for nullable types.
+ ///
+ /// Reference to the current property value, which may be null for nullable types. If the change is not cancelled, this
+ /// will be set to .
+ ///
/// The proposed new property value, which may be null for nullable types.
/// The virtual method invoked before the change, returning true to cancel.
/// The pre-change event raised to allow modification or cancellation.
@@ -52,9 +55,9 @@ public static class CWPPropertyHelper
///
///
public static bool ChangeProperty (
- T currentValue,
+ ref T currentValue,
T newValue,
- Func, bool> onChanging,
+ Func, bool>? onChanging,
EventHandler>? changingEvent,
Action doWork,
Action>? onChanged,
@@ -70,13 +73,17 @@ public static class CWPPropertyHelper
}
ValueChangingEventArgs args = new (currentValue, newValue);
- bool cancelled = onChanging (args) || args.Handled;
- if (cancelled)
+ if (onChanging is { })
{
- finalValue = currentValue;
+ bool cancelled = onChanging (args) || args.Handled;
- return false;
+ if (cancelled)
+ {
+ finalValue = currentValue;
+
+ return false;
+ }
}
changingEvent?.Invoke (null, args);
@@ -100,6 +107,7 @@ public static class CWPPropertyHelper
doWork (finalValue);
ValueChangedEventArgs changedArgs = new (currentValue, finalValue);
+ currentValue = finalValue;
onChanged?.Invoke (changedArgs);
changedEvent?.Invoke (null, changedArgs);
diff --git a/Terminal.Gui/ViewBase/View.Drawing.Scheme.cs b/Terminal.Gui/ViewBase/View.Drawing.Scheme.cs
index 876e14fca..dcd28794b 100644
--- a/Terminal.Gui/ViewBase/View.Drawing.Scheme.cs
+++ b/Terminal.Gui/ViewBase/View.Drawing.Scheme.cs
@@ -26,7 +26,7 @@ public partial class View
set
{
CWPPropertyHelper.ChangeProperty (
- _schemeName,
+ ref _schemeName,
value,
OnSchemeNameChanging,
SchemeNameChanging,
@@ -209,7 +209,7 @@ public partial class View
public bool SetScheme (Scheme? scheme)
{
return CWPPropertyHelper.ChangeProperty (
- _scheme,
+ ref _scheme,
scheme,
OnSettingScheme,
SchemeChanging,
diff --git a/Terminal.Gui/ViewBase/View.Layout.cs b/Terminal.Gui/ViewBase/View.Layout.cs
index b12e2b78c..2f5a4660c 100644
--- a/Terminal.Gui/ViewBase/View.Layout.cs
+++ b/Terminal.Gui/ViewBase/View.Layout.cs
@@ -328,7 +328,7 @@ public partial class View // Layout APIs
set
{
CWPPropertyHelper.ChangeProperty (
- _height,
+ ref _height,
value,
OnHeightChanging,
HeightChanging,
@@ -416,7 +416,7 @@ public partial class View // Layout APIs
set
{
CWPPropertyHelper.ChangeProperty (
- _width,
+ ref _width,
value,
OnWidthChanging,
WidthChanging,