【问题标题】:XAML Page With Grid And Button带有网格和按钮的 XAML 页面
【发布时间】:2018-11-30 23:42:02
【问题描述】:

我有一个网格,它将占据我的大部分 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>

【问题讨论】:

  • 网格在哪里??也许您尝试创建一个自定义控件并且混淆了使用 contentpage 而不是 contentview 包装它?
  • @NickKovalsky - 我编辑 OP 以显示 GRID 创建。如果我需要包括我实际将数据绑定到网格的位置,我也可以这样做。
  • 仍然看不到您在哪里布置网格和按钮。您只是显示了控件,而不是您布局它们的页面或代码..
  • 一个 ContentPage 只能有一个孩子。您需要将 Grid 和 Button 包含在 Layout 容器中
  • 那么还有一些有趣的事情发生了,如果没有看到你所有的布局,很难说它是什么。

标签: xaml xamarin xamarin.forms


【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    • 2012-11-28
    • 2015-11-02
    • 1970-01-01
    • 2021-02-22
    • 2012-04-24
    • 1970-01-01
    相关资源
    最近更新 更多