xamarin / Xamarin.Forms

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

[Bug] Image get resized randomly when app goes to background #14150

Open scarrier92 opened 3 years ago

scarrier92 commented 3 years ago

Description

When I first launch my app the images in my menu get render with a height of 26. But if I leave the app to go to another app, the image size changes and when I comme back my menu gets very ugly Images width and height go to 32 .

Steps to Reproduce

  1. Xaml MenPage:
    <StackLayout VerticalOptions="FillAndExpand" Focused="StackLayout_Focused">
        <ListView x:Name="ListViewMenu"
                    HasUnevenRows="True">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid Padding="10">
                            <Label Text="{Binding Title}"  FontSize="20" TextColor="{DynamicResource foreground}"/>
                            <Image x:Name="img" Source="{local:ImageResource ApplicationCalcul.Views.General.icons8-lock-96.png}"    IsVisible="{Binding IsLock}" HorizontalOptions="End" VerticalOptions="Start"  SizeChanged="img_SizeChanged">
                            </Image>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout> 
  2. Start app
  3. img_SizeChanged gets called, image are size 26 and looks good
  4. Click round button on IPhone to go to main page
  5. img_SizeChanged gets called, image are size 32 and looks good
  6. Go back to app
  7. Open menu (the image are way too big for no reason

Expected Behavior

I would expect the same Xaml to be rendered the sameway independantly of the app is open for the first time or the second one

Actual Behavior

The menu is rendered correctly at first and when you exit and comme back to the app the rendering as changed

Basic Information

Environment

Show/Hide Visual Studio info ``` Microsoft Visual Studio Community 2019 Version 16.9.3 VisualStudio.16.Release/16.9.3+31129.286 Microsoft .NET Framework Version 4.8.04084 Version installée : Community Visual C++ 2019 00435-60000-00000-AA191 Microsoft Visual C++ 2019 Adaptateur de test pour Boost.Test 1.0 Permet d'utiliser les outils de test de Visual Studio avec des tests unitaires écrits pour Boost.Test. Les conditions d'utilisation et les mentions tierces sont disponibles dans le répertoire d'installation de l'extension. Adaptateur de test pour Google Test 1.0 Active l'utilisation des outils de test de Visual Studio avec les tests unitaires écrits pour Google Test. Les conditions d'utilisation et les notifications tierces sont disponibles dans le répertoire d'installation de l'extension. ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools ASA Service Provider 1.0 ASP.NET and Web Tools 2019 16.9.693.2781 ASP.NET and Web Tools 2019 ASP.NET Core Razor Language Services 16.1.0.2112521+5741df381174d72f08e3632bb99f52e8635b6a1a Provides languages services for ASP.NET Core Razor. ASP.NET Web Frameworks and Tools 2019 16.9.693.2781 Pour plus d'informations, visitez https://www.asp.net/ Assistants Microsoft Visual C++ 1.0 Assistants Microsoft Visual C++ Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer. Azure Data Lake Tools for Visual Studio 2.6.1000.0 Microsoft Azure Data Lake Tools for Visual Studio Azure Functions and Web Jobs Tools 16.9.693.2781 Azure Functions and Web Jobs Tools Azure Stream Analytics Tools for Visual Studio 2.6.1000.0 Microsoft Azure Stream Analytics Tools for Visual Studio Common Azure Tools 1.10 Fournit des services courants utilisables par Microsoft Azure Mobile Services et Microsoft Azure Tools. Cookiecutter 16.9.21026.1 Fournit des outils pour rechercher, instancier et personnaliser des modèles au format cookiecutter. Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. Extension IntelliCode 1.0 Informations détaillées sur l'extension Visual Studio IntelliCode Extensions des outils de conteneur Visual Studio 1.0 Affichez, gérez et diagnostiquez les conteneurs dans Visual Studio. Fabric.DiagnosticEvents 1.0 Événements de diagnostic Fabric Gestionnaire de package NuGet 5.9.0 Gestionnaire de package NuGet dans Visual Studio. Pour plus d'informations sur NuGet, visitez https://docs.nuget.org/ Microsoft Azure HDInsight Azure Node 2.6.1000.0 HDInsight Node under Azure Node Microsoft Azure Hive Query Language Service 2.6.1000.0 Language service for Hive query Microsoft Azure Service Fabric Tools pour Visual Studio 16.0 Microsoft Azure Service Fabric Tools pour Visual Studio Microsoft Azure Stream Analytics Language Service 2.6.1000.0 Language service for Azure Stream Analytics Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node Microsoft Azure Tools 2.9 Microsoft Azure Tools pour Microsoft Visual Studio 2019 - v2.9.40218.1 Microsoft Continuous Delivery Tools pour Visual Studio 0.4 Simplification de la configuration des pipelines Azure DevOps à partir de l'IDE Visual Studio. Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers Mono Debugging for Visual Studio 16.9.7 (df23ba6) Support for debugging Mono processes with Visual Studio. Outils Azure App Service v3.0.0 16.9.693.2781 Outils Azure App Service v3.0.0 Outils C# 3.9.0-6.21160.10+59eedc33d35754759994155ea2f4e1012a9951e3 Composants C# utilisés dans l'IDE. Selon votre type de projet et vos paramètres, une version différente du compilateur peut être utilisée. Outils de développement Office pour Visual Studio 16.0.30502.00 Outils de développement Microsoft Office pour Visual Studio Outils TypeScript 16.0.30201.2001 Outils TypeScript pour Microsoft Visual Studio Outils Visual Basic 3.9.0-6.21160.10+59eedc33d35754759994155ea2f4e1012a9951e3 Composants Visual Basic utilisés dans l'IDE. Selon votre type de projet et vos paramètres, une version différente du compilateur peut être utilisée. Package hôte de l'adaptateur de débogage de Visual Studio Code 1.0 Couche d'interopérabilité pour l'hébergement d'adaptateurs de débogage Visual Studio Code dans Visual Studio Package Microsoft Visual Studio VC 1.0 Package Microsoft Visual Studio VC ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info Python 16.9.21026.1 Fournit IntelliSense, des projets, des modèles, le débogage, des fenêtres interactives et du support pour les développeurs Python. Python - Prise en charge Django 16.9.21026.1 Fournit des modèles et une intégration pour le framework web Django. Python - Prise en charge du profilage 16.9.21026.1 Prise en charge du profilage pour les projets Python. Python - Prise en charge IronPython 16.9.21026.1 Fournit des modèles et une intégration pour les projets basés sur IronPython. Python - Prise en charge de Conda 16.9.21026.1 Prise en charge de Conda pour les projets Python. ResXManager ResXManager Manage localization of all ResX-Based resources in one place. Shows all resources of a solution and let's you edit the strings and their localizations in a well-arranged data grid. SQL Server Data Tools 16.0.62103.10080 Microsoft SQL Server Data Tools ToolWindowHostedEditor 1.0 Hosting json editor into a tool window Visual F# Tools 16.9.0-beta.21102.9+7ce7132f1459095e635194d09d6f73265352029a Microsoft Visual F# Tools Visual Studio Tools pour CMake 1.0 Visual Studio Tools pour CMake Visual Studio Tools pour Conteneurs 1.0 Visual Studio Tools pour Conteneurs Visual Studio Tools pour Docker 1.1 Développez, exécutez et validez vos applications ASP.NET Core dans l'environnement cible. Appuyez sur F5 pour exécuter votre application directement dans un conteneur avec débogage ou sur CTRL+F5 pour modifier et actualiser votre application sans avoir à recréer le conteneur. Visual Studio Tools pour Kubernetes 1.0 Visual Studio Tools pour Kubernetes VisualStudio.DeviceLog 1.0 Informations sur mon paquet VisualStudio.Mac 1.0 Mac Extension for Visual Studio Workflow Manager Tools 1.0 1.0 Ce package contient les composants d’intégration Visual Studio nécessaires pour Workflow Manager. Xamarin 16.9.000.273 (d16-9@1bba9e0) Extension Visual Studio permettant de développer pour Xamarin.iOS et Xamarin.Android. Xamarin Designer 16.9.0.316 (remotes/origin/d16-9@fdbf64026) Extension Visual Studio pour activer les outils Xamarin Designer dans Visual Studio. Xamarin Templates 16.9.68 (8e9b569) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 11.2.2.1 (d16-9/877f572) Xamarin.Android Reference Assemblies and MSBuild support. Mono: 5e9cb6d Java.Interop: xamarin/java.interop/d16-9@54f8c24 ProGuard: Guardsquare/proguard/v7.0.1@912d149 SQLite: xamarin/sqlite/3.34.1@daff8f4 Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-9@d210f11 Xamarin.iOS and Xamarin.Mac SDK 14.14.2.5 (3836759d4) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```

Build Logs

Screenshots

First launch image

Aftex exiting app and comming back: image

Reproduction Link

Workaround

Specify a widthrequest in xaml

rachelkang commented 3 years ago

Hi, @scarrier92 - thanks for submitting this issue. Do you have any code that's influencing the size of any of your views? And what code do you have inside your img_SizeChanged function? If you can share your project or a sample project reproducing the issue, that would be super helpful!

Generally speaking, I recommend you check out https://github.com/Redth/ResizetizerNT/ to combat any image issues you're facing

scarrier92 commented 3 years ago

There was only a breakpoint in img_SizeChanged this is how I know that the width request changes when someone leaves the app.