dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.23k stars 1.76k forks source link

Android: Binding does not work when view is hidden #10109

Closed jbe2277 closed 9 months ago

jbe2277 commented 2 years ago

Description

On Android it seems that the Binding does not update the properties when the view is hidden. However, it works on Windows and it worked with Xamarin Forms 5 on Android as well.

Explanation: During navigation (async Task operation) the navigation item is shown as disabled (gray). After navigation has completed the NavigationItem.IsCommandEnabled is set back to true and via Binding the navigation items is shown as enabled again.

Issue on Android: maui-android-issue02

On Windows this works correct: maui-windows-works02

Steps to Reproduce

Link to public reproduction project repository

https://github.com/jbe2277/waf/tree/69803cef490970a344c370616021464f59ae201d

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12

Did you find any workaround?

No

Relevant log output

No response

PureWeen commented 2 years ago

if you add a color for "Isenabled=true" does that work?

  <Label Grid.RowSpan="2" Text="{Binding IconGlyph}" FontFamily="MaterialIcons" FontSize="22" VerticalOptions="Center" HorizontalOptions="Center">
                                <Label.Triggers>
                                    <DataTrigger TargetType="Label" Binding="{Binding IsCommandEnabled}" Value="False">
                                        <Setter Property="TextColor" Value="LightGray"/>
                                    </DataTrigger>
                                </Label.Triggers>
                            </Label>
ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

jbe2277 commented 2 years ago

@PureWeen : I have added an additional DataTrigger with color Red for true. This works. After navigation has completed it applies the color Red.

So it seems that it does not switch back to the default color when the DataTrigger condition changes to false. However, this issue is only on Android. Windows works correct.

<Label Grid.Column="1" Grid.Row="0" Text="{Binding Title}" Style="{StaticResource Subtitle}" VerticalOptions="Center">
    <Label.Triggers>
        <DataTrigger TargetType="Label" Binding="{Binding IsCommandEnabled}" Value="False">
            <Setter Property="TextColor" Value="LightGray"/>
        </DataTrigger>
        <DataTrigger TargetType="Label" Binding="{Binding IsCommandEnabled}" Value="True">
            <Setter Property="TextColor" Value="Red"/>
        </DataTrigger>
    </Label.Triggers>
</Label>
jbe2277 commented 1 year ago

Update: This issue still exists after update to .NET 7/MAUI 7.

Zhanglirong-Winnie commented 1 year ago

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 4.0. Can repro on Android platform with sample project. waf.zip Screenshot 2023-07-25 150911

WebGoose commented 1 year ago

Any update on this? I am also running into the same issue where values aren't updating on a control if it's not visible.

jbe2277 commented 9 months ago

✅ Seems that this issue got fixed. It does not occur anymore with MAUI 8.0.6.