- XamlPatterns_v1.1.0.0.zip
- Controls
- Core
- docu
- Program
- Pub
- Desktop.Debug
- Itenso.Community.XamlPatterns.Controls.dll
- Itenso.Community.XamlPatterns.dll
- Desktop.Release
- Itenso.Community.XamlPatterns.Controls.dll
- Itenso.Community.XamlPatterns.dll
- Silverlight.Debug
- Itenso.Community.XamlPatterns.Controls.dll
- Itenso.Community.XamlPatterns.dll
- Silverlight.Release
- Itenso.Community.XamlPatterns.Controls.dll
- Itenso.Community.XamlPatterns.dll
- WindowsPhone.Debug
- Itenso.Community.XamlPatterns.Controls.dll
- Itenso.Community.XamlPatterns.dll
- WindowsPhone.Release
- Itenso.Community.XamlPatterns.Controls.dll
- Itenso.Community.XamlPatterns.dll
- XamlPatterns.Desktop.sln
- XamlPatterns.Desktop.suo
- XamlPatterns.Silverlight.sln
- XamlPatterns.Silverlight.suo
- XamlPatterns.WindowsPhone.sln
- XamlPatterns.WindowsPhone.suo
|
// -- FILE ------------------------------------------------------------------
// name : ModelDataGrid.cs
// project : Itenso Community
// created : Jani Giannoudis - 2012.05.05
// language : c#
// environment: .NET 4.0
// copyright : (c) 2004-2012 by Itenso GmbH, Switzerland
// --------------------------------------------------------------------------
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Itenso.Community.XamlPatterns.Windows;
using ICommand = Itenso.Community.XamlPatterns.Windows.Input.ICommand;
namespace Itenso.Community.XamlPatterns.Controls
{
// ------------------------------------------------------------------------
public class ModelDataGrid : DataGrid, IDisposable
{
// ----------------------------------------------------------------------
public static readonly DependencyProperty ItemCreateCommandProperty = DependencyProperty.RegisterAttached(
"ItemCreateCommand",
typeof( ICommand ),
typeof( ModelDataGrid ),
null );
// ----------------------------------------------------------------------
public static readonly DependencyProperty ItemEditCommandProperty = DependencyProperty.RegisterAttached(
"ItemEditCommand",
typeof( ICommand ),
typeof( ModelDataGrid ),
new PropertyMetadata( ItemEditCommandPropertyChanged ) );
// ----------------------------------------------------------------------
public static readonly DependencyProperty ItemDeleteCommandProperty = DependencyProperty.RegisterAttached(
"ItemDeleteCommand",
typeof( ICommand ),
typeof( ModelDataGrid ),
null );
// ----------------------------------------------------------------------
public ICommand ItemCreateCommand
{
get { return (ICommand)GetValue( ItemCreateCommandProperty ); }
set { SetValue( ItemCreateCommandProperty, value ); }
} // ItemCreateCommand
// ----------------------------------------------------------------------
public ICommand ItemEditCommand
{
get { return (ICommand)GetValue( ItemEditCommandProperty ); }
set { SetValue( ItemEditCommandProperty, value ); }
} // ItemEditCommand
// ----------------------------------------------------------------------
public ICommand ItemDeleteCommand
{
get { return (ICommand)GetValue( ItemDeleteCommandProperty ); }
set { SetValue( ItemDeleteCommandProperty, value ); }
} // ItemDeleteCommand
// ----------------------------------------------------------------------
public void Dispose()
{
Dispose( true );
GC.SuppressFinalize( this );
} // Dispose
// ----------------------------------------------------------------------
protected virtual void Dispose( bool disposing )
{
if ( disposing )
{
if ( mouseClickManager != null )
{
mouseClickManager.DoubleClick -= MouseDoubleClickHandler;
}
}
} // Dispose
// ----------------------------------------------------------------------
protected override void OnKeyDown( KeyEventArgs e )
{
base.OnKeyDown( e );
if ( Keyboard.Modifiers != ModifierKeys.None )
{
return;
}
switch ( e.Key )
{
case Key.Insert:
e.Handled = HandleCommandRequest( ItemCreateCommand );
break;
case Key.F2:
e.Handled = HandleCommandRequest( ItemEditCommand );
break;
case Key.Delete:
e.Handled = HandleCommandRequest( ItemDeleteCommand );
break;
}
} // OnKeyDown
// ----------------------------------------------------------------------
protected override void OnMouseLeftButtonUp( MouseButtonEventArgs e )
{
base.OnMouseLeftButtonUp( e );
if ( mouseClickManager != null )
{
mouseClickManager.HandleClick( e );
}
} // OnMouseLeftButtonUp
// ----------------------------------------------------------------------
protected bool HandleCommandRequest( ICommand command, object parameter = null )
{
if ( command == null )
{
return false;
}
if ( !command.CanExecute( parameter ) )
{
return false;
}
command.Execute( parameter );
return true;
} // HandleCommandRequest
// ----------------------------------------------------------------------
private void SetupItemEditCommand()
{
if ( ItemEditCommand == null || mouseClickManager != null )
{
return;
}
mouseClickManager = new MouseClickManager( this );
mouseClickManager.DoubleClick += MouseDoubleClickHandler;
} // SetupItemEditCommand
// ----------------------------------------------------------------------
private void MouseDoubleClickHandler( object sender, MouseButtonEventArgs e )
{
HandleCommandRequest( ItemEditCommand );
} // MouseDoubleClickHandler
// ----------------------------------------------------------------------
private static void ItemEditCommandPropertyChanged( DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e )
{
((ModelDataGrid)dependencyObject).SetupItemEditCommand();
} // ItemEditCommandPropertyChanged
// ----------------------------------------------------------------------
// members
private MouseClickManager mouseClickManager;
} // class ModelDataGrid
} // namespace Itenso.Community.XamlPatterns.Controls
// -- EOF -------------------------------------------------------------------
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
👨 Senior .NET Software Engineer
🚀 My Open Source Projects
-
Time Period Library 👉
GitHub
-
Payroll Engine 👉
GitHub
Feedback and contributions are welcome.