Пример #1
0
 private void AddSuccess_Click(object sender, RoutedEventArgs e)
 {
     //add list view      ***judge is existed the same title***
     tipTextBlock.Text = "";
     if (tipTextBox.Text.Length > 0)
     {
         addFlyout.Hide();
         //data
         System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
         long            timeStamp = (long)(DateTime.Now - startTime).TotalMilliseconds;
         ObservableCollection <CardTitleViewModel> lists = new ObservableCollection <CardTitleViewModel>();
         lists.Add(new CardTitleViewModel {
             CardId = timeStamp, HeaderTitle = tipTextBox.Text, Contents = new ObservableCollection <CardContent>()
         });
         //add userControl
         this.cardListViewModel.CardLists.Add(new CardTitleViewModel {
             CardId = timeStamp, HeaderTitle = tipTextBox.Text, Contents = new ObservableCollection <CardContent>()
         });;
         CardTitleViewModel    lastVM       = this.cardListViewModel.CardLists[this.cardListViewModel.CardLists.Count - 1];
         SingleCardUserControl singleCardUC = new SingleCardUserControl();
         singleCardUC.cardTitleVM         = lastVM;
         singleCardUC.HorizontalAlignment = HorizontalAlignment.Left;
         singleCardUC.Margin = new Thickness(15, 0, 0, 0);
         singleCardUC.DeleteCardListEvent     += deleteCardListAction;
         singleCardUC.ListViewChangeItemEvent += SingleCardUC_ListViewChangeItemEvent;
         CardPanel.Children.Add(singleCardUC);
         tipTextBox.Text   = "";
         tipTextBlock.Text = "";
         this.cardUCLists.Add(singleCardUC);
     }
     else
     {
         tipTextBlock.Text = "The title is empty.Please enter a title";
     }
 }
Пример #2
0
        //public CardTitleVM cardTitleVM { get; set; }

        private async void deleteCardListAction(object parameter)
        {
            //dialog
            CardTitleViewModel model        = parameter as CardTitleViewModel;
            ContentDialog      deleteDialog = new ContentDialog
            {
                Title             = "Delete",
                Content           = "Are you sure to delete" + " \"" + model.HeaderTitle + " \" list",
                PrimaryButtonText = "Delete",
                CloseButtonText   = "Cancel"
            };

            ContentDialogResult result = await deleteDialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                int index = 0;
                for (int i = 0; i < this.cardListViewModel.CardLists.Count; i++)
                {
                    CardTitleViewModel singleVM = this.cardListViewModel.CardLists[i];
                    if (singleVM.CardId == model.CardId)
                    {
                        index = i;
                        break;
                    }
                }
                SingleCardUserControl deleteCardUC = this.cardUCLists[index];
                CardPanel.Children.Remove(deleteCardUC);
                this.cardUCLists.RemoveAt(index);
                this.cardListViewModel.CardLists.RemoveAt(index);

                foreach (CardContent content in deleteCardUC.cardTitleVM.Contents)
                {
                    if (content.AlarmTime != null)
                    {
                        ToastUtil toastUtil = new ToastUtil();
                        toastUtil.removeToast(content);
                    }
                }
            }
        }
Пример #3
0
        private async void getJsonText()
        {
            StorageFolder storageFolder = KnownFolders.PicturesLibrary;

            try
            {
                StorageFile sampleFile = await storageFolder.GetFileAsync("cardJson.txt");

                string text = await Windows.Storage.FileIO.ReadTextAsync(sampleFile);

                if (text.Length == 0)
                {
                    this.cardListViewModel = new CardListViewModel();
                }
                else
                {
                    this.cardListViewModel = new CardListViewModel(text);
                }
            }
            catch (FileNotFoundException)
            {
                // If the file dosn't exits it throws an exception, make fileExists false in this case
                this.cardListViewModel = new CardListViewModel();
            }
            finally
            {
                foreach (CardTitleViewModel singleVM in this.cardListViewModel.CardLists)
                {
                    SingleCardUserControl singleCardUC = new SingleCardUserControl();
                    singleCardUC.cardTitleVM = await Task.Run(() => singleVM);

                    singleCardUC.HorizontalAlignment = HorizontalAlignment.Left;
                    singleCardUC.Margin = new Thickness(15, 0, 0, 0);
                    singleCardUC.DeleteCardListEvent     += deleteCardListAction;
                    singleCardUC.ListViewChangeItemEvent += SingleCardUC_ListViewChangeItemEvent;
                    CardPanel.Children.Add(singleCardUC);
                    this.cardUCLists.Add(singleCardUC);
                }
            }
        }