Forum Xamarin Xamarin.Forms

iOS App crashing when binding to Text & IsVisible

BenJones.3507BenJones.3507 USMember ✭✭

I'm having issues with binding in iOS. We have numerous forms in our app and they're broadly set out as per the example with an Entry and an associated label for validation feedback - we're using FluentValidation for this. The label is hidden unless there are errors to show, this is so they take up no space on the interace when not required.

<Entry x:Name="UsernameEntry" 
    Placeholder="{Binding UILabelLoginName}"
    IsTextPredictionEnabled="False"
    PlaceholderColor="#333333"
    TextColor="#000000" 
    ReturnType="Done"
        Text="{Binding LoginName.Value}"
        InputTransparent="False">
    <Entry.Behaviors>
        <behaviors:EventToCommandBehavior
            Command="{Binding ClearValidationCommand}"
            CommandParameter="LoginName"
            EventName="Focused" />
    </Entry.Behaviors>
</Entry>

<Label
    IsVisible="{Binding LoginName.IsValid, Converter={StaticResource InverseBoolean}}"
    Style="{StaticResource ErrorLabelStyle}"
        Text="{Binding LoginName.FirstError}" />

This works lovely in Android, in iOS though the binding to IsVisible crashes the app. If we set IsVisible to true as opposed to binding it and set a fixed HeightRequest then it works fine but I don't want empty labels taking up space within the forms.

Android - On Load

Android - On Error

iOS - On Load (IsVisible set to Binding)

iOS - On Error (IsVisible set to Binding)

  • Crash

iOS - On Load (IsVisible set to True)

iOS - On Error (IsVisible set to True)

The exception at the time of the crash is,

Object reference not set to an instance of an object

at Xamarin.Forms.Platform.iOS.VisualElementTracker.UpdateClip () [0x00072] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:413
at Xamarin.Forms.Platform.iOS.VisualElementTracker.UpdateNativeControl () [0x0006c] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:386
at Xamarin.Forms.Platform.iOS.VisualElementTracker.HandlePropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00064] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:97
at (wrapper delegate-invoke) .invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:229
at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:353
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:461
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:397
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x00042] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:334
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindablePropertyKey propertyKey, System.Object value) [0x0000e] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:318
at Xamarin.Forms.VisualElement.set_Height (System.Double value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:324
at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x0001a] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1081
at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:316
at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:708
at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:178
at Xamarin.Forms.TemplatedView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00019] in D:\a\1\s\Xamarin.Forms.Core\TemplatedView.cs:29
at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:812
at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1083
at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:316
at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:708
at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.View child, Xamarin.Forms.Rectangle region, Xamarin.Forms.SizeRequest childSizeRequest) [0x00225] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:319
at Xamarin.Forms.StackLayout.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00081] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:65
at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:812
at Xamarin.Forms.Layout.ResolveLayoutChanges () [0x0005c] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:392
at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/Foundation/NSAction.cs:152
--- End of stack trace from previous location where exception was thrown ---

at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/UIKit/UIApplication.cs:65
at xxxx.iOS.Application.Main (System.String[] args) [0x00002] in C:\xxxx\xxxx.iOS\Main.cs:19

Any guidance would be very much appreciated!

Thanks

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    If hardcode to set the property won't throw crash, it may be caused by your converter.
    Sometimes you will get a null value in your converter so we need to use an if statement to exclude this condition:

    if (value != null)
    {
    
    }
    

    And if the cast in the converter fails, it will crash too. Please check the code in the converter.
    If the issue persists, try to post a small sample here to help us reproduce it.

  • BenJones.3507BenJones.3507 USMember ✭✭

    @LandLu said:
    If hardcode to set the property won't throw crash, it may be caused by your converter.
    Sometimes you will get a null value in your converter so we need to use an if statement to exclude this condition:

    if (value != null)
    {
    
    }
    

    And if the cast in the converter fails, it will crash too. Please check the code in the converter.
    If the issue persists, try to post a small sample here to help us reproduce it.

    Thanks for that, unfortunately my converter already catches null values;

    public class InverseBooleanConverter : IValueConverter
        {
            #region IValueConverter Members
    
            public object Convert(object value, Type targetType, object parameter,
                System.Globalization.CultureInfo culture)
            {
                if (value != null)
                {
                    if (targetType != typeof(bool))
                        throw new InvalidOperationException("The target must be a boolean");
    
                    return !(bool)value;
                }
    
                return false;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter,
                System.Globalization.CultureInfo culture)
            {
                throw new NotSupportedException();
            }
    
            #endregion
        }
    

    I've attached the debugger and stepped through just to be sure and value is always true/false and never null.

  • LandLuLandLu Member, Xamarin Team Xamurai

    Could you please provide a repo here?
    I need it to do some investigation.

  • BenJones.3507BenJones.3507 USMember ✭✭

    @LandLu said:
    Could you please provide a repo here?
    I need it to do some investigation.

    Hi, I'm unable to share it on a public forum, can I share it privately with you?

  • LinnKristinLinnKristin NOUniversity ✭✭

    I´m having more or less the same issues, but I´m using Rg.Plugins.Popup. My problem is "fixed" if I set the popup to be very small (so that the the popup is fitting within the left over space when the keyboard is showing). Must be something with the resizing. First I got it with a isvisible true/false too, but removing that alone in my case was not enough for not crashing.

    System.NullReferenceException: Object reference not set to an instance of an object
    at Xamarin.Forms.Platform.iOS.VisualElementTracker.UpdateClip () [0x00072] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:413
    at Xamarin.Forms.Platform.iOS.VisualElementTracker.UpdateNativeControl () [0x0006c] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:386
    at Xamarin.Forms.Platform.iOS.VisualElementTracker.HandlePropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00064] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:97
    at (wrapper delegate-invoke) .invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
    at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:229
    at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:353
    at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:461
    at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:397
    at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x00042] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:334
    at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindablePropertyKey propertyKey, System.Object value) [0x0000e] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:318
    at Xamarin.Forms.VisualElement.set_Height (System.Double value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:324
    at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x0001a] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1081
    at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:316
    at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:708
    at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:178
    at Xamarin.Forms.TemplatedView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00019] in D:\a\1\s\Xamarin.Forms.Core\TemplatedView.cs:29
    at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
    at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
    at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:812
    at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1083
    at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:316
    at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:708
    at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:178
    2020-07-06 13:36:04.676 CornerStone.iOS[371:16901]
    at Xamarin.Forms.Page.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0010d] in D:\a\1\s\Xamarin.Forms.Core\Page.cs:278
    at Rg.Plugins.Popup.Pages.PopupPage.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x000ff] in C:\Users\mhvdi\Documents\OpenSource\Rg.Plugins.Popup\Rg.Plugins.Popup\Pages\PopupPage.cs:196
    at Xamarin.Forms.Page.UpdateChildrenLayout () [0x000ca] in D:\a\1\s\Xamarin.Forms.Core\Page.cs:357
    at Xamarin.Forms.Page.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Page.cs:337
    at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:812
    at Xamarin.Forms.Page.ForceLayout () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Page.cs:245
    at Rg.Plugins.Popup.Pages.PopupPage.OnPropertyChanged (System.String propertyName) [0x00059] in C:\Users\mhvdi\Documents\OpenSource\Rg.Plugins.Popup\Rg.Plugins.Popup\Pages\PopupPage.cs:142
    at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:461
    at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:397
    at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x00042] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:334
    at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:311
    at Rg.Plugins.Popup.Pages.PopupPage.set_SystemPadding (Xamarin.Forms.Thickness value) [0x00000] in C:\Users\mhvdi\Documents\OpenSource\Rg.Plugins.Popup\Rg.Plugins.Popup\Pages\PopupPage.cs:79
    at Rg.Plugins.Popup.IOS.Extensions.PlatformExtension.UpdateSize (Rg.Plugins.Popup.IOS.Renderers.PopupPageRenderer renderer) [0x00102] in C:\Users\mhvdi\Documents\OpenSource\Rg.Plugins.Popup\Rg.Plugins.Popup\Platforms\Ios\Extensions\PlatformExtension.cs:71
    at Rg.Plugins.Popup.IOS.Renderers.PopupPageRenderer.ViewDidLayoutSubviews () [0x00006] in C:\Users\mhvdi\Documents\OpenSource\Rg.Plugins.Popup\Rg.Plugins.Popup\Platforms\Ios\Renderers\PopupPageRenderer.cs:108
    at Rg.Plugins.Popup.IOS.Renderers.PopupPageRenderer.KeyBoardUpNotification (Foundation.NSNotification notifi) [0x0000c] in C:\Users\mhvdi\Documents\OpenSource\Rg.Plugins.Popup\Rg.Plugins.Popup\Platforms\Ios\Renderers\PopupPageRenderer.cs:131
    at Foundation.InternalNSNotificationHandler.Post (Foundation.NSNotification s) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/Foundation/NSNotificationCenter.cs:48
    at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
    at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/UIKit/UIApplication.cs:86
    at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.18.2.1/src/Xamarin.iOS/UIKit/UIApplication.cs:65
    at CornerStone.iOS.Application.Main (System.String[] args) [0x00002] in /Users/linnkristin/GIT/CS/CornerStone/iOS/Main.cs:16
    CalabashServer | XTC_SKIP_LPSERVER_TOKEN is not in the app environment

  • LandLuLandLu Member, Xamarin Team Xamurai

    @BenJones.3507 I don't need the whole real project.
    Could you please reproduce this with a small sample and share it here?

  • BenJones.3507BenJones.3507 USMember ✭✭

    @LandLu no problem, I've uploaded a cut down project to show the issue here - https://bitbucket.org/benjones3/scwappxamsupport/src/master/

    To reproduce, launch and from the flyout menu select Login then press the Next button leaving the entry box empty.

  • JohnHardmanJohnHardman GBUniversity admin

    @LandLu said:
    If hardcode to set the property won't throw crash, it may be caused by your converter.
    Sometimes you will get a null value in your converter so we need to use an if statement to exclude this condition:

    if (value != null)
    {
    
    }
    

    When converting a value bound to a property that has a type that is not nullable, under what circumstances would the value converter receive a null value?

  • LandLuLandLu Member, Xamarin Team Xamurai

    I modified your layout after some tests. And the ultimate design looks like:

    <ScrollView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
        <!--<StackLayout>-->
        <Grid>
    
            <Frame x:Name="LoginFrameStep1" Margin="20" Padding="20"
                    BackgroundColor="White" IsVisible="True"
                    CornerRadius="12" HasShadow="False">
                <!--<StackLayout>-->
                <Grid>
    
                    <Frame BackgroundColor="{StaticResource background-light-grey}"
                            CornerRadius="4"
                            Padding="20" 
                            BorderColor="#FFFFFF" 
                            HasShadow="False" InputTransparent="False">
    
                        <StackLayout>
    
                            <Entry
                                x:Name="UsernameEntry" 
                                Placeholder="{Binding UILabelYourLoginName}"
                                ReturnType="Next"
                                Text="{Binding LoginName.Value}"
                                IsTextPredictionEnabled="False"
                                IsSpellCheckEnabled="False"
                                Keyboard="Default" Style="{StaticResource EntryStyle}">
                                <Entry.Behaviors>
                                    <behaviors:EventToCommandBehavior
                                        Command="{Binding ClearValidationCommand}"
                                        CommandParameter="LoginName"
                                        EventName="Focused" />
                                </Entry.Behaviors>
                            </Entry>
    
                            <!--WORKING-->
                            <!--<Label
                                IsVisible="True" HeightRequest="50" BackgroundColor="Orange"
                                Style="{StaticResource ErrorLabelStyle}"
                                Text="{Binding LoginName.FirstError}" />-->
    
                            <!--NOT WORKING-->
                            <Label
                                IsVisible="{Binding LoginName.IsValid, Converter={StaticResource InverseBoolean}}"
                                Style="{StaticResource ErrorLabelStyle}"
                                Text="{Binding LoginName.FirstError}" />
    
                            <controls:RoundedButton 
                                Text="Next"
                                Command="{Binding ValidateLoginStep1Command}"/>
    
                        </StackLayout>
    
    
                    </Frame>
    
                <!--</StackLayout>-->
                </Grid>
    
            </Frame>
    
        <!--</StackLayout>-->
        </Grid>
    
    </ScrollView>
    

    I replaced the StackLayout with Grid and removed some VerticalOptions. It works finally:

  • BenJones.3507BenJones.3507 USMember ✭✭

    Thanks @LandLu, I'll give this a try in the main project and see how I get along.

    Is this down to me making incorrect usage of the layouts or is it a bug of Xamarin in not being able to handle it properly?

  • BenJones.3507BenJones.3507 USMember ✭✭

    On further investigation that solution works but only on the very specific minimal example, taking that and trying to integrate it back into my main project with everything else on the view, as soon as I add RowDefinitions to the Grid, unless I set them to a fixed height I'm back to where I was and app crashes on showing the message.

    The whole idea of this is that I don't want empty space where the error could be. How come this is so difficult to achieve on iOS when out of the box it's so easy on Android.



            <Frame x:Name="LoginFrameStep1" Margin="20" Padding="20"
                    BackgroundColor="White" IsVisible="True"
                    CornerRadius="12" HasShadow="False">
                <!--<StackLayout>-->
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
    
                    <Frame BackgroundColor="{StaticResource background-light-grey}"
                            CornerRadius="4"
                            Padding="20" 
                            BorderColor="#FFFFFF" 
                            HasShadow="False" InputTransparent="False" Grid.Row="0">
    
                        <StackLayout>
    
                            <Entry
                                x:Name="UsernameEntry" 
                                Placeholder="{Binding UILabelYourLoginName}"
                                ReturnType="Next"
                                Text="{Binding LoginName.Value}"
                                IsTextPredictionEnabled="False"
                                IsSpellCheckEnabled="False"
                                Keyboard="Default" Style="{StaticResource EntryStyle}">
                                <Entry.Behaviors>
                                    <behaviors:EventToCommandBehavior
                                        Command="{Binding ClearValidationCommand}"
                                        CommandParameter="LoginName"
                                        EventName="Focused" />
                                </Entry.Behaviors>
                            </Entry>
    
                            <!--WORKING-->
                            <!--<Label
                                IsVisible="True" HeightRequest="50" BackgroundColor="Orange"
                                Style="{StaticResource ErrorLabelStyle}"
                                Text="{Binding LoginName.FirstError}" />-->
    
                            <!--NOT WORKING-->
                            <Label
                                IsVisible="{Binding LoginName.IsValid, Converter={StaticResource InverseBoolean}}"
                                Style="{StaticResource ErrorLabelStyle}"
                                Text="{Binding LoginName.FirstError}" />
    
                            <controls:RoundedButton 
                                Text="Next"
                                Command="{Binding ValidateLoginStep1Command}"/>
                            
                        </StackLayout>
    
                        
                    </Frame>
    
                    <Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" 
                            RowSpacing="5" ColumnSpacing="5" Margin="0" Padding="0,0,0,0"
                          ColumnDefinitions="75*, 25*"
                            RowDefinitions="Auto" Grid.Row="1">
    
                        <Label Text="Remember my Login Name"
                               VerticalOptions="Center"
                               TextColor="{StaticResource capita-navy-blue}" 
                               Grid.Column="0" />
                        <Switch x:Name="swRememberMyLoginName" 
                                IsToggled="True" Grid.Column="1" HorizontalOptions="End"/>
                    </Grid>
    
                    <!--</StackLayout>-->
                </Grid>
    
            </Frame>
            
        <!--</StackLayout>-->
        </Grid>
    
    </ScrollView>
    
  • LandLuLandLu Member, Xamarin Team Xamurai

    Displaying or hiding controls is not so difficult in my sample:

    I even try a similar layout as yours in my sample. It still works as expected.
    It is a complex project so I can't find out why it occurred like this.
    I can only help you adjust the layout to fix it.

Sign In or Register to comment.