Windows Phone 8.1 New Features-Flipview of controls

Source: Internet
Author: User

This article introduces the new FlipView control in Windows Phone 8.1, which is named in the Chinese name: Flip view.

Although it sounds a bit awkward, but its use of people will certainly not unfamiliar. In Windows Phone 8, we often add a boot page for the first launch of the app, a few guided images to display, and then click OK to enter the app. We'll write a control for it, and Flipview can do it easily. Flipview can not only be used as a picture navigation control, but also as text switch, step switch and so on. Let's look at a simple example:

<FlipView>    <TextBlockText= "1"HorizontalAlignment= "Center"VerticalAlignment= "Center"FontSize= "$"/>    <TextBlockText= "2"HorizontalAlignment= "Center"VerticalAlignment= "Center"FontSize= "$"/>    <TextBlockText= "3"HorizontalAlignment= "Center"VerticalAlignment= "Center"FontSize= "$"/></FlipView>

We have added three elements to Flipview, respectively, and 3. To see how the results work:

For example, we can display the 3 by horizontal swipe, but not the loop display, that is, you cannot swipe from 1 to the right to display 3, or from 3 to the left to display 1.

Similar to other collection class controls, FlipView supports adding elements directly or binding ItemsSource to a data source. Here are some of the two ways we can illustrate each:

(1) add element collection directly

<FlipViewSelectedIndex= "0">    <TextBlockText= "TextBlock"HorizontalAlignment= "Center"VerticalAlignment= "Center"FontSize= "The "/>    <ImageSource= "Assets/setting.png"Width= "+"/>    <BorderBackground= "Green"Width= "$"Height= "$"/></FlipView>

We have added three different types of elements. At the same time we can determine the initial display element by modifying the SelectedIndex property. To see how the results work:

(2) Binding via ItemsSource property

<FlipViewx:name= "Demoflipview">    <flipview.itemtemplate>        <DataTemplate>            <GridBackground= "Yellowgreen">                <TextBlockHorizontalAlignment= "Center"VerticalAlignment= "Center"Text="{Binding Democontent}"FontSize= "$"/>            </Grid>        </DataTemplate>    </flipview.itemtemplate>    <Flipview.itemspanel>        <itemspaneltemplate>            <StackPanelOrientation= "Vertical"/>        </itemspaneltemplate>    </Flipview.itemspanel></FlipView>

We have specified ItemTemplate and itemspanel for FlipView. The Itemspanel is a vertically arranged StackPanel so that we can display the elements by sliding up and down. Take a look at data binding in the background code:

protected Override Async voidonnavigatedto (NavigationEventArgs e) {List<Demo> demolist =NewList<demo>(); Demolist.add (NewDemo () {democontent ="First Item"}); Demolist.add (NewDemo () {democontent ="Second Item" }); Demolist.add (NewDemo () {democontent ="Last Item" }); Demoflipview.itemssource=demolist;}
 Public class demo{    publicstringgetset;}

Binding code is very simple, here do not do too much explanation, to see the effect of running:

, three elements are displayed by sliding up and down. Again, we can use code to control which element FlipView displays. For example, an auto-browsing album, every few seconds to transform a picture, to the last one, and then re-come. Take a look at the code implementation:

New= timespan.fromseconds (1.0+ = (sender, e) +=    {if1  )        demoflipview.selectedindex++    ; Else 0;});           _timer. Start ();

As the above code can achieve FlipView automatic switching effect, here we do not need to explain.

Well, here we will put the basic application of FlipView, hope to everyone has help, thank you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.