private void OnMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton != MouseButton.Left)
            {
                return;
            }


            if (HasCurrentCellState && !((CheckBox)sender).IsPressed && IsFocused)
            {
                ((CheckBox)sender).IsChecked = !((CheckBox)sender).IsChecked;

                TreeGridCell treeGridCell = null;

                var checkBox = sender as CheckBox;

                if (checkBox.Parent is TreeGridCell)
                {
                    treeGridCell = checkBox.Parent as TreeGridCell;
                }

                var rowColumnIndex = new RowColumnIndex();
                rowColumnIndex.RowIndex    = treeGridCell != null ? treeGridCell.ColumnBase.RowIndex : new RowColumnIndex().RowIndex;
                rowColumnIndex.ColumnIndex = treeGridCell != null ? treeGridCell.ColumnBase.ColumnIndex : new RowColumnIndex().ColumnIndex;

                if (!rowColumnIndex.IsEmpty)
                {
                    TreeGrid.RaiseCurrentCellValueChangedEvent(new TreeGridCurrentCellValueChangedEventArgs(TreeGrid)
                    {
                        RowColumnIndex = rowColumnIndex, Record = checkBox.DataContext, Column = treeGridCell.ColumnBase.TreeGridColumn
                    });
                }
            }
        }
        /// <summary>
        /// Called when [CheckBox click].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        void OnCheckBoxClick(object sender, RoutedEventArgs e)
        {
            var checkBox = sender as CheckBox;

            TreeGridCell treeGridCell = null;

            if (checkBox.Parent is TreeGridCell)
            {
                treeGridCell = checkBox.Parent as TreeGridCell;
            }


            var rowcolumnIndex = new RowColumnIndex();

            rowcolumnIndex.RowIndex    = treeGridCell != null ? treeGridCell.ColumnBase.RowIndex : new RowColumnIndex().RowIndex;
            rowcolumnIndex.ColumnIndex = treeGridCell != null ? treeGridCell.ColumnBase.ColumnIndex : new RowColumnIndex().ColumnIndex;

#if !WPF
            if (checkBox.IsThreeState)
            {
                SetIsChecked(checkBox, checkBox.IsChecked);
            }
            if (!rowcolumnIndex.IsEmpty)
            {
                this.TreeGrid.SelectionController.HandlePointerOperations(new GridPointerEventArgs(PointerOperation.Pressed, null), rowcolumnIndex);
                this.TreeGrid.SelectionController.HandlePointerOperations(new GridPointerEventArgs(PointerOperation.Released, null), rowcolumnIndex);
            }
#endif
            TreeGrid.RaiseCurrentCellValueChangedEvent(new TreeGridCurrentCellValueChangedEventArgs(TreeGrid)
            {
                RowColumnIndex = rowcolumnIndex, Record = checkBox.DataContext, Column = treeGridCell.ColumnBase.TreeGridColumn
            });

            if (HasCurrentCellState)
            {
                BindingExpression = this.CurrentCellRendererElement.GetBindingExpression(ToggleButton.IsCheckedProperty);
            }
            //when check or uncheck the checkbox, setter property of checkbox column fires two times in the Model class.
            //while loading, we set the updatesourcetrigger as explicit for checkboxcolumn if we set updatetrigger as PropertyChanged in sample for checkboxcolumn.
            //so skips the below call by checking the updatesourcetrigger.
#if WPF
            if (treeGridCell.ColumnBase.TreeGridColumn.isValueMultiBinding)
            {
                if (BindingExpression != null && (treeGridCell != null && (treeGridCell.ColumnBase.TreeGridColumn.ValueBinding as MultiBinding).UpdateSourceTrigger == UpdateSourceTrigger.Explicit))
                {
                    BindingExpression.UpdateSource();
                }
            }
            else if (BindingExpression != null && (treeGridCell != null && (treeGridCell.ColumnBase.TreeGridColumn.ValueBinding as Binding).UpdateSourceTrigger == UpdateSourceTrigger.Explicit))
            {
                BindingExpression.UpdateSource();
            }
#else
            if (BindingExpression != null && (treeGridCell != null && (treeGridCell.ColumnBase.TreeGridColumn.ValueBinding as Binding).UpdateSourceTrigger == UpdateSourceTrigger.Explicit))
            {
                BindingExpression.UpdateSource();
            }
#endif
        }
        /// <summary>
        /// Shoulds the grid try automatic handle key down.
        /// </summary>
        /// <param name="e">The <see cref="Windows.UI.Core.KeyEventArgs"/> instance containing the event data.</param>
        /// <returns></returns>
        protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e)
        {
            if (!HasCurrentCellState)
            {
                return(true);
            }

            var          CurrentCellUIElement = (CheckBox)CurrentCellRendererElement;
            TreeGridCell treeGridCell         = null;

            if (CurrentCellUIElement.Parent is TreeGridCell)
            {
                treeGridCell = CurrentCellUIElement.Parent as TreeGridCell;
            }

            switch (e.Key)
            {
            case Key.Up:
            case Key.Down:
                return(true);

            case Key.Space:
            {
                if (!CurrentCellUIElement.IsEnabled)
                {
                    return(true);
                }
                if (BindingExpression != null)
                {
                    BindingExpression.UpdateSource();
                }
#if WPF
                CurrentCellUIElement.Focus();
#else
                CurrentCellUIElement.Focus(FocusState.Programmatic);
#endif
                return(true);
            }
            }
            return(base.ShouldGridTryToHandleKeyDown(e));
        }
Exemplo n.º 4
0
		void cells_CollectionChanged(object sender, System.ComponentModel.CollectionChangeEventArgs e)
		{
			// Exit if there already is a tree cell for this row
			if (_treeCell != null) return;

			if (e.Action == System.ComponentModel.CollectionChangeAction.Add || e.Action == System.ComponentModel.CollectionChangeAction.Refresh)
			{
				TreeGridCell treeCell = null;

				if (e.Element == null)
				{
					foreach (DataGridViewCell cell in base.Cells)
					{
						if (cell.GetType().IsAssignableFrom(typeof(TreeGridCell)))
						{
							treeCell = (TreeGridCell)cell;
							break;
						}

					}
				}
				else
				{
					treeCell = e.Element as TreeGridCell;
				}

				if (treeCell != null) 
				  _treeCell = treeCell;
			}
		}
        void OnHyperLinkClick(object sender, EventArgs e)
#endif
        {
#if WPF
            Hyperlink hyperlinkControl;
            //Content is TetxBlock, so we need to get the Hyperlink from Inlines of TextBlock
            if (sender is TextBlock)
            {
                hyperlinkControl = (sender as TextBlock).Inlines.Cast <Hyperlink>().FirstOrDefault();
            }
            else
            {
                hyperlinkControl = (Hyperlink)sender;
            }
#else
            var hyperlinkControl = (HyperlinkButton)sender;
#endif
            TreeGridCell gridcell = null;
#if UWP
            if (hyperlinkControl.Parent is TreeGridCell)
            {
                gridcell = hyperlinkControl.Parent as TreeGridCell;
            }
#else
            if (hyperlinkControl.Parent is TextBlock)
            {
                var textBlock = hyperlinkControl.Parent as TextBlock;
                gridcell = textBlock.Parent as TreeGridCell;
            }
#endif
            var navigateText   = string.Empty;
            var rowColumnIndex = RowColumnIndex.Empty;
            rowColumnIndex.RowIndex    = gridcell != null ? gridcell.ColumnBase.RowIndex : new RowColumnIndex().RowIndex;
            rowColumnIndex.ColumnIndex = gridcell != null ? gridcell.ColumnBase.ColumnIndex : new RowColumnIndex().ColumnIndex;
            if (!rowColumnIndex.IsEmpty)
            {
                this.TreeGrid.SelectionController.HandlePointerOperations(new GridPointerEventArgs(PointerOperation.Pressed, null), rowColumnIndex);
                this.TreeGrid.SelectionController.HandlePointerOperations(new GridPointerEventArgs(PointerOperation.Released, null), rowColumnIndex);
            }
            if (hyperlinkControl.NavigateUri != null)
            {
                navigateText = hyperlinkControl.NavigateUri.ToString();
            }
            else
            {
                if (rowColumnIndex != null && !rowColumnIndex.IsEmpty)
                {
                    //Get the column from rowColumnIndex.
                    var column = this.TreeGrid.Columns[this.TreeGrid.ResolveToGridVisibleColumnIndex(rowColumnIndex.ColumnIndex)];
                    column.ColumnWrapper.DataContext = hyperlinkControl.DataContext;
                    if (column.ColumnWrapper.Value != null)
                    {
                        navigateText = column.ColumnWrapper.Value.ToString();
                    }
                }
            }

            if (TreeGrid.CurrentCellRequestNavigateEvent(new CurrentCellRequestNavigateEventArgs(TreeGrid)
            {
                NavigateText = navigateText, RowData = hyperlinkControl.DataContext, RowColumnIndex = rowColumnIndex
            }))
            {
                return;
            }
            const string pattern = @"((http|https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)";
            //the hyperlink value is stored in the variable navigateText.
            if (navigateText != null)
            {
                var NavigateUri = Regex.IsMatch(navigateText.ToString(), pattern)
                                  ? new Uri(navigateText.ToString())
                                  : null;
                if (NavigateUri == null)
                {
                    return;
                }

                hyperlinkControl.NavigateUri = NavigateUri;
#if WPF
                Process.Start(new ProcessStartInfo(hyperlinkControl.NavigateUri.AbsoluteUri));
#else
                if (e is KeyRoutedEventArgs && (e as KeyRoutedEventArgs).Key == Key.Space)
                {
                    await Launcher.LaunchUriAsync(new Uri(hyperlinkControl.NavigateUri.AbsoluteUri));
                }
#endif
            }
        }