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] [iOS] Cannot find SwipeView object with x:Name #15194

Closed misve0411 closed 2 years ago

misve0411 commented 2 years ago

Description

Even though I have a name on my SwipeView tag, I cannot reach it in backend code. Nor can I get intellisense in backend code for all objects inside SwipeView tags! If I set a name on any tag outside the SwipeView tags, I instantly can see the name in backend code but not if, for instance a label tag, is located between SwipeView start and end tag.

Steps to Reproduce

  1. Add "x:Name" to a SwipeView tag ( )
  2. Go to backend code ( .xaml.cs ) and write "swipeView".
  3. <?xml version="1.0" encoding="UTF-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:ff="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms" xmlns:iOsSpecific="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" xmlns:pancake="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView" iOsSpecific:Page.ModalPresentationStyle="OverFullScreen" iOsSpecific:Page.UseSafeArea="False" x:Class="QuTIP.Views.BottomSheet.BottomSheet" BackgroundColor="Transparent" x:Name="BottomSheetInstance">

Expected Behavior

I should be able to write for example "swipeView.Close()" in the backend code

Actual Behavior

I get a red line underneath and the name is not presented/recognised with the help of intellisense.

Basic Information

Environment

Show/Hide Visual Studio info ``` === Visual Studio Community 2019 for Mac === Version 8.10.19 (build 2) GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638) Package version: 612000162 === Mono Framework MDK === Runtime: Mono 6.12.0.162 (2020-02/2ca650f1f62) (64-bit) Package version: 612000162 === Roslyn (Language Service) === 4.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb === NuGet === Version: 5.9.0.7134 === .NET SDK (x64) === SDK: /usr/local/share/dotnet/sdk/5.0.405/Sdks SDK Versions: 5.0.405 5.0.404 5.0.403 5.0.402 5.0.401 3.1.416 3.1.415 3.1.414 3.1.413 MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks === .NET Core Runtime === Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 5.0.14 5.0.13 5.0.12 5.0.11 5.0.10 3.1.22 3.1.21 3.1.20 3.1.19 === .NET Core 3.1 SDK === SDK: 3.1.416 === .NET 5.0 SDK === SDK: 5.0.405 === Xamarin.Profiler === Version: 1.6.15.68 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler === Updater === Version: 11 === Apple Developer Tools === Xcode 13.2.1 (19586) Build 13C100 === Xamarin.Mac === Version: 8.6.0.3 (Visual Studio Community) Hash: caa899d24 Branch: d17-1 Build date: 2022-01-16 21:16:56-0500 === Xamarin.iOS === Version: 15.6.0.3 (Visual Studio Community) Hash: caa899d24 Branch: d17-1 Build date: 2022-01-16 21:16:56-0500 === Xamarin Designer === Version: 16.11.0.60 Hash: 56f9b80b0 Branch: remotes/origin/d16-11 Build date: 2021-12-15 02:44:16 UTC === Xamarin.Android === Version: 12.0.0.3 (Visual Studio Community) Commit: xamarin-android/d16-11/f0e3c2d SDK Tools Version: 26.1.1 SDK Platform Tools Version: 30.0.4 SDK Build Tools Version: 30.0.2 Build Information: Mono: c633fe9 Java.Interop: xamarin/java.interop/d16-11@476bb5b ProGuard: Guardsquare/proguard/v7.0.1@912d149 SQLite: xamarin/sqlite/3.35.4@85460d3 Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-11@87af37b === Eclipse Temurin JDK === Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home 1.8.0.302 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL === Android SDK Manager === Version: 16.10.0.13 Hash: 1b81df5 Branch: remotes/origin/d16-10 Build date: 2021-11-12 01:17:32 UTC === Android Device Manager === Version: 16.10.0.15 Hash: 89dcc0b Branch: remotes/origin/d16-10 Build date: 2021-11-12 01:17:52 UTC === Build Information === Release ID: 810190002 Git revision: 632b6ca654e2733a685bfc9c6a0686e0a317092b Build date: 2022-02-09 13:38:14-05 Build branch: release-8.10 === Operating System === Mac OS X 12.2.1 Darwin 21.3.0 Darwin Kernel Version 21.3.0 Wed Jan 5 21:37:58 PST 2022 root:xnu-8019.80.24~20/RELEASE_X86_64 x86_64 === Enabled user installed extensions === MFractor 4.4.10 ```

Build Logs

Screenshots

Reproduction Link

Workaround

jfversluis commented 2 years ago

You're using it in a DataTemplate which isn't a concrete instance. If you want to do something with that SwipeView you probably want to use data binding. Also see: https://www.youtube.com/watch?v=Or_qn8i8jVM&list=PLfbOp004UaYWOuVUuEtGlpkDIC1houhn_&index=1

misve0411 commented 2 years ago

Ok. Thank you for quick answer, now I know what messes things up!

My core problem is that I swipe left to reveal a "Delete" button and there are three events that triggers on that: SwipeStarted, SwipeChanging and SwipeEnded but neither of these events triggers when I swipe to close the "Delete" button again. So I thought I had to find another way to see if it is open or not and one way of to doing this is to get the SwipeView object in code behind and look at the property "IsOpen" but sadly I cannot get hold on the object as I described above.

I do have a tap event to close it in code behind and can set a status parameter (swipeDeleteOpen = false) but I need this also to be done when I swipe it to close. How can I solve this?