Xaml 如何在xamarin表单的列表视图中仅添加一次按钮
使用此代码Xaml 如何在xamarin表单的列表视图中仅添加一次按钮,xaml,xamarin,xamarin.forms,Xaml,Xamarin,Xamarin.forms,使用此代码 x:Class=“适合计划。时间线页面” Title=“时间线” BackgroundColor=“{DynamicSource MainWrapperBackgroundColor} 但是如果我想在列表视图的末尾只显示一次订单按钮,如何实现呢 我尝试过,但没有成功: 它在末尾显示了按钮,但列表为空。ListView提供了HeaderTemplate和FooterTemplate。您应该将按钮放在FooterTemplate中,如下所示: <ListView I
x:Class=“适合计划。时间线页面”
Title=“时间线”
BackgroundColor=“{DynamicSource MainWrapperBackgroundColor}
但是如果我想在列表视图的末尾只显示一次订单按钮,如何实现呢
我尝试过,但没有成功:
它在末尾显示了按钮,但列表为空。ListView提供了HeaderTemplate
和FooterTemplate
。您应该将按钮放在FooterTemplate
中,如下所示:
<ListView ItemsSource="{ Binding TimelineList }" SeparatorVisibility="None" BackgroundColor="{ DynamicResource BasePageColor }" HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
.................
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.FooterTemplate>
<DataTemplate>
<ContentView>
//Put your button here
</ContentView>
</DataTemplate>
</ListView.FooterTemplate>
</ListView>
.................
//把你的按钮放在这里
从上一个答案开始,您可以将按钮放在页脚中,或者如果您想将按钮保留在单元格模板中,然后用IsVisible=您的自定义转换器将按钮包装起来,这将检查如果(myIndex==TotalistCount)
然后,按钮将仅显示列表中最后一项。尼克,但是,这可能解决了问题,但不是实现这一点的好方法。这会为每个ListView项创建一个按钮实例。使用
解决了我的问题
<ContentPage.Content>
<ListView
ItemsSource="{ Binding TimelineList }"
SeparatorVisibility="None"
BackgroundColor="{ DynamicResource BasePageColor }"
HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout>
<StackLayout>
<Grid x:Name="GridTasks">
<local:TimelineItemTemplate
Padding="{ DynamicResource MainWrapperPadding }"/>
</Grid>
</StackLayout>
<StackLayout>
</StackLayout>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
<artina:Button
Clicked="OnNextButtonTapped"
Style="{DynamicResource PrimaryActionButtonStyle}"
Text="Order"
VerticalOptions="EndAndExpand"
WidthRequest="{ artina:OnOrientationDouble
LandscapeTablet=600 }"
HorizontalOptions="{ artina:OnOrientationLayoutOptions
PortraitPhone=Fill,
LandscapePhone=Fill,
PortraitTablet=Fill,
LandscapeTablet=Center }"/>
<ListView ItemsSource="{ Binding TimelineList }" SeparatorVisibility="None" BackgroundColor="{ DynamicResource BasePageColor }" HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
.................
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.FooterTemplate>
<DataTemplate>
<ContentView>
//Put your button here
</ContentView>
</DataTemplate>
</ListView.FooterTemplate>
</ListView>