private void OnTabStripDrop(object sender, Windows.UI.Xaml.DragEventArgs e) { // This event is called when we're dragging between different TabViews // It is responsible for handling the drop of the item into the second TabView object obj; object objOriginTabView; if (e.DataView.Properties.TryGetValue(DataIdentifier, out obj) && e.DataView.Properties.TryGetValue(DataTabView, out objOriginTabView)) { // TODO - BUG: obj should never be null, but occassionally is. Why? if (obj == null || objOriginTabView == null) { return; } var originTabView = objOriginTabView as TabView; var destinationTabView = sender as TabView; var destinationItems = destinationTabView.TabItems; var tabViewItem = obj as TabViewItem; if (destinationItems != null) { // First we need to get the position in the List to drop to var index = -1; // Determine which items in the list our pointer is inbetween. for (int i = 0; i < destinationTabView.TabItems.Count; i++) { var item = destinationTabView.ContainerFromIndex(i) as TabViewItem; if (e.GetPosition(item).X - item.ActualWidth < 0) { index = i; break; } } // Remove item from the old TabView originTabView.TabItems.Remove(tabViewItem); if (index < 0) { // We didn't find a transition point, so we're at the end of the list destinationItems.Add(tabViewItem); } else if (index < destinationTabView.TabItems.Count) { // Otherwise, insert at the provided index. destinationItems.Insert(index, tabViewItem); } // Select the newly dragged tab destinationTabView.SelectedItem = tabViewItem; } } }
private async void ItemListView2_Drop(object sender, DragEventArgs e) { string itemIndexString = await e.Data.GetView().GetTextAsync("itemIndex"); var item = storeData.Collection[int.Parse(itemIndexString)]; Point pos = e.GetPosition(ItemListView2.ItemsPanelRoot); ListViewItem lvi = (ListViewItem)ItemListView2.ContainerFromIndex(0); double itemHeight = lvi.ActualHeight + lvi.Margin.Top + lvi.Margin.Bottom; int index = Math.Min(ItemListView2.Items.Count - 1, (int)(pos.Y / itemHeight)); ListViewItem targetItem = (ListViewItem)ItemListView2.ContainerFromIndex(index); Point positionInItem = e.GetPosition(targetItem); if (positionInItem.Y > itemHeight / 2) { index++; } index = Math.Min(ItemListView2.Items.Count, index); storeData2.Collection.Insert(index, item); }
private async void WeekGridView_Drop(object sender, DragEventArgs e) { bool success = false; StaffItem si = null; try { string itemIndexString = await e.Data.GetView().GetTextAsync("ItemNumber"); //which shift si = siList.ElementAt(int.Parse(itemIndexString)); success = true; } catch { //string itemIndexString = await e.Data.GetView().GetTextAsync("ItemNumber2"); //which shift //StaffItem si = siList2.ElementAt(int.Parse(itemIndexString)); success = false; } if (!success) { string itemIndexString = await e.Data.GetView().GetTextAsync("ItemNumber2"); //which shift si = siList2.ElementAt(int.Parse(itemIndexString)); } //////////////////////////////// //List<StaffItem> temp = (List<StaffItem>)WeekGridView.ItemsSource; //temp.ElementAt(0). //////////////////////////////// FrameworkElement root = Window.Current.Content as FrameworkElement; Point position = this.TransformToVisual(root).TransformPoint(e.GetPosition(this)); int newIndex = 0; // check items directly under the pointer foreach (var element in VisualTreeHelper.FindElementsInHostCoordinates(position, root)) { // assume horizontal orientation var container = element as ContentControl; if (container == null) { continue; } int tempIndex = WeekGridView.IndexFromContainer(container); if (tempIndex >= 0) { newIndex = tempIndex; // adjust index depending on pointer position Point center = container.TransformToVisual(root).TransformPoint(new Point(container.ActualWidth / 2, container.ActualHeight / 2)); if (position.Y > center.Y) { newIndex++; } break; } } if (newIndex < 0) { // if we haven't found item under the pointer, check items in the rectangle to the left from the pointer position foreach (var element in GetIntersectingItems(position, root)) { // assume horizontal orientation var container = element as ContentControl; if (container == null) { continue; } // int tempIndex = WeekGridView.ItemContainerGenerator.IndexFromContainer(container); int tempIndex = WeekGridView.IndexFromContainer(container); if (tempIndex < 0) { // we only need GridViewItems belonging to this GridView control // so skip all elements which are not continue; } Rect bounds = container.TransformToVisual(root).TransformBounds(new Rect(0, 0, container.ActualWidth, container.ActualHeight)); if (bounds.Left <= position.X && bounds.Top <= position.Y && tempIndex > newIndex) { //_currentOverGroup = GetItemGroup(container.Content); newIndex = tempIndex; // adjust index depending on pointer position if (position.Y > bounds.Top + container.ActualHeight / 2) { newIndex++; } if (bounds.Right > position.X && bounds.Bottom > position.Y) { break; } } } } if (newIndex < 0) { newIndex = 0; } if (newIndex >= empList.Count * 9) { newIndex = empList.Count * 9 - 1; } //empList = await User.ReadUsersList(); // await new MessageDialog(newIndex.ToString()).ShowAsync(); StaffItem selectedStaffItem = dList.ElementAt(newIndex); if (selectedStaffItem.workHours == null) { if (!String.IsNullOrEmpty(si.workHours.TimeOffReason)) { //timeOff // WorkHours wh = new WorkHours() { EmployeeId = empList.ElementAt(SelectedString.i / 9).UserId,TimeOffFrom= SelectedString.date,TimeOffTo=SelectedString.date+new TimeSpan(23,0,0), TimeOffReason="Time Off"}; WorkHours wh = new WorkHours(); //wh = selectedStaffItem.workHours; wh.TimeOffReason = si.workHours.TimeOffReason; wh.TimeOffFrom = selectedStaffItem.date; wh.TimeOffTo = selectedStaffItem.date + new TimeSpan(23, 0, 0); wh.EmployeeId = empList.ElementAt(selectedStaffItem.i / 9).UserId; //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2); //myGrid.Opacity = 0.5; await WorkHours.InsertNewWorkHours(wh); fillWeeklyCalendar(); //myGrid.Opacity = 1; //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2); } else { // Shift // WorkHours wh = new WorkHours() { EmployeeId = empList.ElementAt(SelectedString.i / 9).UserId, From = SelectedString.date + ts1, To = SelectedString.date + ts2 , OnCallOnly = false, BreakTimeFrom= new TimeSpan(8+count,0,0), BreakTimeTo=new TimeSpan(8+count+1,0,0),TimeOffReason=String.Empty }; WorkHours wh = new WorkHours(); //wh = selectedStaffItem.workHours; wh.From = selectedStaffItem.date + si.workHours.From.TimeOfDay; wh.To = (si.workHours.From.TimeOfDay.Hours != 23) ? selectedStaffItem.date +si.workHours.To.TimeOfDay : selectedStaffItem.date.AddDays(1) + si.workHours.To.TimeOfDay; wh.EmployeeId = empList.ElementAt(selectedStaffItem.i / 9).UserId; wh.OnCallOnly = false; wh.BreakTimeFrom = new TimeSpan(si.workHours.From.TimeOfDay.Hours + empList.Count, 0, 0); wh.BreakTimeTo = new TimeSpan(si.workHours.From.TimeOfDay.Hours + empList.Count + 1, 0, 0); wh.TimeOffReason = String.Empty; //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 2); //myGrid.Opacity = 0.5; await WorkHours.InsertNewWorkHours(wh); fillWeeklyCalendar(); //myGrid.Opacity = 1; //Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 2); } } else { await new MessageDialog("Conflict").ShowAsync(); } }
void ElementScrollViewer_DragEnter(object sender, DragEventArgs e) { //} //private void viewer_MouseMove(object sender, MouseEventArgs e) //{ if (VerticalOffset == 0 && e != null) { //var p = this.TransformToVisual(ElementRelease).Transform(new Point(0, 0)); //if (p.Y < -VerticalPullToRefreshDistance) double Translation_Y = e.GetPosition(ElementScrollViewer).Y; if (Translation_Y - ManipulationStartedYOffset < VerticalPullToRefreshDistance) { if (!isPulling) { isPulling = true; ChangeVisualState(RefreshState.Pulling, true); if (EnteredPullRefreshThreshold != null) { EnteredPullRefreshThreshold(this, EventArgs.Empty); } //GoToState("Pulling", true); } } else if (isPulling) { isPulling = false; if (LeftPullRefreshThreshold != null) { LeftPullRefreshThreshold(this, EventArgs.Empty); } ChangeVisualState(RefreshState.ReleasePulling, true); //GoToState("ReleasePulling", true); } } }
async private void UpdateOutput(DragEventArgs e) { ClearOutput(); OutputCursorPosition.Text = e.GetPosition(MainGrid).X + "," + e.GetPosition(MainGrid).Y; string keys = ""; if (e.Modifiers.HasFlag(DragDropModifiers.Alt)) keys += "Alt "; if (e.Modifiers.HasFlag(DragDropModifiers.Control)) keys += "Control "; if (e.Modifiers.HasFlag(DragDropModifiers.LeftButton)) keys += "LeftButton "; if (e.Modifiers.HasFlag(DragDropModifiers.MiddleButton)) keys += "MiddleButton "; if (e.Modifiers.HasFlag(DragDropModifiers.None)) keys += "None "; if (e.Modifiers.HasFlag(DragDropModifiers.RightButton)) keys += "RightButton "; if (e.Modifiers.HasFlag(DragDropModifiers.Shift)) keys += "Shift "; OutputModifiers.Text = keys; string acceptedOperations = ""; if (e.AcceptedOperation.HasFlag(DataPackageOperation.Copy)) acceptedOperations += "Copy "; if (e.AcceptedOperation.HasFlag(DataPackageOperation.Move)) acceptedOperations += "Move "; if (e.AcceptedOperation.HasFlag(DataPackageOperation.Link)) acceptedOperations += "Link "; if (e.AcceptedOperation.HasFlag(DataPackageOperation.None)) acceptedOperations += "None "; OutputAcceptedOperations.Text = acceptedOperations; string requestedOperations = ""; if (e.DataView.RequestedOperation.HasFlag(DataPackageOperation.Copy)) requestedOperations += "Copy "; if (e.DataView.RequestedOperation.HasFlag(DataPackageOperation.Move)) requestedOperations += "Move "; if (e.DataView.RequestedOperation.HasFlag(DataPackageOperation.Link)) requestedOperations += "Link "; if (e.DataView.RequestedOperation.HasFlag(DataPackageOperation.None)) requestedOperations += "None "; OutputRequestedOperations.Text = requestedOperations; if (e.DataView.Contains(StandardDataFormats.ApplicationLink)) OutputDPAppLink.Text = (await e.DataView.GetApplicationLinkAsync()).ToString(); if (e.DataView.Contains(StandardDataFormats.WebLink)) OutputDPWebLink.Text = (await e.DataView.GetWebLinkAsync()).ToString(); if (e.DataView.Contains(StandardDataFormats.Text)) OutputDPText.Text = await e.DataView.GetTextAsync(); if (e.DataView.Contains(StandardDataFormats.Rtf)) OutputDPRtf.Text = await e.DataView.GetRtfAsync(); if (e.DataView.Contains(StandardDataFormats.Html)) OutputDPHTML.Text = await e.DataView.GetHtmlFormatAsync(); if (e.DataView.Contains(StandardDataFormats.Bitmap)) { BitmapImage image = new BitmapImage(); var streamRef = await e.DataView.GetBitmapAsync(); var stream = await streamRef.OpenReadAsync(); image.SetSource(stream); OutputDPBitmap.Source = image; } if (e.DataView.Contains(StandardDataFormats.StorageItems)) { var files = await e.DataView.GetStorageItemsAsync(); foreach (var file in files) { TextBlock t = new TextBlock(); t.Text = file.Name; OutputDPFiles.Children.Add(t); } } }
void dropList_DragOver(object sender, DragEventArgs e) { var pos = e.GetPosition(ItemListView2.ItemsPanelRoot); ListViewItem lvi = (ListViewItem)ItemListView2.ContainerFromIndex(0); double itemHeight = lvi.ActualHeight + lvi.Margin.Top + lvi.Margin.Bottom; int index = Math.Min(ItemListView2.Items.Count - 1, (int)(pos.Y / itemHeight)); ListViewItem lvidrop = (ListViewItem)ItemListView2.ContainerFromIndex(index); if (index != currDropIndex) { if (currDropIndex >= 0) { //remove the border ListViewItem lvidropOld = (ListViewItem)ItemListView2.ContainerFromIndex(currDropIndex); lvidropOld.BorderThickness = noBorder; } lvidrop.BorderBrush = blueBorder; lvidrop.BorderThickness = thickBorder; currDropIndex = index; } }
private async void ItemListView2_Drop(object sender, DragEventArgs e) { string data = await e.Data.GetView().GetTextAsync("data"); //Find the position where item will be dropped in the listview Point pos = e.GetPosition(ItemListView2.ItemsPanelRoot); //Get the size of one of the list items ListViewItem lvi = (ListViewItem)ItemListView2.ContainerFromIndex(0); double itemHeight = lvi.ActualHeight + lvi.Margin.Top + lvi.Margin.Bottom; //Determine the index of the item from the item position (assumed all items are the same size) int index = Math.Min(ItemListView2.Items.Count - 1, (int)(pos.Y / itemHeight)); rootPage.NotifyUser("You dropped \'" + data + "\' from the first list onto item \'" + (index + 1) + "\' of the second list", NotifyType.StatusMessage); //Remove the border from the item ListViewItem lvidropOld = (ListViewItem)ItemListView2.ContainerFromIndex(currDropIndex); lvidropOld.BorderThickness = noBorder; }
private async void Canvas_Drop(object sender, DragEventArgs e) { DataTemplate dataTemplate = this.Resources["PlayerElementTemplate"] as DataTemplate; var elem = dataTemplate.LoadContent() as FrameworkElement; var pname = await e.DataView.GetTextAsync(); elem.DataContext = App.MainViewModel.SelectedTeam.Players.First((pl) => pl.Name == pname); var p = e.GetPosition(Canvas); Canvas.SetLeft(elem, p.X); Canvas.SetTop(elem, p.Y); Canvas.Children.Add(elem); }