Skip to content

Instantly share code, notes, and snippets.

@MarcosCobena
Created November 29, 2017 16:51
Show Gist options
  • Select an option

  • Save MarcosCobena/06a5050f71b61bad2b1f127dc7200ff3 to your computer and use it in GitHub Desktop.

Select an option

Save MarcosCobena/06a5050f71b61bad2b1f127dc7200ff3 to your computer and use it in GitHub Desktop.
How to implement an attached header view flowing on top of scrollable content in Xamarin.Forms
public class DoubleToTopThicknessConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double height;
try
{
height = (double)value;
}
catch
{
height = 0;
}
var topThickness = new Thickness
{
Top = height
};
return topThickness;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return 0d;
}
}
<?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:converters="clr-namespace:Foo.Converters"
x:Class="Foo.Page">
<ContentPage.Resources>
<ResourceDictionary>
<converters:DoubleToTopThicknessConverter x:Key="DoubleToTopThicknessConverter" />
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<AbsoluteLayout>
<ScrollView
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
Padding="{Binding Source={x:Reference HeaderStackLayout}, Path=Height, Converter={StaticResource DoubleToTopThicknessConverter}}">
<!-- ... -->
</ScrollView>
<StackLayout x:Name="HeaderStackLayout"
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds="0, 0, AutoSize, AutoSize">
<!-- ... -->
</StackLayout>
</AbsoluteLayout>
</ContentPage.Content>
</ContentPage>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment