1

Hello I got an error while doing login page. I just code Mainpage.xaml file other files are default and I picked "blank" when creating project. My error is:

" System.InvalidOperationException: "The class, property, or method you are attempting to use ("GradientBrush" is part of GradientBrush; to use it, you must opt-in by calling Forms.SetFlags("Brush_Experimental") before calling Forms.Init()."

I just write one file which is Mainpage.xaml. Does anybody help me how to handle my problem?

    <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="HealthCareApp.MainPage">
<StackLayout>
        <StackLayout.Background>
            <LinearGradientBrush EndPoint="0,1">
                <GradientStop Color="#48b6a6" Offset="0.1" /> 
                <GradientStop Color="#2b78d4" Offset="1.0" />
            </LinearGradientBrush>
        </StackLayout.Background>
        <StackLayout Padding="0" Margin="10,100,10,0" HorizontalOptions="FillAndExpand" >
            <Frame BackgroundColor="Transparent" HeightRequest="500" Padding="0" Margin="0">
                <StackLayout>
                    <StackLayout Margin="10">
                        <Label Text="SIGN IN" TextColor="White" HorizontalOptions="CenterAndExpand" FontAttributes="Bold" ></Label>
                    </StackLayout>
                    <StackLayout Padding="0" Margin="15,10">
                        
                        <Frame BackgroundColor="Transparent" BorderColor="White" Padding="0" HorizontalOptions="FillAndExpand" CornerRadius="30">
                            <StackLayout Orientation="Horizontal">
                                <Frame BackgroundColor="SkyBlue" HeightRequest="40" WidthRequest="40" CornerRadius="30" Padding="0" Margin="5">
                                    <Image Source="https://www.findool.com/images/avatars/avatar.png" Aspect="AspectFill" Margin="0"/>
                                </Frame>
                                <Entry Placeholder="Email" TextColor="#666666" FontAttributes="None" HorizontalOptions="FillAndExpand" Margin="0,0,20,0"/>
                            </StackLayout>
                        </Frame>

                        <Frame BackgroundColor="Transparent" BorderColor="White" Margin="0,15,0,0" Padding="0" HorizontalOptions="FillAndExpand" CornerRadius="30">
                            <StackLayout Orientation="Horizontal">
                                <Frame BackgroundColor="SkyBlue" HeightRequest="40" WidthRequest="40" CornerRadius="30" Padding="0" Margin="5">
                                    <Image Source="https://images.all-free-download.com/images/graphicthumb/lock_icon_6813906.jpg" Aspect="AspectFill" Margin="0"/>
                                </Frame>
                                <Entry Placeholder="Password" IsPassword="True" TextColor="White" FontAttributes="None" HorizontalOptions="FillAndExpand" Margin="0,0,20,0"/>
                            </StackLayout>
                        </Frame>

                        <StackLayout  Orientation="Horizontal">
                            <CheckBox IsChecked="False" Color="White" />
                            <Label Text="Remember me" TextColor="White" FontSize="Small" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" />

                            <Label Text="Forgot Password" TextColor="White" FontAttributes="Bold" HorizontalOptions="EndAndExpand" FontSize="Small" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" />
                        </StackLayout>

                        <Button Text="SIGN IN" BackgroundColor="#2b78d4" TextColor="White" CornerRadius="30" />
                        <StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
                            <Label Text="Still Not Connected ?" TextColor="White" FontSize="Small"/>
                            <Label Text="Sign Up" TextColor="White" FontAttributes="Bold" FontSize="Small"/>
                        </StackLayout>

                        <StackLayout Margin="0,25,0,0" Padding="0">
                            <Grid>
                                <BoxView BackgroundColor="White" HeightRequest="1" WidthRequest="150"  HorizontalOptions="Center" VerticalOptions="Center"/>
                                <Frame BackgroundColor="White" HeightRequest="45" WidthRequest="45" CornerRadius="45" HasShadow="False" BorderColor="White" Margin="0" HorizontalOptions="Center" Padding="0">
                                    <Label Text="OR" TextColor="White" FontSize="Small" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
                                </Frame>
                            </Grid>
                        </StackLayout>

                        <StackLayout Margin="0,25" Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
                            <Frame BackgroundColor="White" HeightRequest="45" WidthRequest="45" CornerRadius="45" HasShadow="False" BorderColor="White" Margin="0" HorizontalOptions="Center" Padding="0">
                                <Image Source="https://www.pngitem.com/pimgs/m/44-440455_transparent-background-fb-logo-hd-png-download.png" Aspect="AspectFill" Margin="0"/>
                            </Frame>
                            <Frame BackgroundColor="White" HeightRequest="45" WidthRequest="45" CornerRadius="45" HasShadow="False" BorderColor="White" Margin="0" HorizontalOptions="Center" Padding="0">
                                <Image Source="https://blog.hubspot.com/hubfs/image8-2.jpg" Aspect="AspectFill" Margin="0"/>
                            </Frame>
                        </StackLayout>
                        
                    </StackLayout>
                </StackLayout>
            </Frame >    
        </StackLayout>
</StackLayout >

</ContentPage>
4
  • the error message tells you exactly how to fix this - "you must opt-in by calling Forms.SetFlags("Brush_Experimental") before calling Forms.Init()."
    – Jason
    Nov 5, 2020 at 20:04
  • Dear @Jason what should I write to MainPage.xaml.cs file ? It is default now, I am just doing ui part without touching any behind logics parts. I only write code to this Mainpage.xaml file and it is above. Maybe it looks weird but I am newbie sorry for asking too questions :/ Nov 5, 2020 at 20:08
  • maybe try searching your code for "Forms.Init" and make the change there? Or read the docs as @CFun notes below
    – Jason
    Nov 5, 2020 at 20:12
  • @Jason yes, I appreciated both of you thanks Nov 5, 2020 at 20:48

1 Answer 1

1

According to the documentation you need to set up experimental flags (In your target platforms projects) for some features that the development team is judging still in experimental phase, so that you acknowledge that before using them.

On android in will be in your MainActivity class, on ios in AppDelegate Class:

Forms.SetFlags("Brush_Experimental")

You can set several experimental flags at once like:

Xamarin.Forms.Forms.SetFlags(new string[] { "SwipeView_Experimental", "Shapes_Experimental", "AppTheme_Experimental" });

Note

Make sure to call SetFlags() before Xamarin.Forms.Forms.Init()

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.