private void LoadTemplates() { Items.Clear(); PageItems.Clear(); int count = 0; string[] files = Directory.GetFiles(Constants.TemplateThumbnailRoot); if (files == null) { Debug.Write("Error: Reading files from the souvenirs image folder returns null."); return; } foreach (var file in files) { string name = Path.GetFileNameWithoutExtension(file); TemplateModel template = new TemplateModel(name, Path.GetFullPath(file), name); if (count < Constants.NumberOfItemsPerPage) { PageItems.Add(template); ++count; } Items.Add(template); } PageCursor = 1; NumberOfPages = (Items.Count + Constants.NumberOfItemsPerPage - 1) / Constants.NumberOfItemsPerPage; PageBackCommand.RaiseCanExecuteChanged(); PageForwardCommand.RaiseCanExecuteChanged(); }
private void BuildMenu() { var settingsItem = new SDK.Model.MenuItem("Settings", "appbar_settings", new SDK.Tools.Thickness(5, 5, 5, 5), true); settingsItem.Click += (s, e) => { MainWindow.SettingsFlyout.Width = MainWindow.ProfileSwitcher.ActualWidth + MainWindow.FLYOUT_WIDTH_MIN; if (!MainWindow.SettingsFlyout.IsOpen) { MainWindow.SettingsFlyout.Visibility = Visibility.Hidden; } MainWindow.SettingsFlyout.IsOpen = true; }; var consoleItem = new SDK.Model.MenuItem("Console", "appbar_app", new SDK.Tools.Thickness(5, 7, 5, 7), true); consoleItem.Click += (s, e) => { ShowWindow(App.Kernel.Get <Logger>().Container); MainWindow.MenuFlyout.IsOpen = false; }; var aboutItem = new SDK.Model.MenuItem("About", "appbar_information", new SDK.Tools.Thickness(9, 4, 9, 4), true); aboutItem.Click += (s, e) => { ShowWindow(App.Kernel.Get <About>().Container); MainWindow.MenuFlyout.IsOpen = false; }; List <MenuItem> extraMenuItems = new List <MenuItem>(MenuItems); MenuItems.Clear(); MenuItems.Add(settingsItem); MenuItems.Add(consoleItem); MenuItems.Add(aboutItem); InternalMenuCount = MenuItems.Count; OwnedItems.AddRange(MenuItems); foreach (MenuItem item in extraMenuItems) { MenuItems.Add(item); } MainPage = new PageItem("MainWindow_NewsTab", new MainPage().Container, true); Gallery = new PageItem("MainWindow_GalleryTab", new Gallery().Container, true); Community = new PageItem("MainWindow_CommunityTab", new Community().Container, true); Personalization = new PageItem("MainWindow_PersonalizationTab", new Personalization().Container, true); List <PageItem> extraPages = new List <PageItem>(PageItems); PageItems.Clear(); PageItems.Add(MainPage); PageItems.Add(Gallery); PageItems.Add(Community); PageItems.Add(Personalization); OwnedItems.AddRange(PageItems); foreach (PageItem item in extraPages) { PageItems.Add(item); } }
private void PageForwardCommandExecute(object parameter) { PageItems.Clear(); ++PageCursor; int startIndex = (PageCursor - 1) * Constants.NumberOfItemsPerPage; for (var i = startIndex; i < startIndex + Constants.NumberOfItemsPerPage; ++i) { if (i >= Items.Count) { break; } PageItems.Add(Items[i]); } PageBackCommand.RaiseCanExecuteChanged(); PageForwardCommand.RaiseCanExecuteChanged(); }
public void Update() { PageItems.Clear(); foreach (var item in AppManager.GetInstance().PageList) { AppPageItem pageItem = new AppPageItem(); pageItem.Page = item.Key; pageItem.IsSelect = false; PageItems.Add(pageItem); } bool isExist = false; foreach (AppPageItem item in PageItems) { if (item.Page == SelectPage) { item.IsSelect = true; isExist = true; break; } } if (!isExist) { SelectPage = 0; foreach (AppPageItem item in PageItems) { if (item.Page == SelectPage) { item.IsSelect = true; break; } } } AppItems.Clear(); foreach (AppItem item in AppManager.GetInstance().AppItemList) { if (item.Page == SelectPage) { AppItems.Add(item); } } }
/// <summary> /// 添加新的页面 /// </summary> /// <param name="page">页面源,使用new Pages.xxx()初始化</param> /// <param name="title">页面标题</param> /// <returns>返回初始化后的Page</returns> public static Page AddPage(Page page, string title) { pages.Add(UUIDTemp, page); var PageInfo = new PageItemModel() { PageTitle = title, PageSource = page, uuid = UUIDTemp }; UUIDTemp = CreateNewUUID; page.DataContext = PageInfo; PageItems.Add(PageInfo); Dispatcher.CurrentDispatcher.Invoke(() => (Application.Current.MainWindow as MainWindow).ListView_Page.SelectedIndex = PageItems.Count - 1); //if (page is Pages.ProcessContainer) //{ // throw new Exception((page as Pages.ProcessContainer).StPar.ToString()); //} return(page); }
public void Sync(int dataTotal = -1) { if (dataTotal > -1) { this.DataTotal = dataTotal; } if (this.PageSize > 0) { this.PageTotal = DataTotal / this.PageSize; if (DataTotal % this.PageSize > 0) { this.PageTotal++; } } if (this.PageIndex <= 0) { this.PageIndex = 1; } if (this.PageTotal <= 0) { this.PageTotal = 1; } if (this.PageIndex > this.PageTotal) { this.PageIndex = this.PageTotal; } this.PageItems = new ObservableCollection <KeyValuePair <int, bool> >(); for (var i = 1; i <= this.PageTotal; i++) { PageItems.Add(new KeyValuePair <int, bool>(i, i != PageIndex)); } IsFirst = PageIndex > 1; IsLast = PageIndex < PageTotal; }
private async void LoadAlbumsAsync() { lock (loadAlbumsMutex) { if (isLoadingAlbums) { return; } isLoadingAlbums = true; } Items.Clear(); PageItems.Clear(); int count = 0; var albums = await oneDriveController.GetAlbumsAsync(); if (albums == null) { if (!HasInternetConnection) { Debug.WriteLine("No internet connection."); } ItemsExist = false; IsLoading = false; Debug.WriteLine("Error: Fetching albums from OneDrive returns null."); lock (loadAlbumsMutex) { isLoadingAlbums = false; } } else { foreach (var album in albums) { var bundle = new BundleModel(album.Id, album.Name, album.ThumbnailUrl); if (count < Constants.NumberOfItemsPerPage) { PageItems.Add(bundle); ++count; } Items.Add(bundle); } } PageCursor = 1; NumberOfPages = (Items.Count + Constants.NumberOfItemsPerPage - 1) / Constants.NumberOfItemsPerPage; NumberOfPages = NumberOfPages < 1 ? 1 : NumberOfPages; ItemsExist = Items.Count != 0; PageBackCommand.RaiseCanExecuteChanged(); PageForwardCommand.RaiseCanExecuteChanged(); IsLoading = false; lock (loadAlbumsMutex) { isLoadingAlbums = false; } }
public void AddPageItem(PageItem pageItem) { PageItems.Add(pageItem); }