Xamarin表单 - 使用TranslateTo向上滑动StackLayouts

时间:2018-04-23 09:23:23

标签: c# xaml xamarin.forms

我有一个包含4个StackLayouts的页面,OnAppearing我'滑动'底部3向上,以便第二个顶部位于顶部,创建一个下拉效果,带有一个工具栏供用户单击(iconStack in the XAML),然后向上或向下滑动堆栈。

当我点击它上下滑动时,这很好用,但是当我向上滑动OnAppearing时,有时候它没有完全向上移动,留下一些堆栈可见,我看不清楚原因,或者看到任何东西调试。

我的代码中是否有人能发现任何明显的内容?

protected override async void OnAppearing()
        {
           // here I get some data from the database and set labels etc before I do the next line...
            SlideUp(0);
            base.OnAppearing();
        }
public void SlideUp(uint time)
        {
            TopLayout.TranslateTo(0, (headerStack.Bounds.Height - (TopLayout.Height + headerStack.Height)), time, Easing.Linear);
            headerStack.TranslateTo(0, (headerStack.Bounds.Height - (TopLayout.Height + headerStack.Height)), time, Easing.Linear);
            Articlestack.TranslateTo(0, (headerStack.Bounds.Height - (TopLayout.Height + headerStack.Height)), time, Easing.Linear);
        }

        public void SlideDown(uint time)
        {
            TopLayout.TranslateTo(0, 0, time, Easing.Linear);
            headerStack.TranslateTo(0, 0, time, Easing.Linear);
            Articlestack.TranslateTo(0, 0, time, Easing.Linear);
        }

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="gl_mobile_app.Views.Article.ArticleInfoOpen"
             xmlns:artina="clr-namespace:UXDivers.Artina.Shared;assembly=UXDivers.Artina.Shared"
             xmlns:local="clr-namespace:gl_mobile_app.Views.Templates;assembly=gl_mobile_app"
             xmlns:ratio="clr-namespace:gl_mobile_app;assembly=gl_mobile_app"
             xmlns:custom="clr-namespace:gl_mobile_app.Controls;assembly=gl_mobile_app"
             xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms">

  <ContentPage.ToolbarItems>
    <ToolbarItem Text="Back" Clicked="GoBack" />
  </ContentPage.ToolbarItems>

  <ContentPage.Content>
    <ScrollView>
      <Grid BackgroundColor="#ede8db" x:Name="articleGrid" >
        <Grid.RowDefinitions>
          <RowDefinition  Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition  Height="Auto"/>
          <RowDefinition  Height="Auto"/>
          <RowDefinition  Height="Auto"/>
        </Grid.RowDefinitions>

        <ffimageloading:CachedImage Grid.Row="0" Aspect="AspectFill" Source="KevingroveCarouselImg" AbsoluteLayout.LayoutBounds="1,1,1,1" AbsoluteLayout.LayoutFlags="All" x:Name="bigImg"
                    HeightRequest="{artina:OnOrientationDouble PortraitPhone=200, PortraitTablet=400, LandscapeTablet=200 }" />

        <artina:Button Margin="10,10,10,10" x:Name="ImgZoom" Clicked="EnlargeImage" HorizontalOptions="End" VerticalOptions="Start" Image="IncreaseImageIcon.png" BackgroundColor="Transparent"  HeightRequest="30" WidthRequest="30"/>

        <StackLayout Grid.Row="1" Orientation="Horizontal" Margin="-6" Padding="30,2,30,2" x:Name="iconStack" HorizontalOptions="FillAndExpand" BackgroundColor="#ede8db" >
          <Label HorizontalTextAlignment="Center" Text="{x:Static ratio:Ingeniuus.TOILET}" Style="{StaticResource Ingeniuus}" TextColor="Gray" FontSize ="{artina:OnOrientationDouble PortraitPhone=20, LandscapePhone=18, PortraitTablet=25, LandscapeTablet=20 }" />
          <Label HorizontalTextAlignment="Center" Text="{x:Static ratio:Ingeniuus.WHEELCHAIR}" Style="{StaticResource Ingeniuus}" TextColor="Gray" FontSize ="{artina:OnOrientationDouble PortraitPhone=20, LandscapePhone=18, PortraitTablet=25, LandscapeTablet=20 }" />
          <Label HorizontalTextAlignment="Center" Text="{x:Static ratio:Ingeniuus.CUTLERY}" Style="{StaticResource Ingeniuus}" TextColor="Gray" FontSize="{artina:OnOrientationDouble PortraitPhone=20, LandscapePhone=18, PortraitTablet=25, LandscapeTablet=20 }" />
          <Label HorizontalTextAlignment="Center" Text="{x:Static ratio:Ingeniuus.BABY}" Style="{StaticResource Ingeniuus}" TextColor="Gray" FontSize="{artina:OnOrientationDouble PortraitPhone=20, LandscapePhone=18, PortraitTablet=25, LandscapeTablet=20 }" />
          <Label HorizontalTextAlignment="Center" Text="{x:Static ratio:Ingeniuus.WIFI}" Style="{StaticResource Ingeniuus}" TextColor="Gray" FontSize="{artina:OnOrientationDouble PortraitPhone=20, LandscapePhone=18, PortraitTablet=25, LandscapeTablet=20 }" />
          <Label HorizontalTextAlignment="Center" Text="{x:Static ratio:Ingeniuus.CAMERA}" Style="{StaticResource Ingeniuus}" TextColor="Gray" FontSize="{artina:OnOrientationDouble PortraitPhone=20, LandscapePhone=18, PortraitTablet=25, LandscapeTablet=20 }" />
          <Label HorizontalTextAlignment="Center" Text="{x:Static ratio:Ingeniuus.MAP_MARKER}" Style="{StaticResource Ingeniuus}" TextColor="Gray" FontSize="{artina:OnOrientationDouble PortraitPhone=20, LandscapePhone=18, PortraitTablet=25, LandscapeTablet=20 }" />
          <Label x:Name="expand"  HorizontalTextAlignment="Center" HorizontalOptions="EndAndExpand" Text="{x:Static ratio:FontAwesome.CHEVRON_CIRCLE_DOWN}" Style="{StaticResource FontIcon}" TextColor="Gray" FontSize="{artina:OnOrientationDouble PortraitPhone=20, LandscapePhone=18, PortraitTablet=25, LandscapeTablet=20 }" />
        </StackLayout>

        <StackLayout x:Name="TopLayout" Padding="30,0,30,0" VerticalOptions="FillAndExpand" Grid.Row="2" BackgroundColor="#ede8db">

          <StackLayout Orientation="Horizontal" x:Name="MapMarker" Opacity="1.0">
            <Label HorizontalTextAlignment="Center" Text="{x:Static ratio:Ingeniuus.MAP_MARKER}" Style="{StaticResource Ingeniuus}" TextColor="Black" FontSize="20" WidthRequest="{artina:OnOrientationDouble PortraitPhone=20,PortraitTablet=40, LandscapeTablet=40 }" />
            <Label Text="Address" VerticalOptions="Center" HorizontalOptions="StartAndExpand" FontAttributes="Bold"  />
          </StackLayout>

          <StackLayout x:Name="AddressStack" >
            <StackLayout.Padding>
              <OnIdiom x:TypeArguments="Thickness">
                <OnIdiom.Phone>
                  <OnPlatform x:TypeArguments="Thickness" iOS="34.5,0,0,0" Android="34.5,0,0,0" />
                </OnIdiom.Phone>
                <OnIdiom.Tablet>
                  <OnPlatform x:TypeArguments="Thickness" iOS="54.5,0,0,0" Android="54.5,0,0,0" />
                </OnIdiom.Tablet>
              </OnIdiom>
            </StackLayout.Padding>
            <Label x:Name="AddressLabel" >
              <Label.FontFamily>
                <OnPlatform x:TypeArguments="x:String">
                  <On Platform="iOS" Value="HelveticaNeue-Roman" />
                  <On Platform="Android" Value="HelveticaNeue-Roman.otf#HelveticaNeue-Roman" />
                </OnPlatform>
              </Label.FontFamily>
            </Label>
          </StackLayout>

          <StackLayout Orientation="Horizontal" x:Name="clock" Opacity="1.0">
            <Label HorizontalTextAlignment="Center" Text="{x:Static ratio:Ingeniuus.CLOCK}" Style="{StaticResource Ingeniuus}" TextColor="Black" FontSize="20" WidthRequest="{artina:OnOrientationDouble PortraitPhone=20,PortraitTablet=40, LandscapeTablet=40 }"/>
            <Label Text="Opening Times" VerticalOptions="Center" HorizontalOptions="StartAndExpand"  FontAttributes="Bold"/>
          </StackLayout>

          <StackLayout x:Name="OpeningTimesStack">
            <StackLayout.Padding>
              <OnIdiom x:TypeArguments="Thickness">
                <OnIdiom.Phone>
                  <OnPlatform x:TypeArguments="Thickness" iOS="34.5,0,0,0" Android="34.5,0,0,0" />
                </OnIdiom.Phone>
                <OnIdiom.Tablet>
                  <OnPlatform x:TypeArguments="Thickness" iOS="54.5,0,0,0" Android="54.5,0,0,0" />
                </OnIdiom.Tablet>
              </OnIdiom>
            </StackLayout.Padding>
            <Label Grid.Row="1" x:Name="OpeningTimesLabel" >
              <Label.FontFamily>
                <OnPlatform x:TypeArguments="x:String">
                  <On Platform="iOS" Value="HelveticaNeue-Roman" />
                  <On Platform="Android" Value="HelveticaNeue-Roman.otf#HelveticaNeue-Roman" />
                </OnPlatform>
              </Label.FontFamily>
            </Label>
          </StackLayout>
          <StackLayout x:Name="Empty2" HeightRequest="10" />


        </StackLayout>

        <StackLayout Grid.Row="4" x:Name="Articlestack">
          <ListView BackgroundColor="White" Margin="-4" Parent="30,0,30,0" x:Name="ArticleListView"  CachingStrategy="RetainElement" HasUnevenRows="True" SeparatorVisibility="None" VerticalOptions="FillAndExpand" HeightRequest="6000" >
            <ListView.ItemTemplate>
              <DataTemplate x:Name="dataTemp">
                <ViewCell>
                  <local:ArticleContentItemTemplate />
                </ViewCell>
              </DataTemplate>
            </ListView.ItemTemplate>
          </ListView>
        </StackLayout>

      </Grid>
    </ScrollView>
  </ContentPage.Content>
</ContentPage>

1 个答案:

答案 0 :(得分:1)

您可以将可见性设置为false,但是您会丢失一些翻译动画而不是翻译动画,之后删除可见性,这将使其保持顺畅。