public void EditItem(ShoppingItemViewModel editItem) { _editItem = editItem; // find the edit and static text controls var container = _todoList.ItemContainerGenerator.ContainerFromItem(editItem); _taskTextEdit = FindNamedDescendant <TextBox>(container, "taskTextEdit"); _taskEditGrid = FindNamedDescendant <Grid>(container, "editGrid"); _taskText = FindNamedDescendant <TextBlock>(container, "taskText"); // store the original text to allow undo _originalText = _taskTextEdit.Text; EditFieldVisible(true); // set the caret position to the end of the text field _taskTextEdit.Focus(); _taskTextEdit.Select(_originalText.Length, 0); _taskEditGrid.LostFocus += _taskEditGrid_LostFocus; //_taskTextEdit.LostFocus += TaskTextEdit_LostFocus; // fade out all other items ((FrameworkElement)_todoList.ItemContainerGenerator.ContainerFromItem(_editItem)).Opacity = 1; var elements = _todoItems.Where(i => i != _editItem) .Select(i => _todoList.ItemContainerGenerator.ContainerFromItem(i)) .Cast <FrameworkElement>(); foreach (var el in elements) { el.Animate(1.0, 0.7, FrameworkElement.OpacityProperty, 800, 0); } }
private void ScrollViewer_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { Debug.WriteLine("scrollViewer_MouseLeftButtonUp"); if (!IsActive) { return; } // hide the pull down item by locating it off screen _pullDownItem.VerticalOffset = -ToDoItemHeight; // if the list was pulled down far enough, add a new item if (_distance > trackDistance) { var newItem = new ShoppingItemViewModel(""); _todoItems.Insert(0, newItem); // when the new item has been rendered, use the edit interaction to place the UI // into edit mode _todoList.InvokeOnNextLayoutUpdated(() => _editInteraction.EditItem(newItem)); } IsActive = false; _effectPlayed = false; }
private void ToDoItemDeletedAction(FrameworkElement deletedElement) { //_deleteSound.Play(); var trans = deletedElement.GetHorizontalOffset().Transform; trans.Animate(trans.X, -(deletedElement.ActualWidth + 50), TranslateTransform.XProperty, 300, 0, new SineEase() { EasingMode = EasingMode.EaseOut }, () => { // find the model object that was deleted ShoppingItemViewModel deletedItem = deletedElement.DataContext as ShoppingItemViewModel; // determine how much we have to 'shuffle' up by double elementOffset = -deletedElement.ActualHeight; // find the items in view, and the location of the deleted item in this list var itemsInView = _todoList.GetItemsInView().ToList(); var lastItem = itemsInView.Last(); int startTime = 0; int deletedItemIndex = itemsInView.Select(i => i.DataContext) .ToList().IndexOf(deletedItem); // iterate over each item foreach (FrameworkElement element in itemsInView.Skip(deletedItemIndex)) { // for the last item, create an action that deletes the model object // and re-renders the list Action action = null; if (element == lastItem) { action = () => { // remove the item _todoItems.Remove(deletedItem); // re-populate our ObservableCollection _todoItems.Reset(); }; } // shuffle this item up TranslateTransform elementTrans = new TranslateTransform(); element.RenderTransform = elementTrans; elementTrans.Animate(0, elementOffset, TranslateTransform.YProperty, 200, startTime, null, action); startTime += 10; } }); }
private void ToDoItemCompletedAction(FrameworkElement fe) { // set the mode object to complete ShoppingItemViewModel completedItem = fe.DataContext as ShoppingItemViewModel; completedItem.Completed = !completedItem.Completed; var color = completedItem.PrevColor; completedItem.PrevColor = completedItem.Color; completedItem.Color = color; // bounce back into place ToDoItemBounceBack(fe); //_completeSound.Play(); }
public ShoppingItemViewModel Put([FromBody] ShoppingItemViewModel shoppingItemViewModel) { var shoppingItem = new ShoppingItem { Id = shoppingItemViewModel.Id, IsPurchased = shoppingItemViewModel.IsPurchased, Quantity = shoppingItemViewModel.Quantity }; var updatedShoppingItem = new ShoppingItemTransitionHandler().AddUpdate(shoppingItem); var item = new Item() { Id = updatedShoppingItem.ItemId, Name = shoppingItemViewModel.Name, PictureId = shoppingItemViewModel.PictureId }; var updatedItem = new ItemTransitionHandler().AddUpdate(item); return(new ShoppingItemViewModel(updatedShoppingItem)); }
private void Touch_FrameReported(object sender, TouchFrameEventArgs e) { if (!IsEnabled) { return; } if (IsActive) { var touchPoints = e.GetTouchPoints(_todoList); // if we still have two touch points continue the pinch gesture if (touchPoints.Count == 2) { double currentDelta = GetDelta(touchPoints[0], touchPoints[1]); double itemsOffset = 0; // is the delta bigger than the initial? if (currentDelta > _initialDelta) { double delta = currentDelta - _initialDelta; itemsOffset = delta / 2; // play a sound effect if the users has pinched far enough to add a new item if (delta > ToDoItemHeight && !_effectPlayed) { _effectPlayed = true; //_popSound.Play(); } _addNewThresholdReached = delta > ToDoItemHeight; // stretch and fade in the new item var cappedDelta = Math.Min(ToDoItemHeight, delta); ((ScaleTransform)_pullDownItem.RenderTransform).ScaleY = cappedDelta / ToDoItemHeight; _pullDownItem.Opacity = cappedDelta / ToDoItemHeight; // set the text _pullDownItem.Text = cappedDelta < ToDoItemHeight ? "Чтобы добавить, тяните вниз" : "Чтобы добавить, отпустите"; } // offset all the items in the list so that they 'part' for (int i = 0; i < _todoItems.Count; i++) { var container = _todoList.ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement; var translateTransform = (TranslateTransform)container.RenderTransform; translateTransform.Y = i <= _itemOneIndex ? -itemsOffset : itemsOffset; } } else { // if we no longer have two touch points, end the interactions IsActive = false; RefreshView(); // hide the pull-down item _pullDownItem.VerticalOffset = -ToDoItemHeight; if (_addNewThresholdReached) { var newItem = new ShoppingItemViewModel(""); _todoItems.Insert(_itemOneIndex, newItem); // when the new item has been rendered, use the edit interaction to place the UI // into edit mode _todoList.InvokeOnNextLayoutUpdated(() => _editInteraction.EditItem(newItem)); } } } else { TouchPointCollection touchPoints; try { touchPoints = e.GetTouchPoints(_todoList); } catch { return; } if (touchPoints.Count == 2) { _addNewThresholdReached = false; _effectPlayed = false; // find the items that were touched ... var itemOne = GetToDoItemAtLocation(touchPoints[0].Position); var itemTwo = GetToDoItemAtLocation(touchPoints[1].Position); if (itemOne != null && itemTwo != null) { // find their indices _itemOneIndex = _todoItems.IndexOf(itemOne); _itemTwoIndex = _todoItems.IndexOf(itemTwo); // are the two items next to each other? if (Math.Abs(_itemOneIndex - _itemTwoIndex) == 1) { if (_itemOneIndex > _itemTwoIndex) { // We need to swap the two int tempIndex = _itemOneIndex; _itemOneIndex = _itemTwoIndex; _itemTwoIndex = tempIndex; var tempItem = itemOne; itemOne = itemTwo; itemTwo = tempItem; } IsActive = true; // determine where to locate the new item placeholder var itemOneContainer = _todoList.ItemContainerGenerator.ContainerFromItem(itemOne) as FrameworkElement; var itemOneContainerPos = itemOneContainer.GetRelativePosition(_todoList); _newItemLocation = itemOneContainerPos.Y + ToDoItemHeight - (ToDoItemHeight / 2); // position the placeholder and add a scale transform _pullDownItem.VerticalOffset = _newItemLocation; _pullDownItem.Opacity = 0; _pullDownItem.RenderTransform = new ScaleTransform() { ScaleY = 1, CenterY = ToDoItemHeight / 2 }; // record the initial distance between touch point _initialDelta = GetDelta(touchPoints[0], touchPoints[1]); AddTranslateTransfromToElements(); _pullDownItem.Opacity = 1; } } } } }