예제 #1
0
        // Handle DataRequested event and provide DataPackage
        public async void OnShareDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
        {
            var request  = args.Request;
            var deferral = args.Request.GetDeferral();

            if (shareItem.imgName != "" && shareItem.imgName != null)
            {
                var file = await ApplicationData.Current.LocalFolder.GetFileAsync(shareItem.imgName);

                IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);

                var picStream = RandomAccessStreamReference.CreateFromStream(fileStream);
                request.Data.SetBitmap(picStream);
            }
            else
            {
                var picStream = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/pic_6.jpg"));
                request.Data.SetBitmap(picStream);
            }
            request.Data.Properties.Title       = shareItem.Title;
            request.Data.Properties.Description = "A share of Todo";
            request.Data.SetText(shareItem.Description);
            shareItem = null;
            deferral.Complete();
        }
예제 #2
0
        private void ShareItem(object sender, RoutedEventArgs e)
        {
            var item = (sender as FrameworkElement).DataContext as Models.TodoItem;

            shareItem = item;
            DataTransferManager.ShowShareUI();
        }
예제 #3
0
        private void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            string Message = "";

            if (titleText.Text == "")
            {
                Message += "请输入标题\n";
            }
            if (detailText.Text == "")
            {
                Message += "请输入内容详情\n";
            }
            if (DatePicker.Date < DateTimeOffset.Now.LocalDateTime.AddDays(-1))
            {
                Message += "请选择正确的时间";
            }

            if (Message == "" && (this.ViewModel == null))
            {
                MainPage.allItem.AddTodoItem(pic.Source as BitmapImage, MySlider.Value, GetImage.getPicClass.imgName, titleText.Text, detailText.Text, DatePicker.Date);
                Message = "创建成功!";
                GetImage.getPicClass.imgName = "";
                Frame rootFrame = Window.Current.Content as Frame;
                rootFrame.Navigate(typeof(MainPage));
            }
            else if (Message == "")
            {
                MainPage.allItem.UpdateTodoItem("", pic.Source as BitmapImage, MySlider.Value, GetImage.getPicClass.imgName, titleText.Text, detailText.Text, DatePicker.Date, this.ViewModel.isChecked);
                this.ViewModel = null;
                Message        = "更新成功!";
                GetImage.getPicClass.imgName = "";
                Frame rootFrame = Window.Current.Content as Frame;
                rootFrame.Navigate(typeof(MainPage));
            }
            var msgbox = new MessageDialog(Message);
            var result = msgbox.ShowAsync();
        }
예제 #4
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.NavigationMode == NavigationMode.New)
            {
                //if this is a new navigation, this is a fresh lauch so we can
                //discard any saved state
                ApplicationData.Current.LocalSettings.Values.Remove("NewPage");
                this.ViewModel = MainPage.allItem.selectedItem;
                if (this.ViewModel != null)
                {
                    DeleteAppBarButton.Visibility = Visibility.Visible;
                    MySlider.Value       = this.ViewModel.picSize;
                    titleText.Text       = this.ViewModel.Title;;
                    detailText.Text      = this.ViewModel.Description;
                    DatePicker.Date      = this.ViewModel.ItemDate;
                    pic.Source           = this.ViewModel.image;
                    createButton.Content = "Update";
                }
            }
            else
            {
                //try to restore state if any, in case we were terminated
                if (ApplicationData.Current.LocalSettings.Values.ContainsKey("NewPage"))
                {
                    SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
                    var composite = ApplicationData.Current.LocalSettings.Values["NewPage"] as ApplicationDataCompositeValue;
                    MySlider.Value  = (double)composite["picSize"];
                    titleText.Text  = (string)composite["title"];
                    detailText.Text = (string)composite["detail"];
                    DatePicker.Date = (DateTimeOffset)composite["date"];
                    GetImage.getPicClass.imgName = (string)composite["image"];
                    string isSelectedId = (string)composite["isSelectedId"];
                    if (isSelectedId != null)
                    {
                        createButton.Content = "Update";
                        foreach (var item in MainPage.allItem.AllItems)
                        {
                            if (item.id == isSelectedId)
                            {
                                MainPage.allItem.selectedItem = this.ViewModel = item;
                            }
                        }
                        DeleteAppBarButton.Visibility = Visibility.Visible;
                    }
                    if (GetImage.getPicClass.imgName == "" || GetImage.getPicClass.imgName == null)
                    {
                        pic.Source = new BitmapImage(new Uri("ms-appx:///Assets/pic_6.jpg"));
                    }
                    else
                    {
                        var file = await ApplicationData.Current.LocalFolder.GetFileAsync(GetImage.getPicClass.imgName);

                        IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);

                        BitmapImage bitmapImage = new BitmapImage();
                        await bitmapImage.SetSourceAsync(fileStream);

                        pic.Source = bitmapImage;
                    }

                    //we have done it, so remove it
                    ApplicationData.Current.LocalSettings.Values.Remove("NewPage");
                }
            }
        }