/// We don't provide default Paste but this public method is exposed to help custom implementation of Paste /// <summary> /// This method stores the cellContent into the item object using ClipboardContentBinding. /// </summary> /// <param name="item"></param> /// <param name="cellContent"></param> public virtual void OnPastingCellClipboardContent(object item, object cellContent) { BindingBase binding = ClipboardContentBinding; if (binding != null) { // Raise the event to give a chance for external listeners to modify the cell content // before it gets stored into the cell if (PastingCellClipboardContent != null) { DataGridCellClipboardEventArgs args = new DataGridCellClipboardEventArgs(item, this, cellContent); PastingCellClipboardContent(this, args); cellContent = args.Content; } // Event handlers can cancel Paste of a cell by setting its content to null if (cellContent != null) { DataGridOwner.SetCellClipboardValue(item, this, cellContent); } } }
/// <summary> /// Handles the CopyingCellClipboardContent event of the PercentageColumn control. Uses a custom CopyingCellClipboardContent /// event handler that formats the percentage as a string before copying it to the clipboard. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e"> /// The <see cref="DataGridCellClipboardEventArgs" /> instance containing the event data. /// </param> private void percentageColumn_CopyingCellClipboardContent(object sender, DataGridCellClipboardEventArgs e) { EventHandlers.PercentageColumn_CopyingCellClipboardContent(e); }
/// <summary> /// This method is called for each selected cell in each selected cell to retrieve the default cell content. /// Default cell content is calculated using ClipboardContentBinding. /// </summary> /// <param name="item"></param> /// <returns></returns> public virtual object OnCopyingCellClipboardContent(object item) { object cellValue = DataGridOwner.GetCellClipboardValue(item, this); // Raise the event to give a chance for external listeners to modify the cell content if (CopyingCellClipboardContent != null) { DataGridCellClipboardEventArgs args = new DataGridCellClipboardEventArgs(item, this, cellValue); CopyingCellClipboardContent(this, args); cellValue = args.Content; } return cellValue; }
/// <summary> /// Handles the CopyingCellClipboardContent event of the colPlayerHome control. Uses a custom CopyingCellCpiboardContent event /// handler that replaces the player ID with the player name. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e"> /// The <see cref="DataGridCellClipboardEventArgs" /> instance containing the event data. /// </param> private void colPlayerHome_CopyingCellClipboardContent(object sender, DataGridCellClipboardEventArgs e) { EventHandlers.PlayerColumn_CopyingCellClipboardContent(e, playersListHome); }
private void DataGridTextColumn_PastingCellClipboardContent(object sender, DataGridCellClipboardEventArgs e) { }
/// <summary> /// Substitutes the Player ID value with the Player's name before copying the data to the clipboard. Used for data-bound columns /// containing player selection combo-boxes. /// </summary> /// <param name="e"> /// The <see cref="DataGridCellClipboardEventArgs" /> instance containing the event data. /// </param> /// <param name="playersList">The players list.</param> public static void PlayerColumn_CopyingCellClipboardContent( DataGridCellClipboardEventArgs e, IEnumerable<KeyValuePair<int, string>> playersList) { try { foreach (var p in playersList) { if (Convert.ToInt32(e.Content) == p.Key) { e.Content = p.Value; break; } } } catch (Exception ex) { Console.WriteLine("Tried to format player column on copy: " + ex.Message); } }
/// <summary>Formats the data being copied to the clipboard. Used for columns containing percentage data.</summary> /// <param name="e"> /// The <see cref="DataGridCellClipboardEventArgs" /> instance containing the event data. /// </param> public static void PercentageColumn_CopyingCellClipboardContent(DataGridCellClipboardEventArgs e) { try { e.Content = String.Format("{0:F3}", e.Content); } catch (Exception ex) { Console.WriteLine("Tried to format percentage column on copy: " + ex.Message); } }
private void Title_PastingCellClipboardContent(object sender, DataGridCellClipboardEventArgs e) { ((DataForXaml)e.Item).Title = e.Content.ToString(); }