C
C#2y ago
.bobgoblin

❔ Setting Up First Xamarin FOrms

trying to follow a xamarin forms tutorial on creating a mobile app...but I am getting these errors
public LoginPage()
{
var vm = new LoginViewModel();
this.BindingContext = vm;
vm.DisplayInvalidLoginPrompt += () => DisplayAlert("Error", "Invalid Credentials", "OK");

InitializeComponent();

Email.Completed += (object sender, EventArgs e) =>
{
Password.Focus();
};

Password.Completed += (object sender, EventArgs e) =>
{
vm.SubmitCommand.Execute(null);
};
}
public LoginPage()
{
var vm = new LoginViewModel();
this.BindingContext = vm;
vm.DisplayInvalidLoginPrompt += () => DisplayAlert("Error", "Invalid Credentials", "OK");

InitializeComponent();

Email.Completed += (object sender, EventArgs e) =>
{
Password.Focus();
};

Password.Completed += (object sender, EventArgs e) =>
{
vm.SubmitCommand.Execute(null);
};
}
errors =>
The name InitializeComponent does not exist in the current context
Email does not contain a definition for Completed
The name Password does not exist in the current context
The name InitializeComponent does not exist in the current context
Email does not contain a definition for Completed
The name Password does not exist in the current context
10 Replies
PraetorBlue
PraetorBlue2y ago
You're using a bunch of variables and methods you never defined anywhere.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
FoxTrotCharlieZulu
This is the guide I'm following...where is it shown to do that? https://www.c-sharpcorner.com/article/xamarin-forms-create-a-login-page-mvvm/
Xamarin.Forms - Create A Login Page (MVVM)
In this code we created the followings properties: Email, Password and the command SubmitCommand() that we will use in the Login command button in the Login page. We use the ICommand interface that allows defining and implementing a command what we call commanding.
PraetorBlue
PraetorBlue2y ago
Looks like you may have: - Skipped the beginning of step 4 with all the XML stuff - Failed to derive from the appropriate base class class LoginPage : ContentPage and possible you skipped more than that too hard to say
.bobgoblin
.bobgoblin2y ago
okay - i'll start back at the beginning and see....
.bobgoblin
.bobgoblin2y ago
@PraetorBlue - I have that code for step 4...Let me show you... LoginPage.xaml
<?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="XF_Login.Views.LoginPage"
BackgroundImage="logo.jpg">
<ContentPage.Content>
<StackLayout Orientation="Vertical" Padding="30" Spacing="40">
<BoxView HeightRequest="10"/>
<Image HorizontalOptions="Center" WidthRequest="300" Source="maco.jpg"/>
<Frame BackgroundColor="#BF043055" HasShadow="False">
<StackLayout Orientation="Vertical" Spacing="10">
<Entry x:Name="Email" Text="{Binding Email}" Placeholder="Email"
PlaceholderColor="White" HeightRequest="40"
Keyboard="Email"
TextColor="White"/>
<Entry x:Name="Password" Text="{Binding Password}" Placeholder="Senha"
PlaceholderColor="White" HeightRequest="40"
IsPassword="True"
TextColor="White"/>
</StackLayout>
</Frame>
<Button Command="{Binding SubmitCommand}" Text="Login" TextColor="White"
FontAttributes="Bold" FontSize="Large" HorizontalOptions="FillAndExpand"
BackgroundColor="#088da5" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
<?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="XF_Login.Views.LoginPage"
BackgroundImage="logo.jpg">
<ContentPage.Content>
<StackLayout Orientation="Vertical" Padding="30" Spacing="40">
<BoxView HeightRequest="10"/>
<Image HorizontalOptions="Center" WidthRequest="300" Source="maco.jpg"/>
<Frame BackgroundColor="#BF043055" HasShadow="False">
<StackLayout Orientation="Vertical" Spacing="10">
<Entry x:Name="Email" Text="{Binding Email}" Placeholder="Email"
PlaceholderColor="White" HeightRequest="40"
Keyboard="Email"
TextColor="White"/>
<Entry x:Name="Password" Text="{Binding Password}" Placeholder="Senha"
PlaceholderColor="White" HeightRequest="40"
IsPassword="True"
TextColor="White"/>
</StackLayout>
</Frame>
<Button Command="{Binding SubmitCommand}" Text="Login" TextColor="White"
FontAttributes="Bold" FontSize="Large" HorizontalOptions="FillAndExpand"
BackgroundColor="#088da5" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
LoginPage.xaml.cs -> https://pastebin.com/Lk7PKASc
Pastebin
loginpage.xaml.cs - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
.bobgoblin
.bobgoblin2y ago
This is the project I have.....maybe you can see error in my code?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
.bobgoblin
.bobgoblin2y ago
@PraetorBlue - any insight?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server