Facebook
From grzesiek51114, 7 Years ago, written in C#.
This paste is a reply to DataGridDP from grzesiek51114 - view diff
Embed
Download Paste or View Raw
Hits: 518
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Input;
  8. using System.Windows.Media;
  9.  
  10. namespace TasksProviderV3.Helpers
  11. {
  12.     public static class DataGridDP
  13.     {
  14.         public static readonly DependencyProperty DoubleClickProperty;
  15.  
  16.         static DataGridDP()
  17.         {
  18.             DoubleClickProperty = DependencyProperty.RegisterAttached("DoubleClick", typeof(ICommand), typeof(DataGridDP),
  19.                 new UIPropertyMetadata(null, OnDoubleClickPropertyChanged));
  20.         }
  21.  
  22.         public static void OnDoubleClickPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
  23.         {
  24.             var grid = obj as DataGrid;
  25.             if (grid != null)
  26.             {
  27.                 var command = e.NewValue as ICommand;
  28.                 if (e.OldValue == null && e.NewValue != null) grid.MouseDoubleClick += Grid_MouseDoubleClick;
  29.                 else if (e.OldValue != null && e.NewValue == null) grid.MouseDoubleClick -= Grid_MouseDoubleClick;
  30.             }
  31.         }
  32.  
  33.         private static void Grid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  34.         {
  35.             var obj = sender as DependencyObject;
  36.             var command = obj.GetValue(DoubleClickProperty) as ICommand;
  37.  
  38.                         if (command != null && command.CanExecute(obj))
  39.             {
  40.                 command.Execute(obj);
  41.             }
  42.         }
  43.  
  44.         public static void SetDoubleClick(DependencyObject obj, ICommand value)
  45.         {
  46.             obj.SetValue(DoubleClickProperty, value);
  47.         }
  48.  
  49.         public static ICommand GetValue(DependencyObject obj)
  50.         {
  51.             return obj.GetValue(DoubleClickProperty) as ICommand;
  52.         }
  53.     }
  54. }
  55.  

Replies to Re: DataGridDP rss

Title Name Language When
Re: Re: DataGridDP grzesiek51114 csharp 7 Years ago.