未加星标

Fading Header In List View Using UWP With XAML And C#

字体大小 | |
[系统(windows) 所属分类 系统(windows) | 发布者 店小二05 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

Before reading this article, please go through the article's link, given below.

Introduction To Universal windows Platform (UWP) App Development Using Windows 10 And Visual Studio 2015

FadeHeader behavior fades a ListView or GridView header UIElement, when the user scrolls. UIElement fades out to 0 opacity, when the edge of the header reaches the edge of the visible bounds of the ListElement.

After reading this article, you can learn how to fade a ListView header, when the user scrolls.

The important tools, which are required to develop UWP are given below.

Windows 10 (Recommended) Visual Studio 2015 Community Edition (It is a free software available online)

Now, we can discuss step by step app development, which is given below.

Step 1

Open Visual Studio 2015 -> Start -> New Project-> Select Universal (under Visual C#->Windows)-> Blank app -> Give the suitable name for your app (UWPFadeHeader)->OK.


Fading Header In List View Using UWP With XAML And C#

After choosing the target and minimum platform version for your Windows, Universal Application will support and the project creates App.xaml and MainPage.xaml.


Fading Header In List View Using UWP With XAML And C#

Step 2

Open (double click) the file MainPage.xaml in Solution Explorer and add Microsoft.Toolkit.Uwp.UI.Animations reference in the project.

To add the reference, right click on your project (UWPFadeHeader) and select Manage NuGet Packages.


Fading Header In List View Using UWP With XAML And C#

Choose browse and search Microsoft.Toolkit.Uwp.UI.Animations. Select the package and install it.


Fading Header In List View Using UWP With XAML And C#

Accept the Licence


Fading Header In List View Using UWP With XAML And C#

The reference is added to the project


Fading Header In List View Using UWP With XAML And C#

Step 3

Add TextBlock control, change the name and text property for the title,


Fading Header In List View Using UWP With XAML And C#

Step 4

Add ListView control, which is given below.


Fading Header In List View Using UWP With XAML And C#

Step 5

Add the XAML namespaces, given below and code for Fading List view header in Mainpage.xaml.

xmlns:interactivity="using:Microsoft.Xaml.Interactivity" xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors"<interactivity:Interaction.Behaviors><behaviors:FadeHeaderBehavior/></interactivity:Interaction.Behaviors>
Fading Header In List View Using UWP With XAML And C#

Step 6

Add the List view header with stackpanel, Grid and Textblock for Header information.

<ListView.Header> <Gridx:Name="MyHeaderGrid"MinHeight="100"Background="Blue"Height="174"> <StackPanelVerticalAlignment="Center"HorizontalAlignment="Center"Margin="20,0"> <TextBlockText="ThisIsTheHeader"TextAlignment="Center"FontWeight="Bold"Style="{ThemeResourceTitleTextBlockStyle}"Foreground="White"Margin="0,5"/> <TextBlockText="YourHeaderwillFadewhileyouscrollup."Style="{ThemeResourceSubtitleTextBlockStyle}"Foreground="White"VerticalAlignment="Center"TextAlignment="Center"/></StackPanel> </Grid> </ListView.Header>
Fading Header In List View Using UWP With XAML And C#

Step 7

Add the List view items.

<x:String>India</x:String> <x:String>UnitesStates</x:String> <x:String>SriLanka</x:String> <x:String>China</x:String> <x:String>Canada</x:String> <x:String>Russia</x:String>
Fading Header In List View Using UWP With XAML And C#

Note

Automatically, the code, given below will be generated in XAML code view, while we are done in the design view.

<Pagex:Class="UWPFadeHeader.MainPage"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="using:UWPFadeHeader"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:interactivity="using:Microsoft.Xaml.Interactivity"xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors"mc:Ignorable="d"> <GridBackground="{ThemeResourceApplicationPageBackgroundThemeBrush}"> <TextBlockx:Name="tblTitle"HorizontalAlignment="Left"Margin="61,65,0,0"TextWrapping="Wrap"Text="UWPToolKitFadeHeaderDemo"VerticalAlignment="Top"Height="26"Width="262"FontWeight="Bold"/> <ListViewx:Name="lvFadeHeader"HorizontalAlignment="Left"Height="304"Margin="61,111,0,0"VerticalAlignment="Top"Width="262"> <interactivity:Interaction.Behaviors> <behaviors:FadeHeaderBehavior/></interactivity:Interaction.Behaviors> <ListView.Header> <Gridx:Name="MyHeaderGrid"MinHeight="100"Background="Blue"Height="174"> <StackPanelVerticalAlignment="Center"HorizontalAlignment="Center"Margin="20,0"> <TextBlockText="ThisIsTheHeader"TextAlignment="Center"FontWeight="Bold"Style="{ThemeResourceTitleTextBlockStyle}"Foreground="White"Margin="0,5"/> <TextBlockText="YourHeaderwillFadewhileyouscrollup."Style="{ThemeResourceSubtitleTextBlockStyle}"Foreground="White"VerticalAlignment="Center"TextAlignment="Center"/></StackPanel> </Grid> </ListView.Header> <x:String>India</x:String> <x:String>UnitesStates</x:String> <x:String>SriLanka</x:String> <x:String>China</x:String> <x:String>Canada</x:String> <x:String>Russia</x:String> </ListView> </Grid> </Page>

Step 8

Deploy your app in the local machine and the output of UWPFadeHeader app is given below.


Fading Header In List View Using UWP With XAML And C#

After scrolling the list view item (50% Fade), the screenshot is given below.


Fading Header In List View Using UWP With XAML And C#

After Scrolling the list view item (100% Fade), the screenshot is given below.


Fading Header In List View Using UWP With XAML And C#

Summary

Now, you have successfully tested UWP ToolKit Fading List View Header in Visual C# - UWP environment.

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

主题: C#WPFWindowsVisual StudiVisual StudioUWHead
分页:12
转载请注明
本文标题:Fading Header In List View Using UWP With XAML And C#
本站链接:http://www.codesec.net/view/481854.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(31)