Xamarin.forms: [Bug]XAML binding behaviour changed V4.1->V4.2

Created on 4 Sep 2019  路  9Comments  路  Source: xamarin/Xamarin.Forms

Description

See attached project to reproduce the problem:
With Xamarin.Forms V4.2.0.709249, the XAML binding behaviour changed when using
<StackLayout x:Name="stacklayout" Orientation="Vertical" IsEnabled="{Binding IsDataInputEnabled}">
and
<x1:ColorSelectorControl BindingContext="{Binding ColorSelector1}" IsEnabled="{Binding Source={x:Reference stacklayout},Path=IsEnabled}" />

When "IsDataInputEnabled" is initial set to false, starting with V4.2 the button inside the color picker control is not shown (gray) as disabled. This works with V4.1

Please try with the attached project.
BindingProblem01.zip

Steps to Reproduce

  1. Build project with reference to Xamarin.Forms V4.2.0.709249
  2. Start UWP app, the color picker control is disabled, but the button inside is not shown as disabled (grey)
  3. Toggle the switch and the control and the button inside is correctly dis/enabled
  4. Build project with reference to Xamarin.Forms 4.1.0.709244
  5. Start UWP app, the color picker control is disabled, and the button inside is shown as disabled (grey), that's OK.

Reproduction Link


BindingProblem01.zip

bug

All 9 comments

most likely a dupe of #7286 or #7097, should be fixed by #7356. regression caused by #7040

verify that this is actually fixed by #7356 before closing.

@sude22 I'm having trouble getting this to build. It doesn't recognize the MVVM Light library. Can you please confirm that it's set up properly? Thanks!

@samhouts you could try to remove the mvvmlight nuget package and and add it again, that should work.

@sude22 I think you're supposed to use MvvmLightLibsStd10 for netstandard libraries

Also the netstandard CSPROJ file has a hard reference to a local dll which might be why you are seeing different behavior then we are when running this project

@PureWeen you are right, I removed the hard reference and added MVVMLightLibsStd10, now it should work, sorry.

BindingProblem01.zip

Just updated the BindingProblem01 project to the 4.2.0 Service Release 1 (4.2.0.778463), but the problem still occures.
I thought it might be fixed with #7356 because this bug was referenced in #7286

So, what's going on here, is not a binding issue, as the Button is actually disabled (you can't click on it), but it's not greyed out. It's actually the IsEnabled property competing with the Command property for setting the enabled state. IsEnabled sets it based on your binding, and the Command checks the CanExecute property of the command.

The fact that the button is not clickable even though it's not grayed out, is because the containing StackLayout is disabled, so none of the components inside are clickable.

The difference in behavior between 4.1. and 4.2 are due to the order in which the bindings are resolved, and you shouldn't rely on that.

So, I'm closing this. You shouldn't use both the Command and the IsEnabled property of a Button is the take away from this. I'm sure you'll be able to fix your issue by rearchitecting your color selector control.

@StephaneDelcroix OK, thank you for that hint. I will have a look at it.

@StephaneDelcroix: I really missed that Button -> Command -> IsEnabled dilemma. Thank you again, I will redesign the control to be en/disabled via viewmodel.

Was this page helpful?
0 / 5 - 0 ratings