Windows 8實用竅門系列:9.Windows 8中使用FlipView

來源:互聯網
上載者:User

  FlipView控制項類似於翻頁控制項,並且是現成的翻頁按鈕,你只需要為其增加資料項目即可。本文講述兩種方式的FlipView項目和展示。

  一:直接前台FlipViewItem

        <FlipView>            <FlipViewItem>                <Image Stretch="Uniform" Source="http://imgcache.qq.com/club/item/wallpic/items/2/3802/760_300_3802.jpg"/>            </FlipViewItem>            <FlipViewItem>                <Image Stretch="Uniform" Source="http://imgcache.qq.com/club/item/wallpic/items/3/4023/c_760_300_4023.jpg"/>            </FlipViewItem>            <FlipViewItem>                <Image Stretch="Uniform" Source="http://imgcache.qq.com/club/item/wallpic/items/3/3673/c_760_300_3673.jpg"/>            </FlipViewItem>            <FlipViewItem>                <Image Stretch="Uniform" Source="http://imgcache.qq.com/club/item/wallpic/items/7/4017/c_760_300_4017.jpg"/>            </FlipViewItem>            <FlipViewItem>                <Image Stretch="Uniform" Source="http://imgcache.qq.com/club/item/wallpic/items/2/3972/c_760_300_3972.jpg"/>            </FlipViewItem>        </FlipView>

  效果如下:

  二:前台設定DataTemplate,後台實體集方式添加資料項目。

        <FlipView Name="fvShow" Margin="100">            <FlipView.ItemTemplate>                <DataTemplate>                    <Grid>                        <Grid.Background>                            <ImageBrush Stretch="Uniform" ImageSource="{Binding ImgUrl}"/>                        </Grid.Background>                        <TextBlock  Height="30" VerticalAlignment="Top" HorizontalAlignment="Left"                                    Margin="180 300 0 0" FontSize="20" Foreground="Blue" Text="{Binding ImgName}"/>                        <TextBlock  Height="30" VerticalAlignment="Top" HorizontalAlignment="Left"                                    Margin="180 350 0 0" FontSize="20" Foreground="Blue" Text="{Binding ImgAddr}"/>                    </Grid>                </DataTemplate>            </FlipView.ItemTemplate>        </FlipView>
   /// <summary>    /// 可用於自身或導航至 Frame 內部的空白頁。    /// </summary>    public sealed partial class MainPage : Page    {        public MainPage()        {            this.InitializeComponent();            this.fvShow.ItemsSource = ImgModel.GetImgData();        }        /// <summary>        /// 在此頁將要在 Frame 中顯示時進行調用。        /// </summary>        /// <param name="e">描述如何訪問此頁的事件數目據。Parameter        /// 屬性通常用於配置頁。</param>        protected override void OnNavigatedTo(NavigationEventArgs e)        {        }    }    /// <summary>    /// 圖片實體    /// </summary>    public class ImgModel    {        /// <summary>        /// 圖片名字        /// </summary>        public string ImgName { get; set; }        /// <summary>        /// 圖片地址        /// </summary>        public string ImgAddr { get; set; }        /// <summary>        /// 圖片URL        /// </summary>        public string ImgUrl { get; set; }        public static List<ImgModel> GetImgData()        {            List<ImgModel> list = new List<ImgModel>();            list.Add(new ImgModel() { ImgName = "名字:北京冬景", ImgAddr = "地址:北京市", ImgUrl = "http://imgcache.qq.com/club/item/wallpic/items/2/3922/760_300_3922.jpg" });            list.Add(new ImgModel() { ImgName = "名字:上海春景", ImgAddr = "地址:上海市", ImgUrl = "http://imgcache.qq.com/club/item/wallpic/items/7/3147/760_300_3147.jpg" });            list.Add(new ImgModel() { ImgName = "名字:天津秋景", ImgAddr = "地址:天津市", ImgUrl = "http://imgcache.qq.com/club/item/wallpic/items/6/3966/c_760_300_3966.jpg" });            list.Add(new ImgModel() { ImgName = "名字:海南夏景", ImgAddr = "地址:海南市", ImgUrl = "http://imgcache.qq.com/club/item/wallpic/items/5/3695/760_300_3695.jpg" });            list.Add(new ImgModel() { ImgName = "名字:成都風景", ImgAddr = "地址:成都市", ImgUrl = "http://imgcache.qq.com/club/item/wallpic/items/8/2518/760_300_2518.jpg" });            return list;        }    }

  看此方式的效果如下:

  最後如需源碼請點擊 Win8FlipView.rar 下載。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.