繁体   English   中英

如何在Xamarin.Forms列表视图下添加按钮

[英]How to add buttons underneath a Xamarin.Forms list view

您好,我有一个正在使用xamrian格式的应用程序,并且有卡片样式的列表视图。 我希望能够在列表视图下方添加3个按钮,其中一个在左侧,一个在中央,另一个在右侧,这是我的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="App.HomePage">
  <ListView x:Name="listView" HasUnevenRows="true"  ItemSelected="OnItemSelected">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <Frame Padding="0,0,0,8" BackgroundColor="#d2d5d7">
            <Frame.Content>
              <Frame Padding="15,15,15,15"   OutlineColor="Gray" BackgroundColor="White">
                <Frame.Content>
                  <StackLayout Padding="20,0,0,0"  Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
                    <Image
                          HorizontalOptions="StartAndExpand"
                          Source="{Binding Image}" />
                    <Label Text="{Binding Name}"
                           TextColor="#69add1"
                           FontFamily="OpenSans-Light"
                           FontSize="24"/>
                  </StackLayout>
                </Frame.Content>
              </Frame>
            </Frame.Content>
          </Frame>  

          </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>
  </ContentPage>

我将如何在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:local="clr-namespace:Sandbox_Forms"
             x:Class="Sandbox_Forms.MainPage">

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="*"/>
      <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <ListView Grid.Row="0" BackgroundColor="Aqua">
      <!-- Add bindings and data template -->
    </ListView>
    <StackLayout Orientation="Horizontal" Grid.Row="1">
      <Button Text="Button1" HorizontalOptions="FillAndExpand"/>
      <Button Text="Button2" HorizontalOptions="FillAndExpand"/>
      <Button Text="Button3" HorizontalOptions="FillAndExpand"/>
    </StackLayout>
  </Grid>

</ContentPage>

这将限制您的ListView仅填充按钮不占用的空间。 输出应如下所示: UWP Desktop示例

<StackLayout>
  <ListView>
    ...
  </ListView>
  <StackLayout Orientation="Horizontal">
    <Button ... />
    <Button ... />
    <Button ... />
  </StackLayout>
</StackLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM