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

时间:2016-07-08 15:30:09

标签: c# xaml xamarin xamarin.forms

你好,我有一个应用程序,我用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中执行此操作?

提前感谢! :)

2 个答案:

答案 0 :(得分:3)

试试这个:

<?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 sample

答案 1 :(得分:1)

MigrationSqlGenerator