Reputation: 2917
I am learning myself some Xamarin development. When I study examples of Xamarin projects, like this one, I sometimes see that a page has a mysterious file with the same name as the xaml file and its code-behind file, but ending with *CS.cs
as you can see is the case with the LoginPage in the above linked project:
LoginPage.xaml
is of course the xaml description of the layout and LoginPage.xaml.cs
is the code-behind. But what does LoginPageCS.cs
? I can remove it from the project and rerun the solution with the same functionality as before. So what is the purpose with files ending with *CS.cs
? I have seen several sample projects where there are *CS.cs
files.
Upvotes: 4
Views: 353
Reputation: 415
Looking at the code, LoginPageCS.cs appears to be largely identical to LoginPage.xaml - so would be a way to create the page controls in C# as opposed to XAML. See this question for a discussion on the difference.
Note the similarities
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="LoginNavigation.LoginPage" Title="Login">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Sign Up" Clicked="OnSignUpButtonClicked" />
</ContentPage.ToolbarItems>
<ContentPage.Content>
<StackLayout VerticalOptions="StartAndExpand">
<Label Text="Username" />
<Entry x:Name="usernameEntry" Placeholder="username" />
<Label Text="Password" />
<Entry x:Name="passwordEntry" IsPassword="true" />
<Button Text="Login" Clicked="OnLoginButtonClicked" />
<Label x:Name="messageLabel" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
LoginPageCS.cs:
public LoginPageCS ()
{
var toolbarItem = new ToolbarItem {
Text = "Sign Up"
};
toolbarItem.Clicked += OnSignUpButtonClicked;
ToolbarItems.Add (toolbarItem);
messageLabel = new Label ();
usernameEntry = new Entry {
Placeholder = "username"
};
passwordEntry = new Entry {
IsPassword = true
};
var loginButton = new Button {
Text = "Login"
};
loginButton.Clicked += OnLoginButtonClicked;
Title = "Login";
Content = new StackLayout {
VerticalOptions = LayoutOptions.StartAndExpand,
Children = {
new Label { Text = "Username" },
usernameEntry,
new Label { Text = "Password" },
passwordEntry,
loginButton,
messageLabel
}
};
}
Upvotes: 3