【问题标题】:Xamarin - make appear element over Grid FormXamarin - 在网格表单上显示元素
【发布时间】:2019-09-02 00:40:39
【问题描述】:

我有一个使用 ContentPage 中的 Grid 制作的表单,例如:

<ContentPage>
<Grid RowSpacing="0" 
           >
    <Grid.RowDefinitions>
        <RowDefinition Height="90" />
        <RowDefinition Height="1" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>


    <Grid BackgroundColor="{StaticResource TopBackground}" Padding="16" RowSpacing="4" ColumnSpacing="0" 
          >
        <Grid.RowDefinitions>
            <RowDefinition Height="4*" />
            <RowDefinition Height="6*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>


        <Button  Text="BUTTON"
                    FontSize="20" Grid.Row="1" Grid.Column="1"
             />  
    </Grid>


    <BoxView Grid.Row="1" HeightRequest="1" BackgroundColor="{StaticResource ColorSeparador}" HorizontalOptions="FillAndExpand" />

    <ScrollView Grid.Row="2">

        <StackLayout Orientation="Vertical" Margin="16" Spacing="4"
                     >
            <local:ContactEntry HeightRequest="35"  Keyboard="Email" x:Name="emailEntry" "/>

            <Button Margin="0,30,0,50" Grid.Row="9" Text="Send" 
                x:Name="BtnEntrar" Clicked= "onEnviarClicked" B/>  
        </StackLayout>

    </ScrollView>


</Grid>
</ContentPage>

我的问题是,当用户发送表单时,我的自定义忙碌指示元素(避免覆盖整个页面)将出现在表单的中心和上方的位置和位置?

     <custom:MyAct
         WidthRequest="150" HeightRequest="150" 
      />  

【问题讨论】:

    标签: xamarin layout grid busyindicator


    【解决方案1】:

    如果您希望自定义指标位于中心并覆盖网格的其余内容,只需执行以下操作:

    <ContentPage>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="90" />
                <RowDefinition Height="1" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <!-- Your content here -->
            <custom:MyAct
                Grid.Row="0"
                Grid.RowSpan="3"
                WidthRequest="150"
                HeightRequest="150"
                VerticalOptions="Center"
                HorizontalOptions="Center" />  
        </Grid>
    </ContentPage>
    

    这样,由于您已经为网格定义了 3 行,因此您的自定义活动指示器将占用与整个网格一样多的空间,这要归功于属性 Grid.RowSpan="3"。此外,指示器将出现在网格中的所有其他内容之上,因为它是在 XAML 代码中定义的。

    要使其正常工作,请记住进行必要的绑定以隐藏/显示您的自定义活动指示器。

    【讨论】:

    • 我正在使用行定义。在我们的解决方案中,活动出现在第 0 行。我需要使用绝对布局吗?
    • 您根本不需要AbsoluteLayout 或您想要实现的目标。请分享您的实际 XAML 代码,因为您在问题中显示的代码中没有行定义。
    • 使用您的解决方案,活动出现但以第 0 行为中心。
    • 请看我上次的编辑。您的主网格正好有三行,所以您缺少的是自定义活动指示器中的属性Grid.RowSpan="3"
    • 乐于助人! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 2016-07-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多