Last active
May 7, 2017 18:30
-
-
Save houseofcat/40661b4b492d435e7770121c141cbbee to your computer and use it in GitHub Desktop.
SfDataGrid - UWP - Cell & Row DoubleClick/DoubleTap EventHandler Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize your DataGrid and set the EventHandlers | |
// The focus here is OpenFileOnDoubleTap | |
private void InitializeMainDataGrid() | |
{ | |
MainDataGrid.ItemsSource = ViewModel.MainSearchResults; | |
MainDataGrid.Columns["FileExt"].AllowGrouping = true; | |
MainDataGrid.Columns["FilePath"].AllowGrouping = true; | |
MainDataGrid.Columns["FileName"].AllowGrouping = true; | |
MainDataGrid.QueryRowHeight += Evt_DataGridQueryRowHeight; | |
MainDataGrid.CellDoubleTapped += Evt_OpenFileOnDoubleTap; | |
} | |
// Actual EventHandler | |
private async void Evt_OpenFileOnDoubleTap(object sender, CellDoubleTappedEventArgs e) | |
{ | |
var rowColumnIndex = e.RowColumnIndex; | |
// Validation Check | |
if (!rowColumnIndex.IsEmpty) | |
{ | |
var colIndex = MainDataGrid.ResolveToGridVisibleColumnIndex(rowColumnIndex.ColumnIndex); | |
// Validation Check | |
if (colIndex > -1 && colIndex < MainDataGrid.Columns.Count) | |
{ | |
var recordIndex = MainDataGrid.ResolveToRecordIndex(rowColumnIndex.RowIndex); | |
// Validation Check | |
if (recordIndex > -1) | |
{ | |
var recordEntry = MainDataGrid.View.GroupDescriptions.Count == 0 ? | |
MainDataGrid.View.Records[recordIndex] | |
: MainDataGrid.View.TopLevelGroup.DisplayElements[recordIndex]; | |
// Validation Check | |
if (recordEntry.IsRecords) | |
{ | |
var record = ((recordEntry as RecordEntry).Data as MainSearchResult); | |
var filePath = record.FilePath; | |
var fileName = record.FileName + "." + record.FileExt; | |
if (filePath != string.Empty && fileName != string.Empty) | |
{ | |
await Tools.OpenFileAsync(filePath, fileName); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment