Xamarin 了解
学习
配置 Navigation
在 view
的 xmlns
配置 , 默认的 Nav
就会不见
NavigationPage.HasNavigationBar="False"
TabView
如果是 Home Page,下面有 tabview 设计
// 配置
xmlns:tabView="clr-namespace:Syncfusion.XForms.TabView;assembly=Syncfusion.SfTabView.XForms"
<ContentPage.Content>
<tabView:SfTabView BackgroundColor="#f2f2f2" EnableSwiping="False"
TabHeaderPosition="Bottom" DisplayMode="Image"
VisibleHeaderCount="4">
<tabView:SfTabView.SelectionIndicatorSettings>
<tabView:SelectionIndicatorSettings Color="Transparent" Position="Fill"
StrokeThickness="0" AnimationDuration="10"/>
</tabView:SfTabView.SelectionIndicatorSettings>
<!-- 第 1 -->
<tabView:SfTabItem Title="Home" ImageSource="homeIcon" SelectionColor="#000000" TitleFontColor="#666666">
<tabView:SfTabItem.Content>
<ScrollView BackgroundColor="#ECECEC">
<StackLayout Padding="0,20,0,0"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
BindingContext="{StaticResource UserVM}">
</StackLayout>
</ScrollView>
</tabView:SfTabItem.Content>
</tabView:SfTabItem>
<!-- 第 2 -->
<tabView:SfTabItem Title="Movie" ImageSource="movieIcon" SelectionColor="#000000" TitleFontColor="#a3a0a0">
<tabView:SfTabItem.Content>
<StackLayout BackgroundColor="#ECECEC" HorizontalOptions="FillAndExpand">
<!-- 内容可以在此处添加 -->
</StackLayout>
</tabView:SfTabItem.Content>
</tabView:SfTabItem>
<!-- 第 3 -->
<tabView:SfTabItem Title="Actor" ImageSource="userIcon" SelectionColor="#000000" TitleFontColor="#a3a0a0">
<tabView:SfTabItem.Content>
<StackLayout BackgroundColor="#ECECEC" BindingContext="{StaticResource UserVM}">
<!-- 内容可以在此处添加 -->
</StackLayout>
</tabView:SfTabItem.Content>
</tabView:SfTabItem>
<!-- 第 4 -->
<tabView:SfTabItem Title="User" ImageSource="userIcon" SelectionColor="#000000" TitleFontColor="#a3a0a0">
<tabView:SfTabItem.Content>
<StackLayout BackgroundColor="#ECECEC" BindingContext="{StaticResource UserVM}">
<!-- 内容可以在此处添加 -->
</StackLayout>
</tabView:SfTabItem.Content>
</tabView:SfTabItem>
</tabView:SfTabView>
</ContentPage.Content>
Frame
边框: Frame
可以定义边框的颜色和厚度,帮助视觉上区分内容。
阴影: 可以添加阴影效果,使 Frame
看起来浮动在其他内容之上,增强立体感。
圆角: 可以设置边角为圆角,使界面更加柔和。
<Frame Padding="10"
BackgroundColor="White"
BorderColor="Gray"
CornerRadius="5"
HasShadow="True">
<StackLayout>
<Label Text="Hello, World!"
FontSize="20"
HorizontalOptions="Center" />
<Button Text="Click Me"
HorizontalOptions="Center" />
</StackLayout>
</Frame>
<Frame CornerRadius="100" HasShadow="True" HeightRequest="32" WidthRequest="32"
BackgroundColor="Black" Padding="5" Margin="12,11,0,0">
<Image Source="tuneIcon" HeightRequest="10" WidthRequest="10"/>
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="OpenTenu"/>
</Frame.GestureRecognizers>
</Frame>
private void OpenTenu(object sender, EventArgs e)
{
// 处理点击事件的逻辑,例如打开菜单
}
CollectionView
显示一个垂直列表
Orientation="Vertical":
- 该属性设置项目的排列方向为垂直。即所有项目将从上到下排列。
Span="4":
- 此属性指定每行显示的项目数量。在这个例子中,每行将展示 4 个项目。当项目的总数超过 4 时,它们将自动换行到下一行。
HorizontalItemSpacing="10":
- 该属性定义项目之间的水平间距。在此示例中,项目之间的水平间距设置为 10 个单位(通常是像素或设备独立单位)。这意味着每个项目之间将留有 10 单位的空隙。
VerticalItemSpacing="10":
- 该属性定义项目之间的垂直间距。与
HorizontalItemSpacing
类似,此属性设置了项目之间的垂直间距,同样为 10 单位。这使得每行之间的项目也会有 10 单位的空隙。
MVVM 版本
<CollectionView ItemsSource="{Binding ActorAvatar}" Margin="10,0,10,0">
<CollectionView.ItemsLayout>
<!-- 一行 4个 -->
<GridItemsLayout Orientation="Vertical"
Span="4"
HorizontalItemSpacing="10"
VerticalItemSpacing="10"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
<StackLayout Padding="0,10,0,10">
<Frame AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1"
Padding="0" CornerRadius="100"
HeightRequest="80" WidthRequest="80"
HorizontalOptions="StartAndExpand">
<AbsoluteLayout>
<Image Source="{Binding ActorImage}"
Aspect="AspectFill"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1"/>
</AbsoluteLayout>
</Frame>
<Label Text="{Binding ActorName}"
HorizontalTextAlignment="Center"
FontAttributes="Bold"/>
</StackLayout>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer CommandParameter="{Binding ActorID}"
Tapped="MoveActorMovie"/>
</StackLayout.GestureRecognizers>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
普通 版本
<CollectionView ItemsLayout="HorizontalList"
x:Name="PromotionList"
HeightRequest="250"
HorizontalScrollBarVisibility="Never"
VerticalOptions="Start">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout Padding="10">
<Frame HasShadow="True"
BackgroundColor="{Binding Genre}"
Padding="25,10"
CornerRadius="100"
BorderColor="LightGray">
<Label Text="{Binding Title}" FontAttributes="Bold"
TextColor="{Binding Duration}"/>
</Frame>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer CommandParameter="{Binding Title}" Tapped="Follow"/>
</StackLayout.GestureRecognizers>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Grid
<Grid Padding="0,0,10,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="0.6*"/>
</Grid.ColumnDefinitions>
</Grid>
Grid.Row="1" Grid.Column="1" Grid.RowSpan="2"
StackLayout
<StackLayout Orientation="Horizontal" Padding="20,0,10,0" Margin="0,10,0,0">
Image
<Image Source="{Binding HotMovie[1].MoviePoster}" Aspect="AspectFill"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1"></Image>
AbsoluteLayout
<AbsoluteLayout>
<Image Source="{Binding HotMovie[0].MoviePoster}" Aspect="AspectFill"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1"></Image>
// 其他内容
</AbsoluteLayout>
Label
<Label Text="{Binding Title}" TextColor="black"
FontSize="17" FontAttributes="Bold" VerticalTextAlignment="Center"/>
BoxView
<BoxView BackgroundColor="LightGray" HeightRequest="1" HorizontalOptions="FillAndExpand"/>
<BoxView BackgroundColor="Black"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,0,1,1"
Opacity="0.5"
x:Name="Boxblack"
IsVisible="false"
></BoxView>
ScrollView
<ScrollView BackgroundColor="#ECECEC">
<StackLayout Padding="0,20,0,0"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
BindingContext="{StaticResource UserVM}">
// 其他内容
</StackLayout>
</ScrollView>
abstractions:CircleImage
<abstractions:CircleImage Aspect="AspectFill"
WidthRequest="80"
HeightRequest="80"
HorizontalOptions="CenterAndExpand"
Source="{Binding UserAvatar}"/>
Entry
<Entry TextColor="Black" Text="{Binding Email}"/>