该登录页面参考自油管上Xamarin教学视频 原视频链接 https://youtu.be/mJE3KCttm3Q
一.效果展示
1.静态图
2.动态图
??表示段落缩进
二.工程结构
三.代码展示
MainPage.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"
xmlns:vm="clr-namespace:Login"
xmlns:ct="http://xamarin.com/schemas/2020/toolkit"
x:Class="Login.MainPage">
<ContentPage.BindingContext>
<vm:MainViewModel/>
</ContentPage.BindingContext>
<Grid>
<ct:MediaElement x:Name="bgVideo" Source="ms-appx:///event.mp4" ShowsPlaybackControls="False"
IsLooping="True" Aspect="AspectFill" AutoPlay="True"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
<BoxView>
<BoxView.Background>
<LinearGradientBrush StartPoint="1,0" EndPoint="1,1">
<GradientStop Color="Transparent" Offset="0"/>
<GradientStop Color="#2E4159" Offset="0.9"/>
<GradientStop Color="#2E4159" Offset="1"/>
</LinearGradientBrush>
</BoxView.Background>
</BoxView>
<Grid RowDefinitions="Auto,Auto,Auto" HeightRequest="280" Margin="30,30,30,100" RowSpacing="40" VerticalOptions="End">
<CarouselView x:Name="cvOnboarding" IndicatorView="LandingIndicator" ItemsSource="{Binding Onboardings}" VerticalOptions="End">
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout Spacing="10">
<Label Text="{Binding Heading}" TextColor="White" FontSize="26" FontAttributes="Bold" WidthRequest="220" HorizontalOptions="Start"/>
<Label Text="{Binding Caption}" TextColor="White" FontSize="14" WidthRequest="220" HorizontalOptions="Start"/>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<IndicatorView x:Name="LandingIndicator" Grid.Row="1" IndicatorsShape="Circle" IndicatorColor="#B8B8B8" SelectedIndicatorColor="#E7305E"/>
<StackLayout Grid.Row="2" Orientation="Horizontal" Spacing="20" VerticalOptions="End" >
<Button Text="Sign Up" Command="{Binding RegisterCommand}" HeightRequest="50" WidthRequest="145" BackgroundColor="#E7305E" TextColor="White" CornerRadius="25" FontAttributes="Bold"/>
<Button Text="Login in" Command="{Binding SignCommand}" HeightRequest="50" WidthRequest="145" BackgroundColor="White" TextColor="#2E4159" CornerRadius="25" FontAttributes="Bold"/>
</StackLayout>
</Grid>
</Grid>
</ContentPage>
MainPage.xaml.cs代码:
```csharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using Xamarin.CommunityToolkit.UI.Views;
using Xamarin.Forms;
namespace Login
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
AnimateCarousel();
}
Timer timer;
private void AnimateCarousel()
{
timer = new Timer(5000) { AutoReset = true ,Enabled=true};
timer.Elapsed += (s, e) =>
{
if (bgVideo.CurrentState != MediaElementState.Playing)
{
bgVideo.Play();
}
Device.BeginInvokeOnMainThread(() =>
{
if (cvOnboarding.Position == 2)
{
cvOnboarding.Position = 0;
return;
}
cvOnboarding.Position += 1;
});
};
}
}
}
MainViewModel.cs代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace Login
{
public class MainViewModel
{
public MainViewModel()
{
Onboardings = GetOnboarding();
}
public List<Onboarding> Onboardings { get; set; }
private List<Onboarding> GetOnboarding()
{
return new List<Onboarding>()
{
new Onboarding { Heading ="Create events in minutes",Caption="From small birthday parties with friends to large community events"},
new Onboarding { Heading = "Your events in one place", Caption = "Manage all your events in one single place to always get a remionder" },
new Onboarding { Heading = "Explore events around you", Caption = "Select any evnet that interest you from a list of awesome events" }
};
}
}
public class Onboarding
{
public string Heading { get; set; }
public string Caption { get; set; }
}
}
APP.xaml代码:
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Login.App">
<Application.Resources>
</Application.Resources>
</Application>
APP.xaml.cs代码:
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Login
{
public partial class App : Application
{
public App()
{
InitializeComponent();
Device.SetFlags(new [] { "MediaElement_Experimental", "Brush_Experimental" });
MainPage = new MainPage();
}
protected override void OnStart()
{
}
protected override void OnSleep()
{
}
protected override void OnResume()
{
}
}
}
四.工程源码
提取码b3bd
|