Propagate VisualElement.IsEnabled to children#12488
Conversation
src/Controls/src/Core/Internals/PropertyPropagationExtensions.cs
Outdated
Show resolved
Hide resolved
|
Will anyone approve it, because the bug is still here! |
|
Suggested changes: dev/is-enabled...dev/is-enabled-alt |
|
Very nice! Looking at that and will merge here |
|
Very excited for this :) |
| [EditorBrowsable(EditorBrowsableState.Never)] | ||
| set => SetValue(IsEnabledPropertyKey, value); | ||
| set => SetValue(IsEnabledProperty, value); |
There was a problem hiding this comment.
Bonus feature, this now works as a setter too!
| var ctx = self.GetContext(property); | ||
| if (ctx?.Binding is not null) | ||
| { | ||
| // support bound properties | ||
| if (!ctx.Attributes.HasFlag(BindableObject.BindableContextAttributes.IsBeingSet)) | ||
| ctx.Binding.Apply(false); | ||
| } |
There was a problem hiding this comment.
@StephaneDelcroix is this the correct way to ask a bindable property to "refresh" or "re-get" the value.
|
Which .NET 7 version is this fix expected in? |
|
How to get this update? |
|
Hi @mattleibow @PureWeen Please we need this update. Thank you |
|
@aidanjbailey @hosamyousof it seems like this bug is fixed in .NET 8 but won't be backported to .NET 7 |
|
Fair enough, thanks for the update. Looking forward to trading my 8 bindings for 1 haha. |
|
非常实用,期待更新 |
|
This seems to be fixed in my .NET 7 app actually, at least button visual states #9753 |
|
The plot thickens... |
|
Still its not working. Have to give separate binding for each item |
|
@Sofiya-kumar what version of maui and vs are you using? What platform? Maybe open a new issue and attach a repro so I can have a look. |
|
Hi @mattleibow , Please check the below repo Microsoft Visual Studio Professional 2022 Installed Version: Professional Visual C++ 2022 00476-80000-00000-AA061 ASP.NET and Web Tools 17.5.318.41597 Azure App Service Tools v3.0.0 17.5.318.41597 C# Tools 4.5.2-3.23171.7+d17f741546fad2786cbd6394d08619544e53a36d Extensibility Message Bus 1.4.3 (main@2a4517a) Microsoft JVM Debugger 1.0 Mono Debugging for Visual Studio 17.5.9 (11975e6) NuGet Package Manager 6.5.0 Razor (ASP.NET Core) 17.5.2.2316603+9f1b6856460af1e592d387ebef416eadddac453f Syntax Visualizer 1.0 TypeScript Tools 17.0.20105.2003 Visual Basic Tools 4.5.2-3.23171.7+d17f741546fad2786cbd6394d08619544e53a36d Visual F# Tools 17.5.0-beta.23053.5+794b7c259d9646a7eb685dad865aa27da7940a21 Visual Studio IntelliCode 2.2 VisualStudio.DeviceLog 1.0 VisualStudio.Mac 1.0 VSPackage Extension 1.0 Xamarin 17.5.0.173 (d17-5@33e727c) Xamarin Designer 17.5.3.46 (remotes/origin/d17-5@e4dd80b2bb) Xamarin Templates 17.5.41 (ba80d05) Xamarin.Android SDK 13.2.0.0 (d17-5/797e2e1) Xamarin.iOS and Xamarin.Mac SDK 16.2.0.5 (7738c90c9) |
Description of Change
There are several issues relating to the
IsEnabledproperty because it is a relatively complex property that involves parent state and combinations of other properties.Previous PRs:
This PR does a few things and tries to avoid major changes or new concepts.
IsEnabled
The main change to existing code is where previously if a command was "disabled" via the
CanExecutemethod, the framework would actually SET the value of theIsEnabledproperty - overwriting any user value. This causes issues if you have bothIsEnabledandCommandset.The new code rather takes advantage of the "coerce value" concept of the
BindablePropertyand "intercepts" the "user value" to make sure all the related properties are in agreement.Previously the
IButtonElementhad aIsEnabledCoreproperty that would be implemented to basically override user values when set - but that now is removed. The new version of that property is a getter-only and is virtual so that other elements can override.The final
IsEnabledvalue is now determined in the coerce value delegate of the property and is basically a check forIsEnabled = parent.IsEnabled && this.IsEnabledCore && userVlaue. Using the propagation system we already have, changing the parent element or the parent value triggers a re-evaluation of all the children - and thus consistency is preserved. Similarly, if theCanExecutevalue of a command is changed, then that also triggers a re-evaluation.The
IsEnabledproperty value is now propagated using the same system thatWindowandFlowDirectionuses:IPropertyPropagationController.PropagatePropertyChanged().Commands
Another (semi-related) change is to split the internal
IButtonElementintoICommandElementandIButtonElement : ICommandEleent. The reason for this is that commands can happen with non-button controls (such as search bar, tool bar and menu bar). This separation now allows the same code to be shared instead of copied - as can be seen by theSearchBarchanges.Tasks
Issues Fixed