xamarin.forms-隐藏元素问题

时间:2019-12-13 21:49:08

标签: c# xamarin.forms

我正在使用xamarin.forms,但无法显示/隐藏元素。

这是我的要素:

 <StackLayout>
            <zxing:ZXingScannerView x:Name="BarcodeScanView" IsVisible="false" HeightRequest="200" OnScanResult="Handle_OnScanResult" />
        </StackLayout>

现在,当我按下按钮时,我想像这样显示此元素:

BarcodeScanView.IsVisible = true;

到目前为止效果很好,

但是当我在另一个方法调用上将其隐藏时,该元素被隐藏了,但仍有额外的空间:

BarcodeScanView.IsVisible = false;

我正在寻找隐藏元素时删除多余空间的方法。

此外,当我再次按下按钮时,该元素没有显示出来,为什么会这样,以及如何解决我遇到的这些问题?

这是我的完整代码:

<?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:zxing="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms" x:Class="Sales.ContractPage" Style="{StaticResource PageStyle}" Title="Sales Contract Generator">
    <ScrollView>
        <StackLayout VerticalOptions="CenterAndExpand" Spacing="25">

            <ActivityIndicator IsRunning="False" x:Name="activityIndicator" />

            <StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand">



                <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">
                    <Entry x:Name="Community" WidthRequest="200" Placeholder="Community" />
                    <Entry x:Name="Job" WidthRequest="200" Placeholder="Job" />
                    <Entry x:Name="Model" WidthRequest="200" Placeholder="Model" />
                    <Entry x:Name="Elevation" WidthRequest="200" Placeholder="Elevation" />
                    <Entry x:Name="Email" WidthRequest="200" Placeholder="Email" />
                    <Entry x:Name="C_Email" WidthRequest="200" Placeholder="C_Email" />
                    <Entry x:Name="Buyer_Salutation" WidthRequest="200" Placeholder="Buyer_Salutation" />
                    <DatePicker x:Name="ClosingDate" WidthRequest="200" />
                </StackLayout>
                <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">

                    <Entry x:Name="Customer_Name" WidthRequest="200" Placeholder="Customer_Name" />
                    <Entry x:Name="Customer_LName" WidthRequest="200" Placeholder="Customer_LName" />
                    <Entry x:Name="C_Buyer_Salutation" WidthRequest="200" Placeholder="C_Buyer_Salutation" />
                    <Entry x:Name="CoBuyer_Name" WidthRequest="200" Placeholder="CoBuyer_Name" />
                    <Entry x:Name="CoBuyer_LName" WidthRequest="200" Placeholder="CoBuyer_LName" />
                    <Entry x:Name="Address1" WidthRequest="200" Placeholder="Address1" />
                    <Entry x:Name="City" WidthRequest="200" Placeholder="City" />
                </StackLayout>
                <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">

                    <Entry x:Name="Phone1Cell" WidthRequest="200" Placeholder="Phone1Cell" />
                    <Entry x:Name="Phone1Work" WidthRequest="200" Placeholder="Phone1Work" />
                    <Entry x:Name="Phone2Main" WidthRequest="200" Placeholder="Phone2Main" />
                    <Entry x:Name="Phone2Cell" WidthRequest="200" Placeholder="Phone2Cell" />
                    <Entry x:Name="Phone2Work" WidthRequest="200" Placeholder="Phone2Work" />
                    <Entry x:Name="Province" WidthRequest="200" Placeholder="Province" />
                    <Entry x:Name="Zip" WidthRequest="200" Placeholder="Zip" />

                </StackLayout>

            </StackLayout>

            <StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand">

                <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">

                    <Button x:Name="FrontCamera" Text="Front Licence" Clicked="OnFrontCamera" Style="{StaticResource ButtonStyle}" WidthRequest="50" />
                    <Button x:Name="BackCamera" Text="Back Licence" Clicked="OnBackCamera" Style="{StaticResource ButtonStyle}" WidthRequest="50" />

                </StackLayout>

                <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">

                    <Button x:Name="CoFrontCamera" Text="Co-Buyer Front Licence" Clicked="OnCoFrontCamera" Style="{StaticResource ButtonStyle}" WidthRequest="50" />
                    <Button x:Name="CoBackCamera" Text="Co-Buyer Back Licence" Clicked="OnCoBackCamera" Style="{StaticResource ButtonStyle}" WidthRequest="50" />


                </StackLayout>

                <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">

                    <Button x:Name="DepositCheques" Text="Deposit Cheques" Clicked="OnDepositCheques" Style="{StaticResource ButtonStyle}" WidthRequest="50" />
                    <Button x:Name="ScanLicence" Text="Scan Licence" Clicked="OnCameraScan" Style="{StaticResource ButtonStyle}" WidthRequest="50" />

                </StackLayout>

            </StackLayout>

            <StackLayout x:Name="ScannerWrapper">
            </StackLayout>

            <StackLayout>
                <Button x:Name="GenerateContract" Text="Generate Contract" Clicked="OnGenerateContract" Style="{StaticResource ButtonStyle}" WidthRequest="200" />
            </StackLayout>

        </StackLayout>

    </ScrollView>

</ContentPage>

0 个答案:

没有答案