惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
量子位
Blog — PlanetScale
Blog — PlanetScale
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
D
Docker
罗磊的独立博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
IT之家
IT之家
MyScale Blog
MyScale Blog
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - 阳光追梦

Xamarin Android ListView 控件使用 Xamarin Android -创建Splash Screen (一) Web Api 2 接口API文档美化 高仿Windows Phone QQ登录界面 Windows Phone 8 显示当前项目的使用内存,最大峰值,最大内存上限 Windows Phone 8 下载文件进度 Windows Phone 8 开发资料 jquery 选择器大全 转载:SQL 递归树 子父节点相互查询 Silverlight 代水印的查询文本框 Style Create a Settings Page for Windows phone Android 4.1 新增UI模板 Winwdos Phone 从手机中读取相册图片 windows phone 学习笔记 四 Windows Phone 7 学习笔记三------文本框输入作用域 2011 西安世界园艺博览会-----Silverlight 电子地图上线 Linq 读取简单的XML数据 Esri for Window Phone 7(一) 加载BingMap Windows Phone 7 学习笔记------常用工具(二)
windows phone 7 学习笔记 五 TileSample
阳光追梦 · 2012-01-04 · via 博客园 - 阳光追梦
WP 7 为应用程序设置为瓦片.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace WPTileSample
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private static readonly string SecondaryTileUriSource = "Source=SeconaryTile";

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            //查找当前是否是瓦片
            ShellTile secondaryTile = this.FindTile(SecondaryTileUriSource);
            this.cbShowTile.IsChecked = secondaryTile != null;
        }

        /// <summary>
        /// 查找当前名称是否在瓦片中
        /// </summary>
        /// <param name="partOfUri"></param>
        /// <returns></returns>
        private ShellTile FindTile(string partOfUri)
        { 
            //当前应该程序是不是瓦片
            ShellTile shellTile = ShellTile.ActiveTiles.FirstOrDefault(
                tile => tile.NavigationUri.ToString().Contains(partOfUri));

            return shellTile;
        }

        private void cbShowTile_Checked(object sender, RoutedEventArgs e)
        {
            // secondary tiles can be created only as the result
            // of user input in an application
            ShellTile tile = this.FindTile(SecondaryTileUriSource);

            if (tile == null)
            {
                // because the UI will navigate to Start
                // when a new secondary tile is created
                // only one secondary tile can be created at a time
                StandardTileData tileData = this.GetSecondaryTileData();

                // having a unique NavigationUri is necessary for distinguishing this tile
                string tileUri = string.Concat("/MainPage.xaml?", SecondaryTileUriSource);
                ShellTile.Create(new Uri(tileUri, UriKind.Relative), tileData);
            }
        }

        //删除瓦片
        private void cbShowTile_Unchecked(object sender, RoutedEventArgs e)
        {
            ShellTile tile = this.FindTile(SecondaryTileUriSource);
            if (tile != null)
            {
                tile.Delete();
                MessageBox.Show("Secondary tile deleted.");
            }
        }

        /// <summary>
        /// 设置瓦片
        /// </summary>
        /// <returns></returns>
        private StandardTileData GetSecondaryTileData()
        {
            StandardTileData tileData = new StandardTileData
            {
                Title = "Secondary Tile",
                BackgroundImage = new Uri("/Images/logo.png", UriKind.Relative),
                Count = 5,
                BackTitle = "Secondary Tile",
                BackBackgroundImage = new Uri("", UriKind.Relative),
                BackContent = "WPG Add Remove Tile Sample"
            };

            return tileData;
        }
    }
}

0VG3$25L$FX242[J5UN0HFX

posted @ 2012-01-04 20:44  阳光追梦  阅读(412)  评论()    收藏  举报