Esempio n. 1
0
        /// <summary>
        /// 使用在导航过程中传递的内容填充页。在从以前的会话
        /// 重新创建页时,也会提供任何已保存状态。
        /// </summary>
        /// <param name="sender">
        /// 事件的来源; 通常为 <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">事件数据,其中既提供在最初请求此页时传递给
        /// <see cref="Frame.Navigate(Type, object)"/> 的导航参数,又提供
        /// 此页在以前会话期间保留的状态的
        /// 字典。 首次访问页面时,该状态将为 null。</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // TODO: 创建适用于问题域的合适数据模型以替换示例数据
            if ((string)e.NavigationParameter == "ReadList")
            {
                var group = await ReadListUtil.GetReadList();

                this.DefaultViewModel["Group"] = group;
                this.DefaultViewModel["Items"] = group.Items;
            }
            else if ((string)e.NavigationParameter == "FavList")
            {
                var group = await ReadListUtil.GetFavList();

                this.DefaultViewModel["Group"] = group;
                this.DefaultViewModel["Items"] = group.Items;
            }
            else
            {
                var group = await SampleDataSource.GetGroupAsync((string)e.NavigationParameter);

                this.DefaultViewModel["Group"] = group;
                this.DefaultViewModel["Items"] = group.Items;
            }
        }
Esempio n. 2
0
        //CommandBar处理
        private async void AppBarClick(object sender, RoutedEventArgs e)
        {
            string id             = (DefaultViewModel["Item"] as SampleDataItem).UniqueId;
            var    resourceLoader = ResourceLoader.GetForCurrentView("Resources");

            switch ((sender as AppBarButton).Tag as string)
            {
            case "AddFav":
                ReadListUtil.AddFavId(id);
                //Lock Screen Badge
                Global.Current.Notifications.UpdateBadgeWithNumber(1);
                //Toast Notification
                ToastUtil.ShowToast(resourceLoader.GetString("HubTitleText"), resourceLoader.GetString("AddFavSuccessText"));
                this.AddFav.Visibility    = Visibility.Collapsed;
                this.RemoveFav.Visibility = Visibility.Visible;
                break;

            case "RemoveFav":
                ReadListUtil.RemoveFavId(id);
                //Lock Screen Badge
                Global.Current.Notifications.UpdateBadgeWithNumber(2);
                //Toast Notification
                ToastUtil.ShowToast(resourceLoader.GetString("HubTitleText"), resourceLoader.GetString("RemoveFavSuccessText"));
                this.AddFav.Visibility    = Visibility.Visible;
                this.RemoveFav.Visibility = Visibility.Collapsed;
                break;

            case "Share":
                (DefaultViewModel["Item"] as SampleDataItem).Title.RegisterForShare(resourceLoader.GetString("ShareTitle"), resourceLoader.GetString("ShareDesc"));
                break;

            case "Save":
            {
                //检测是否有sd卡,如果没有,就弹出toast提示
                if (!await FileEx.IsAvailableRemoveDevice("SD"))
                {
                    ToastUtil.ShowToast(resourceLoader.GetString("HubTitleText"), resourceLoader.GetString("NoSD"));
                    return;
                }
                //保存文件到sd卡
                string fileName = string.Empty;
                foreach (StorageTarget item in Enum.GetValues(typeof(StorageTarget)))
                {
                    if (item.ToString() == "SD")
                    {
                        await resourceLoader.GetString("HTMLContent").Save("NewsSample", "saved.html", item);

                        ToastUtil.ShowToast(resourceLoader.GetString("HubTitleText"), resourceLoader.GetString("SaveSDSuccessText"));
                    }
                }
            }

            break;

            default:
                break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 在单击某个项时进行调用。
        /// </summary>
        /// <param name="sender">显示所单击项的 GridView。</param>
        /// <param name="e">描述所单击项的事件数据。</param>
        private void ItemView_ItemClick(object sender, ItemClickEventArgs e)
        {
            // 导航至相应的目标页,并
            // 通过将所需信息作为导航参数传入来配置新页
            var itemId = ((SampleDataItem)e.ClickedItem).UniqueId;

            ((SampleDataItem)e.ClickedItem).Read = true;
            ReadListUtil.SaveReadId(itemId);

            TileUitl.UpdateTile(((SampleDataItem)e.ClickedItem).Title);

            this.Frame.Navigate(typeof(ItemPage), itemId);
        }
        /// <summary>
        /// 显示在 <see cref="ItemPage"/> 中单击的项的详细信息。
        /// </summary>
        /// <param name="sender">Click 事件的源。</param>
        /// <param name="e">有关 Click 事件的默认信息。</param>
        private void ItemView_ItemClick(object sender, ItemClickEventArgs e)
        {
            var itemId = ((SampleDataItem)e.ClickedItem).UniqueId;

            ((SampleDataItem)e.ClickedItem).Read = true;
            ReadListUtil.SaveReadId(itemId);

            TileUitl.UpdateTile(((SampleDataItem)e.ClickedItem).Title);

            if (!Frame.Navigate(typeof(ItemPage), itemId))
            {
                throw new Exception(this.resourceLoader.GetString("NavigationFailedExceptionMessage"));
            }
        }
Esempio n. 5
0
        private async Task GetSampleDataAsync()
        {
            if (this._groups.Count != 0)
            {
                return;
            }

            Uri dataUri;

            if (Windows.Globalization.ApplicationLanguages.Languages[0] == "zh-Hans-CN")
            {
                dataUri = new Uri("ms-appx:///DataModel/SampleDataCN.json");
            }
            else
            {
                dataUri = new Uri("ms-appx:///DataModel/SampleData.json");
            }

            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);

            string jsonText = await FileIO.ReadTextAsync(file);

            JsonObject jsonObject = JsonObject.Parse(jsonText);
            JsonArray  jsonArray  = jsonObject["Groups"].GetArray();

            foreach (JsonValue groupValue in jsonArray)
            {
                JsonObject      groupObject = groupValue.GetObject();
                SampleDataGroup group       = new SampleDataGroup(groupObject["UniqueId"].GetString(),
                                                                  groupObject["Title"].GetString(),
                                                                  groupObject["Subtitle"].GetString(),
                                                                  groupObject["ImagePath"].GetString(),
                                                                  groupObject["Description"].GetString());

                foreach (JsonValue itemValue in groupObject["Items"].GetArray())
                {
                    JsonObject itemObject = itemValue.GetObject();
                    group.Items.Add(new SampleDataItem(itemObject["UniqueId"].GetString(),
                                                       itemObject["Title"].GetString(),
                                                       itemObject["Subtitle"].GetString(),
                                                       itemObject["ImagePath"].GetString(),
                                                       itemObject["Description"].GetString(),
                                                       itemObject["Content"].GetString(),
                                                       ReadListUtil.IsRead(itemObject["UniqueId"].GetString())
                                                       ));
                }
                this.Groups.Add(group);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 使用在导航过程中传递的内容填充页。  在从以前的会话
        /// 重新创建页时,也会提供任何已保存状态。
        /// </summary>
        /// <param name="sender">
        /// 事件的来源;通常为 <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">事件数据,其中既提供在最初请求此页时传递给
        /// <see cref="Frame.Navigate(Type, object)"/> 的导航参数,又提供
        /// 此页在以前会话期间保留的状态的
        /// 字典。首次访问页面时,该状态将为 null。</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // TODO: 创建适用于问题域的合适数据模型以替换示例数据
            var item = await SampleDataSource.GetItemAsync((string)e.NavigationParameter);

            this.DefaultViewModel["Item"] = item;

            this.AddFav.Visibility    = (ReadListUtil.IsFav(item.UniqueId)) ? Visibility.Collapsed : Visibility.Visible;
            this.RemoveFav.Visibility = (ReadListUtil.IsFav(item.UniqueId)) ? Visibility.Visible : Visibility.Collapsed;

            var    resourceLoader = ResourceLoader.GetForCurrentView("Resources");
            string aaa            = resourceLoader.GetString("HTMLContent");

            aaa = aaa.Replace("<!DOCTYPE html><html lang='en' xmlns='http://www.w3.org/1999/xhtml'><head>    <meta charset='utf-8' />    <title></title></head><body>", "<!DOCTYPE html><html lang='en' xmlns='http://www.w3.org/1999/xhtml'><head>    <meta charset='utf-8' />    <title></title></head><body bgcolor='#1f1f1f' text='#ffffff'>");
            this.NewsBrowser.NavigateToString(aaa);
        }
Esempio n. 7
0
        /// <summary>
        /// 使用在导航过程中传递的内容填充页。  在从以前的会话
        /// 重新创建页时,也会提供任何已保存状态。
        /// </summary>
        /// <param name="sender">
        /// 事件的来源;通常为 <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">事件数据,其中既提供在最初请求此页时传递给
        /// <see cref="Frame.Navigate(Type, object)"/> 的导航参数,又提供
        /// 此页在以前会话期间保留的状态的
        /// 字典。首次访问页面时,该状态将为 null。</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // TODO: 创建适用于问题域的合适数据模型以替换示例数据
            if ((string)e.NavigationParameter == "ReadList")
            {
                this.DefaultViewModel["Item"] = await ReadListUtil.GetReadList();
            }
            else if ((string)e.NavigationParameter == "FavList")
            {
                this.DefaultViewModel["Item"] = ReadListUtil.GetFavList();
            }
            else
            {
                var item = await SampleDataSource.GetItemAsync((string)e.NavigationParameter);

                this.DefaultViewModel["Item"] = item;
                this.AddFav.Visibility        = (ReadListUtil.IsFav(item.UniqueId)) ? Visibility.Collapsed : Visibility.Visible;
                this.RemoveFav.Visibility     = (ReadListUtil.IsFav(item.UniqueId)) ? Visibility.Visible : Visibility.Collapsed;
            }
        }
        /// <summary>
        /// 在单击节内的项时调用。
        /// </summary>
        /// <param name="sender">GridView 或 ListView
        /// 为 ListView)。</param>
        /// <param name="e">描述所单击项的事件数据。</param>
        void ItemView_ItemClick(object sender, ItemClickEventArgs e)
        {
            // 导航至相应的目标页,并
            // 通过将所需信息作为导航参数传入来配置新页
            if (e.ClickedItem is SampleDataItem)
            {
                var itemId = ((SampleDataItem)e.ClickedItem).UniqueId;

                ((SampleDataItem)e.ClickedItem).Read = true;
                ReadListUtil.SaveReadId(itemId);

                TileUitl.UpdateTile(((SampleDataItem)e.ClickedItem).Title);

                this.Frame.Navigate(typeof(ItemPage), itemId);
            }
            else if (e.ClickedItem is SampleDataGroup)
            {
                var groupId = ((SampleDataGroup)e.ClickedItem).UniqueId;
                if (!Frame.Navigate(typeof(SectionPage), groupId))
                {
                    throw new Exception(this.resourceLoader.GetString("NavigationFailedExceptionMessage"));
                }
            }
            else if (e.ClickedItem is HeroImageItem)
            {
                Frame.Navigate(typeof(ItemPage), "Group-3-Item-4");
            }
            else if (e.ClickedItem is AboutItem)
            {
                var tag = ((AboutItem)e.ClickedItem).tag;
                if (tag == "ReadList") 
                {
                    Frame.Navigate(typeof(SectionPage), "ReadList");
                }else if(tag=="FavList")
                {
                    Frame.Navigate(typeof(SectionPage), "FavList");
                }
            }
        }