Created
November 29, 2017 16:51
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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