Xaml Xamarin表单中gridview的项模板?
我想在gridview中使用一个项目模板,这样所有的孩子看起来都一样,这可能吗?或者有没有类似的工作,以Xamarin的形式 这是我的项目模板Xaml Xamarin表单中gridview的项模板?,xaml,xamarin,gridview,xamarin.forms,itemtemplate,Xaml,Xamarin,Gridview,Xamarin.forms,Itemtemplate,我想在gridview中使用一个项目模板,这样所有的孩子看起来都一样,这可能吗?或者有没有类似的工作,以Xamarin的形式 这是我的项目模板 <FlexLayout Grid.Row="0" Grid.Column="0" HorizontalOptions="CenterAndExpand" VerticalOptions="Center
<FlexLayout
Grid.Row="0" Grid.Column="0"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
Direction="Column" AlignContent="Center"
MinimumHeightRequest="110"
WidthRequest="90"
>
<Button BorderColor="#fff"
BorderWidth="1"
BackgroundColor="#4D000000"
HeightRequest="90" CornerRadius="45"
Image="vera"/>
<Label Text="Chat"
Margin="0,4,0,0"
HeightRequest="20"
FontSize="9"
HorizontalTextAlignment="Center"
HorizontalOptions="CenterAndExpand"/>
</FlexLayout>
您只需在网格定义中添加布局即可。现在,如果您想要动态内容,只需要绑定所需的属性。 这是不正确的,因为没有行和等的定义,但您只需要在代码隐藏中动态定义所需内容,并相应地添加行和列
<Grid>
<Grid.RowDefinitions>
//"Here you define your rows"
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
//"Here you define your columns"
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
//"Here you define your desired template"
<FlexLayout
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
Direction="Column" AlignContent="Center"
MinimumHeightRequest="110"
WidthRequest="90"
>
<Button BorderColor="#fff"
BorderWidth="1"
BackgroundColor="#4D000000"
HeightRequest="90" CornerRadius="45"
Image="vera"/>
<Label Text="Chat"
Margin="0,4,0,0"
HeightRequest="20"
FontSize="9"
HorizontalTextAlignment="Center"
HorizontalOptions="CenterAndExpand"/>
</FlexLayout>
</Grid>
//“在这里定义行”
//“在这里定义列”
//“在此定义所需的模板”
为什么不使用Listview
<ListView Grid.Row="0" Grid.Column="0" ItemSource="{Binding ListOfItem}">
<ListView.ItemTemplate>
<DateTemplate>
<ViewCell>
<FlexLayout
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
Direction="Column" AlignContent="Center"
MinimumHeightRequest="110"
WidthRequest="90">
<Button BorderColor="#fff" Command="{Binding ButtonCommand}"
BorderWidth="1"
BackgroundColor="#4D000000"
HeightRequest="90" CornerRadius="45"
Image="vera"/>
<Label Text="{Binding Text}"
Margin="0,4,0,0"
HeightRequest="20"
FontSize="9"
HorizontalTextAlignment="Center"
HorizontalOptions="CenterAndExpand"/>
</FlexLayout>
<ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
作为ItemSource,创建一个对象,该对象包含按钮的命令属性和名称的字符串,并创建这些对象的列表