带有网格和按钮的XAML页面

时间:2018-11-30 13:53:12

标签: xaml xamarin xamarin.forms

我有一个网格,它将占用我的大部分Xamarin.Forms页面,并且我想在网格下方添加一个按钮。我的问题是我正在使用以下语法添加按钮,但是该按钮会填满整个页面。

我需要更改什么才能使按钮直接出现在网格下方?

    <?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="XF.Pages.AEI" >
    <ContentView Content="{Binding ApprovedUserGrid,Mode=TwoWay}" Padding="0,30,0,0"/>
    <Button Command="{Binding OkayCommand}" Text="Okay" TextColor="White"  
            FontAttributes="Bold" FontSize="Large" HorizontalOptions="FillAndExpand"  
            BackgroundColor="#088da5" /> 
</ContentPage>

这是我的网格的C#(不是我实际绑定的位置,而是创建位置)

        private Grid _Grid;

    public Grid TestGrid
    {
        get { return _Grid ?? (_Grid=new Grid()); }
        set
        {
            _Grid = value;
            NotifyPropertyChanged();
        }
    }

编辑
我将代码编辑为这样,没有错误,但是页面上没有看到我的按钮?

    <?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="XF_Login.Pages.ApproveUsers" >
    <StackLayout Orientation="Vertical" Padding="30" Spacing="40"> 
       <ContentView Content="{Binding ApprovedUserGrid,Mode=TwoWay}" Padding="0,30,0,0"/>
       <Button Command="{Binding OkayCommand}" Text="Okay" TextColor="White"  
            FontAttributes="Bold" FontSize="Large" HorizontalOptions="FillAndExpand"  
            BackgroundColor="#088da5" /> 
    </StackLayout>
</ContentPage>

1 个答案:

答案 0 :(得分:1)

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"  
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
             x:Class="XF_Login.Pages.ApproveUsers" >
    <StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" Padding="30" Spacing="40"> 
       <ContentView VerticalOptions="FillAndExpand" Content="{Binding ApprovedUserGrid,Mode=TwoWay}" Padding="0,30,0,0"/>
       <Button Command="{Binding OkayCommand}" Text="Okay" TextColor="White"  
            FontAttributes="Bold" FontSize="Large" HorizontalOptions="Center"  
            BackgroundColor="#088da5" /> 
    </StackLayout>
</ContentPage>