|
| 1 | +# FadeHeader |
| 2 | + |
| 3 | +The **FadeHeader behavior** fades a ListView or GridView Header UIElement when the user scrolls. The UIElement fades out to 0 opacity when the edge of the Header reaches the edge of the visible bounds of the ListElement. |
| 4 | + |
| 5 | +## Syntax |
| 6 | + |
| 7 | +### XAML Implementation ### |
| 8 | + |
| 9 | +**Implicit usage**: |
| 10 | + |
| 11 | +Automatically detects the Header element by finding the ListViewBase (note: GridView uses ListViewBase) |
| 12 | + |
| 13 | +```xaml |
| 14 | + |
| 15 | + <interactivity:Interaction.Behaviors> |
| 16 | + <behaviors:FadeHeaderBehavior /> |
| 17 | + </interactivity:Interaction.Behaviors> |
| 18 | + |
| 19 | +``` |
| 20 | + |
| 21 | + |
| 22 | +**Explicit usage**: |
| 23 | + |
| 24 | +Set the ElementName property using the UIElement of the Header manually |
| 25 | + |
| 26 | +```xaml |
| 27 | + |
| 28 | + <interactivity:Interaction.Behaviors> |
| 29 | + <behaviors:FadeHeaderBehavior HeaderElement="{Binding ElementName=MyHeaderGrid}" /> |
| 30 | + </interactivity:Interaction.Behaviors> |
| 31 | + |
| 32 | +``` |
| 33 | + |
| 34 | +### C# Implementation ### |
| 35 | + |
| 36 | +Implicit usage: |
| 37 | + |
| 38 | +```csharp |
| 39 | + |
| 40 | + Microsoft.Xaml.Interactivity.Interaction.GetBehaviors(MyListView).Add(new FadeHeaderBehavior()); |
| 41 | + |
| 42 | +``` |
| 43 | + |
| 44 | +Explicit usage: |
| 45 | + |
| 46 | +```csharp |
| 47 | + |
| 48 | + Microsoft.Xaml.Interactivity.Interaction.GetBehaviors(MyListView).Add(new FadeHeaderBehavior { HeaderElement = MyHeaderGrid }); |
| 49 | + |
| 50 | +``` |
| 51 | + |
| 52 | + |
| 53 | +## Example ## |
| 54 | + |
| 55 | +```xaml |
| 56 | + |
| 57 | + <ListView x:Name="MyListView"> |
| 58 | + <interactivity:Interaction.Behaviors> |
| 59 | + <behaviors:FadeHeaderBehavior /> |
| 60 | + </interactivity:Interaction.Behaviors> |
| 61 | + <ListView.Header> |
| 62 | + <Grid x:Name="MyHeaderGrid" |
| 63 | + MinHeight="250" |
| 64 | + Background="{StaticResource Brush-Blue-01}"> |
| 65 | + <StackPanel VerticalAlignment="Center" |
| 66 | + HorizontalAlignment="Center" |
| 67 | + Margin="20,0"> |
| 68 | + <TextBlock Text="This Is The Header" |
| 69 | + TextAlignment="Center" |
| 70 | + FontWeight="Bold" |
| 71 | + Style="{ThemeResource TitleTextBlockStyle}" |
| 72 | + Foreground="{StaticResource Brush-White}" |
| 73 | + Margin="0,5" /> |
| 74 | + <TextBlock Text="It starts with 100% opacity but will fade to 0% as you scroll up." |
| 75 | + Style="{ThemeResource SubtitleTextBlockStyle}" |
| 76 | + Foreground="{StaticResource Brush-White}" |
| 77 | + VerticalAlignment="Center" |
| 78 | + TextAlignment="Center" /> |
| 79 | + </StackPanel> |
| 80 | + </Grid> |
| 81 | + </ListView.Header> |
| 82 | +</ListView> |
| 83 | + |
| 84 | +``` |
| 85 | + |
| 86 | + |
| 87 | +[FadeHeader Behavior Sample Page Source](https://github.com/Microsoft/UWPCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/FadeHeader) |
| 88 | + |
| 89 | +Please view the [toolkit sample application](https://github.com/Microsoft/UWPCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.SampleApp) for the UWP Community Toolkit for current samples and example code. |
| 90 | + |
| 91 | +## Example Image |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +## Requirements (Windows 10 Device Family) |
| 96 | + |
| 97 | +| [Device family](http://go.microsoft.com/fwlink/p/?LinkID=526370) | Universal, 10.0.10586.0 or higher | |
| 98 | +| --- | --- | |
| 99 | +| Namespace | Microsoft.Toolkit.Uwp.UI.Animations | |
| 100 | + |
| 101 | +## API |
| 102 | + |
| 103 | +* [FadeHeader source code](https://github.com/Microsoft/UWPCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/FadeHeader.cs) |
| 104 | + |
| 105 | + |
0 commit comments