Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support For DataGrid DoubleTap Events Specific to the DataGridRows #2249

Closed
4 of 15 tasks
lukeblevins opened this issue Jun 15, 2018 · 10 comments
Closed
4 of 15 tasks
Labels
DataGrid 🔠 Issues on DataGrid control feature request 📬 A request for new changes to improve functionality
Milestone

Comments

@lukeblevins
Copy link
Contributor

lukeblevins commented Jun 15, 2018

I'm submitting a...




## Current behavior
Currently, to interact with a DataGrid's rows, you must specify a SelectionChanged event. This can become inefficient and somewhat confusing when users are able to select more than one items. Because of this, I would like the functionality to only execute the SelectedItem code when a row is DoubleTapped. Previously, it was possible to add an EventSetter to the DataGridRows' style (As mentioned here: https://stackoverflow.com/questions/22790181/wpf-datagrid-row-double-click-event-programmatically), but since EventSetter is now not apart of UWP, I am left without this functionality.

## Expected behavior
My proposed solution is to add a "RowDoubleTapped" event directly to the UWP DataGrid class itself. I need this to be easily accessible from my XAML code. This already exists with the ListView class which has a similar "ItemClicked" event as an alternative to SelectionChanged.

## Minimal reproduction of the problem with instructions
Create a project using a DataGrid (with a binded ItemSource) that requires DoubleTap event functionality on the DataGridRows themselves. The current DoubleTapped event is not row-specific, meaning it covers the entire DataGrid. I attempted to use this event only to find that the sender was returning a DataGrid rather than a DataGridRow.

Environment


``` Nuget Package(s): Microsoft.Toolkit.Uwp.UI.Controls.DataGrid

Package Version(s): 3.1.0-preview1 (LATEST as of 6/15/2018)

Windows 10 Build Number:

  • Creators Update (15063)
  • Fall Creators Update (16299)
  • April 2018 Update (17134)
  • Insider Build (build number: )

App min and target version:

  • Creators Update (15063)
  • Fall Creators Update (16299)
  • April 2018 Update (17134)
  • Insider Build (xxxxx)

Device form factor:

  • Desktop
  • Mobile
  • Xbox
  • Surface Hub
  • IoT

Visual Studio

  • 2017 (version: 15.7.3)
  • 2017 Preview (version: )
@nmetulev
Copy link
Contributor

ping @harinikmsft

@nmetulev nmetulev added feature request 📬 A request for new changes to improve functionality DataGrid 🔠 Issues on DataGrid control labels Jun 18, 2018
@harinikmsft harinikmsft added this to the future milestone Jun 25, 2018
@harinikmsft
Copy link
Contributor

That seems like a valid ask, we might want to take a look at other DataGridRow** events that we may want to add as part of this. Marking this as a feature request for the future.

@robloo
Copy link
Contributor

robloo commented Nov 18, 2018

Duplicate of #2388

@robloo
Copy link
Contributor

robloo commented Nov 18, 2018

Definitely think a "RowPressed" and "RowDoublePressed" would be a big positive. This is not difficult to implement in the control either. Hoping this feature request is implemented in the next release.

As a bonus please consider "ColumnHeaderPressed" and "ColumnHeaderDoublePressed" as well

@lukeblevins
Copy link
Contributor Author

Definitely think a "RowPressed" and "RowDoublePressed" would be a big positive. This is not difficult to implement in the control either. Hoping this feature request is implemented in the next release.
As a bonus please consider "ColumnHeaderPressed" and "ColumnHeaderDoublePressed" as well
I also think there needs to be a RowRightTapped to create a proper distinction between that and right-tapping the control itself. (Which should only include the column headers)

@robloo In the application I'm building, users currently have to manually select the row before right-clicking in order to display the row-appropriate context menu. Otherwise, it just displays the column header context menu. I think it would be more user-friendly to have a RowRightTapped which autoselects the nearest row and fires (all on rightclick).

@robloo
Copy link
Contributor

robloo commented Nov 18, 2018

@duke7553 I do the same thing in my application. When a right click is detected, I select the row under the click/press. A context menu is then displayed. Full code is below if this will help you :) For sure more of this should be 'out-of-the-box' functionality of the DataGrid.

I also think we need to stay away from the "Tapped" terminology -- this is specific for touch inputs. The generic "Pressed" is better for this I think.

View Code

private void DataGrid_PointerPressed(object sender, PointerRoutedEventArgs e)
{
	DataGrid dataGrid = sender as DataGrid;
	PointerPoint point = e.GetCurrentPoint(dataGrid);
	DataGridRow pressedRow = null;
	object pressedObject = null;
	MenuFlyout flyout;

	// Determine the pressed row
	try
	{
		pressedRow    = FindParent<DataGridRow>(e.OriginalSource as DependencyObject);
		pressedObject = ((List<object>)dataGrid.ItemsSource)[pressedRow.GetIndex()];
	}
	catch { }

	if (point.Properties.IsRightButtonPressed)
	{
		// Select the row
		try
		{
			dataGrid.SelectedItems.Clear();
			dataGrid.SelectedItems.Add(pressedObject);
		}
		catch { }

		// Open the context menu flyout
		try
		{
			flyout = new MenuFlyout(); // Do other stuff here
			flyout.ShowAt(dataGrid, point.Position);
		}
		catch { }
	}
	else
	{
		// Do other stuff
	}

	return;
}

/// <summary>
/// Finds the parent element of the specified type.
/// </summary>
/// <typeparam name="T">The type of the parent element to return.</typeparam>
/// <param name="child">The child to find the element for.</param>
/// <returns></returns>
public static T FindParent<T>(DependencyObject child) where T : DependencyObject
{
	T parent = null;
	DependencyObject currParent;

	currParent = VisualTreeHelper.GetParent(child);
	while (currParent != null)
	{
	   if (currParent is T)
	   {
		  parent = (T)currParent;
		  break;
	   }

	   // find the next parent
	   currParent = VisualTreeHelper.GetParent(currParent);
	}

	return (parent);
}

@lukeblevins
Copy link
Contributor Author

@robloo Thank you for this code! I agree, this should be implemented out-of-the-box within DataGrid.

@robloo
Copy link
Contributor

robloo commented Dec 28, 2018

Since @harinikmsft was collecting a list of events that we may want to add for this, I have summarized as follows:

  • RowPressed : As discussed above. Indicates a row has been pressed so further processing or context menu's can occur.
  • RowDoublePressed : Same as RowPressed, just the double click version.
  • ColumnHeaderPressed : Occurs whenever a column header is pressed. Must take priority over any sort direction internal updates. This will allow for custom filtering menus or right click options to turn on/off columns.
  • ColumnHeaderDoublePressed : Same as ColumnHeaderPressed, just the double click version.
  • ColumnHeaderWidthChanged : Occurs whenever the user resizes a column header width. This will allow for saving this information in a clean way. This is commonly needed when restoring UI state.

@anawishnoff
Copy link

We are not adding features to this DataGrid at this time. I know you already added some feedback along these lines to the WinUI discussion issue - feel free to add more if anything comes up. Thanks!

@Kyaa-dost
Copy link
Contributor

Closing this request since these features are not being added at this time.

@CommunityToolkit CommunityToolkit locked as resolved and limited conversation to collaborators Apr 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
DataGrid 🔠 Issues on DataGrid control feature request 📬 A request for new changes to improve functionality
Projects
None yet
Development

No branches or pull requests

7 participants