xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] Invisible BindableLayout when modified off screen #13607

Open AndyNetDuma opened 3 years ago

AndyNetDuma commented 3 years ago

Description

When modifying a BindableView's collection if it is not visible it will remain invisible until the data is update again.

Steps to Reproduce

  1. Load attacked project
  2. Toggle checkbox (just bound to BindableView IsVisible) to hide the checkbox
  3. Click regenerate data (just sets the data to a new collection)
  4. Toggle the checkbox again to see a missing list
  5. Optionally click regenerate data again to see the list reappear

Expected Behavior

List doesn't disappear

Actual Behavior

List disappears

Basic Information

Environment

Show/Hide Visual Studio info ``` Microsoft Visual Studio Professional 2019 Version 16.8.4 VisualStudio.16.Release/16.8.4+30907.101 Microsoft .NET Framework Version 4.8.03752 Installed Version: Professional Visual C++ 2019 00435-60000-00000-AA199 Microsoft Visual C++ 2019 ASP.NET and Web Tools 2019 16.8.557.25636 ASP.NET and Web Tools 2019 ASP.NET Core Razor Language Services 16.1.0.2052803+84e121f1403378489b842e1797df2f3f5a49ac3c Provides languages services for ASP.NET Core Razor. ASP.NET Web Frameworks and Tools 2019 16.8.557.25636 For additional information, visit https://www.asp.net/ Azure App Service Tools v3.0.0 16.8.557.25636 Azure App Service Tools v3.0.0 Azure Functions and Web Jobs Tools 16.8.557.25636 Azure Functions and Web Jobs Tools C# Tools 3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30924.1 Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE. Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Microsoft Library Manager 2.1.113+g422d40002e.RR Install client-side libraries easily to any web project Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container. Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package Mono Debugging for Visual Studio 16.8.43 (00471f8) Support for debugging Mono processes with Visual Studio. NuGet Package Manager 5.8.1 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ Productivity Power Tools 2017/2019 16.0 Installs the individual extensions of Productivity Power Tools 2017/2019 ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info SQL Server Data Tools 16.0.62012.31170 Microsoft SQL Server Data Tools TypeScript Tools 16.0.21016.2001 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 16.8.0-beta.20507.4+da6be68280c89131cdba2045525b80890401defd Microsoft Visual F# Tools Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio Visual Studio Container Tools Extensions 1.0 View, manage, and diagnose containers within Visual Studio. Visual Studio Spell Check Everywhere VSSpellCheckEverywhere An extension that enables spell checking within any Visual Studio file editor or tool window that uses WPF text boxes. https://GitHub.com/EWSoftware/VSSpellChecker Visual Studio Spell Checker VSSpellChecker An editor extension that checks the spelling of comments, strings, and plain text as you type or interactively with tool windows. https://GitHub.com/EWSoftware/VSSpellChecker Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Foo 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio Xamarin 16.8.000.261 (d16-8@bb99248) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 16.8.0.507 (remotes/origin/d16-8@e87b24884) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 16.8.112 (86385a3) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 11.1.0.26 (d16-8/a36ce73) Xamarin.Android Reference Assemblies and MSBuild support. Mono: 5e9cb6d Java.Interop: xamarin/java.interop/d16-8@79d9533 ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000 SQLite: xamarin/sqlite/3.32.1@1a3276b Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc Xamarin.iOS and Xamarin.Mac SDK 14.8.0.3 (c51fabee8) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```

Build Logs

Screenshots

Reproduction Link

InvisibleBindableLayout.zip

Workaround

Manually reassign the list when it becomes visible. Tedious to do in every instance.

AndyNetDuma commented 3 years ago

I should say this issues is blocking our next release from using xamarin 5.0 however we also depend on a feature introduced in 5.0 (menu visibility) so we are essentially blocked from releasing until this is resolved

rachelkang commented 3 years ago

Hi, @AndyNetDuma - thanks for submitting this issue! Would you mind sharing what version of XF you observed the different behavior you expected? I tried running your sample on XF 4.8 and observed the same behavior.

It seems to me that the actual behavior matches the expected behavior here - the CheckBox IsChecked property and StackLayout IsVisible property are both set to the same RadioChecked binding.

AndyNetDuma commented 3 years ago

I checked older versions with the sample and you are right, it is broken as far back as I tested, 4.5, however in our app the issue is only present on 5.0 and above.

In our app we initially noticed this when changing page. Imagine the list is on page 1 and the button to regenerate is on page 2. In reality we aren't actually setting IsVisible so it's always visible. If you regenerate the data on page 2 then go back to page 1 the list is invisible. After honing in on the issue we noticed it was easiest to replicate with the IsVisible property.

So in reality I suspect this issue only cropped up in 5.0 because some internal change now tracks page visibility the same way as an elements IsVisible. This causes the issue to be ever present for us and anyone using an MVC pattern as data is often modified in the model and the view is notified of the change.

It seems to me that the actual behavior matches the expected behavior here - the CheckBox IsChecked property and StackLayout IsVisible property are both set to the same RadioChecked binding.

I don't understand how this is expected behaviour. I suspect you misunderstood the issue. You should be able to modify the data in the background and the visibility of the list should be unrelated. Obviously I would expect the checkbox's IsChecked to match the IsVisible property of the list. The issue is when it is checked, with data in the list, the list isn't visible. See the pic for an example. image

rmarinho commented 3 years ago

Yap i can confirm this issue. when the itemsource changes when IsVisible is false it keeps of items to show when IsVisible is rue

ish-1313 commented 3 years ago

seems to hit the same when bindablelayout is in invisible state collection update is not processed correctly

xaml

 <Grid RowDefinitions="Auto,Auto, Auto, *" ColumnDefinitions="*,*" BindingContext="{Binding ., Source={x:Reference thisPage}}">
        <Button Text="Fill data" x:Name="btFill" Clicked="btFill_Clicked" />
        <Button Grid.Column="1" Text="Clear data" x:Name="btClear" Clicked="btClear_Clicked" />
        <Button Grid.Row="1" Text="Reset ItemSource" x:Name="btReset" Clicked="btReset_Clicked" />
        <RadioButton Grid.Row="2" Content="Visible" GroupName="radio" IsChecked="{Binding MakeVisible}" />
        <RadioButton Grid.Row="2" Grid.Column="1" Content="Invisible" GroupName="radio" />
        <StackLayout Grid.Row="3" Grid.ColumnSpan="2" IsVisible="{Binding MakeVisible}" BindableLayout.ItemsSource="{Binding Data}">
            <BindableLayout.ItemTemplate>
                <DataTemplate>
                    <Frame BorderColor="Black">
                    <Grid ColumnDefinitions="*,*">
                        <Label Text="{Binding FieldA}"/>
                        <Label Text="{Binding FieldB}" Grid.Column="1" />
                    </Grid>
                    </Frame>
                </DataTemplate>
            </BindableLayout.ItemTemplate>
        </StackLayout>
    </Grid>

code to fill collection and remove couple of items

      private void btFill_Clicked(object sender, EventArgs e)
        {
            Data = new ObservableCollection<SampleData>();
            for (int i = 0; i < 5; i++)
            {
                Data.Add(new SampleData($"field a #{i}", $"field b #{i}"));
            }
        }

        private void btClear_Clicked(object sender, EventArgs e)
        {
            _data.RemoveAt(0);
            _data.RemoveAt(1);

        }

изображение

screenshot after clicking clear when stacklayout in invisible state

as a possible workaround - resetting itemsource data after switching to visible state forces correct redraw

   private void btReset_Clicked(object sender, EventArgs e)
        {
            var _saved = _data;
            Data = null;
            Data = _saved;
        }

изображение

ish-1313 commented 3 years ago

after playing more with my sample project I found, that this problem occurs only if vertical option for stack layout is fill or fillandexpand. setting vertical option to anything but these cure the problem with bindablelayout redraw on invisible changed to true

richardwoollcott commented 3 years ago

We are also experiencing this problem or a similar one, the problem is on Android only. Version 4.8.0.1821 worked fine, upgrading to version 5.0.0.2012 or 5.0.01874 causes blank items to be displayed. We are using ReactiveUI and DynamicData's SourceCache connected to a ReadOnlyObservableCollection bound to a StackLayout via BindableLayout.ItemsSource.

We are using Native.Forms to host Xamarin.Forms Content Pages. We have tabbed pages using Fragments to host each Xamarin.Forms ContentPage.

We use a RefreshView, to reproduce pull to refresh and switch to another tabbed page. Stay on that page until the data has loaded and return to the original page. This will be displaying blank items instead of the visuals defined in the ItemTemplate.

The workaround described above to disconnect the ItemsSource works but is visually unappealing and we have put a lot of effort into ensuring the application loads and refreshes smoothly. We would like to upgrade the app to Xamarin.Forms 5 to take advantage of support and on-going bug fixes but can't really do this until this problem is fixed.

Changing the VerticalOptions of the StackLayout doesn't make any difference.

I have spent some time trying to reproduce the problem in a sample app but haven't succeeded yet - it is quite a complex setup.

We would appreciate it if you can look into this, thanks.

cropped_empty_items

IcySnex commented 1 year ago

Are there any updates on this?

bondarenkod commented 1 year ago

I thought I was doing something wrong. Spend a few hours trying to play with XAML related to BindableLayout.ItemsSource.

Should google first!

I found a workaround that works for me.

image