Browse Source

upgrade Xceed.Wpf.DataGrid

fix a couple of issues and some commented. we don't really care much about this project since we dont use it in propresenter
pull/1778/head
Pat Limosnero 2 years ago
parent
commit
c80d2f58e6
  1. 1716
      ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/(CollectionView)/DataGridCollectionViewGroup.cs
  2. 128
      ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/(CollectionView)/EntityDetailDescription.cs
  3. 58
      ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/(CollectionView)/QueryEntityDetailsEventArgs.cs
  4. 96
      ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/AssemblyVersionInfo.cs
  5. 134
      ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/Converters/ImageConverter.cs
  6. 6776
      ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/DataGridContext.cs
  7. 568
      ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/GenericContentTemplateSelector.cs
  8. 637
      ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/GroupHeaderControl.cs
  9. 4319
      ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/ItemsSourceHelper.cs
  10. 78
      ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/Properties/AssemblyInfo.cs
  11. 1142
      ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/Utils/Wpf/DragDrop/DragSourceManagerBase.cs
  12. 1182
      ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/Xceed.Wpf.DataGrid.csproj
  13. 2
      ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.sln

1716
ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/(CollectionView)/DataGridCollectionViewGroup.cs

File diff suppressed because it is too large

128
ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/(CollectionView)/EntityDetailDescription.cs

@ -17,91 +17,91 @@
using System;
using System.Collections;
using System.ComponentModel;
using System.Data.Objects.DataClasses;
using System.Data.Entity.Core.Objects.DataClasses;
using System.Reflection;
namespace Xceed.Wpf.DataGrid
{
internal class EntityDetailDescription : DataGridDetailDescription
{
public EntityDetailDescription()
internal class EntityDetailDescription : DataGridDetailDescription
{
}
public EntityDetailDescription( string propertyName )
: this()
{
if( string.IsNullOrEmpty( propertyName ) )
throw new ArgumentException( "The specified property name is null or empty", "propertyName" );
public EntityDetailDescription()
{
}
this.RelationName = propertyName;
}
public EntityDetailDescription(string propertyName)
: this()
{
if (string.IsNullOrEmpty(propertyName))
throw new ArgumentException("The specified property name is null or empty", "propertyName");
#region QueryDetails Event
this.RelationName = propertyName;
}
public event EventHandler<QueryEntityDetailsEventArgs> QueryDetails;
#region QueryDetails Event
protected virtual void OnQueryDetails( QueryEntityDetailsEventArgs e )
{
var handler = this.QueryDetails;
if( handler == null )
return;
public event EventHandler<QueryEntityDetailsEventArgs> QueryDetails;
handler.Invoke( this, e );
}
protected virtual void OnQueryDetails(QueryEntityDetailsEventArgs e)
{
var handler = this.QueryDetails;
if (handler == null)
return;
#endregion
handler.Invoke(this, e);
}
protected internal override IEnumerable GetDetailsForParentItem( DataGridCollectionViewBase parentCollectionView, object parentItem )
{
EntityObject entityObject = parentItem as EntityObject;
#endregion
if( entityObject == null )
return null;
protected internal override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
{
EntityObject entityObject = parentItem as EntityObject;
// Even if EntityObject is not in a loadable state, we must still return the IList
// so that the ItemProperties can be extracted based on the elements type.
bool entityObjectLoadable = ItemsSourceHelper.IsEntityObjectLoadable( entityObject );
if (entityObject == null)
return null;
// We let the user take charge of handling the details.
QueryEntityDetailsEventArgs args = new QueryEntityDetailsEventArgs( entityObject );
// Even if EntityObject is not in a loadable state, we must still return the IList
// so that the ItemProperties can be extracted based on the elements type.
bool entityObjectLoadable = ItemsSourceHelper.IsEntityObjectLoadable(entityObject);
if( entityObjectLoadable )
this.OnQueryDetails( args );
// We let the user take charge of handling the details.
QueryEntityDetailsEventArgs args = new QueryEntityDetailsEventArgs(entityObject);
// The parentItem must implement IEntityWithRelationships
Type parentItemType = parentItem.GetType();
if( typeof( IEntityWithRelationships ).IsAssignableFrom( parentItemType ) )
{
// Since the relationship was based on the the property
// name, we must find that property using reflection.
PropertyInfo propertyInfo = parentItemType.GetProperty( this.RelationName );
if (entityObjectLoadable)
this.OnQueryDetails(args);
if( propertyInfo != null )
{
RelatedEnd relatedEnd = propertyInfo.GetValue( parentItem, null ) as RelatedEnd;
if( relatedEnd != null )
{
// Make sure that the details are loaded
// except if the user already handled it.
if( !relatedEnd.IsLoaded
&& !args.Handled
&& entityObjectLoadable )
// The parentItem must implement IEntityWithRelationships
Type parentItemType = parentItem.GetType();
if (typeof(IEntityWithRelationships).IsAssignableFrom(parentItemType))
{
relatedEnd.Load();
// Since the relationship was based on the the property
// name, we must find that property using reflection.
PropertyInfo propertyInfo = parentItemType.GetProperty(this.RelationName);
if (propertyInfo != null)
{
RelatedEnd relatedEnd = propertyInfo.GetValue(parentItem, null) as RelatedEnd;
if (relatedEnd != null)
{
// Make sure that the details are loaded
// except if the user already handled it.
if (!relatedEnd.IsLoaded
&& !args.Handled
&& entityObjectLoadable)
{
relatedEnd.Load();
}
IListSource listSource = relatedEnd as IListSource;
// Returns an IList to have proper change notification events.
if (listSource != null)
return listSource.GetList();
}
}
}
IListSource listSource = relatedEnd as IListSource;
// Returns an IList to have proper change notification events.
if( listSource != null )
return listSource.GetList();
}
return null;
}
}
return null;
}
}
}

58
ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/(CollectionView)/QueryEntityDetailsEventArgs.cs

@ -15,47 +15,43 @@
***********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Data.Objects.DataClasses;
using System.Data.Entity.Core.Objects.DataClasses;
namespace Xceed.Wpf.DataGrid
{
public class QueryEntityDetailsEventArgs : EventArgs
{
#region CONSTRUCTORS
internal QueryEntityDetailsEventArgs( EntityObject parentItem )
: base()
public class QueryEntityDetailsEventArgs : EventArgs
{
if( parentItem == null )
throw new ArgumentNullException( "parentItem" );
#region CONSTRUCTORS
this.ParentItem = parentItem;
}
internal QueryEntityDetailsEventArgs(EntityObject parentItem)
: base()
{
if (parentItem == null)
throw new ArgumentNullException("parentItem");
#endregion CONSTRUCTORS
this.ParentItem = parentItem;
}
#region ParentItem Property
#endregion CONSTRUCTORS
public EntityObject ParentItem
{
get;
private set;
}
#region ParentItem Property
#endregion ParentItem Property
public EntityObject ParentItem
{
get;
private set;
}
#region Handled Property
#endregion ParentItem Property
public bool Handled
{
get;
set;
}
#region Handled Property
#endregion Handled Property
}
public bool Handled
{
get;
set;
}
#endregion Handled Property
}
}

96
ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/AssemblyVersionInfo.cs

@ -14,28 +14,86 @@
***********************************************************************************/
[assembly: System.Reflection.AssemblyVersion( _XceedVersionInfo.Version )]
#region Using directives
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Windows;
using System.Windows.Markup;
#endregion
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Xceed Toolkit for WPF - DataGrid")]
[assembly: AssemblyDescription("This assembly implements the Xceed.Wpf.DataGrid namespace, a data grid control for the Windows Presentation Framework.")]
[assembly: AssemblyCompany("Xceed Software Inc.")]
[assembly: AssemblyProduct("Xceed Toolkit for WPF - DataGrid")]
[assembly: AssemblyCopyright("Copyright (C) Xceed Software Inc. 2007-2017")]
[assembly: CLSCompliant(true)]
[assembly: ComVisible(false)]
[assembly: XmlnsPrefix("http://schemas.xceed.com/wpf/xaml/datagrid", "xcdg")]
[assembly: XmlnsDefinition("http://schemas.xceed.com/wpf/xaml/datagrid", "Xceed.Wpf.DataGrid")]
[assembly: XmlnsDefinition("http://schemas.xceed.com/wpf/xaml/datagrid", "Xceed.Wpf.DataGrid.Converters")]
[assembly: XmlnsDefinition("http://schemas.xceed.com/wpf/xaml/datagrid", "Xceed.Wpf.DataGrid.Markup")]
[assembly: XmlnsDefinition("http://schemas.xceed.com/wpf/xaml/datagrid", "Xceed.Wpf.DataGrid.Views")]
[assembly: XmlnsDefinition("http://schemas.xceed.com/wpf/xaml/datagrid", "Xceed.Wpf.DataGrid.ValidationRules")]
[assembly: SecurityRules(SecurityRuleSet.Level1)]
[assembly: AllowPartiallyTrustedCallers]
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.SourceAssembly, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
#pragma warning disable 1699
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile(@"sn.snk")]
[assembly: AssemblyKeyName("")]
#pragma warning restore 1699
internal static class _XceedVersionInfo
{
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )]
public const string BaseVersion = "3.4";
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )]
public const string Version = BaseVersion + ".0.0";
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )]
public const string PublicKeyToken = "ba83ff368b7563c6";
public const string FrameworkVersion = "4.0.0.0";
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )]
public const string DesignFullName =
"Xceed.Wpf.DataGrid,Version=" +
Version +
",Culture=neutral,PublicKeyToken=" + PublicKeyToken;
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )]
public const string CurrentAssemblyPackUri =
"pack://application:,,,/Xceed.Wpf.DataGrid,Version=" + Version;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const string BaseVersion = "3.4";
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const string Version = BaseVersion + ".0.0";
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const string PublicKeyToken = "ba83ff368b7563c6";
public const string FrameworkVersion = "4.0.0.0";
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const string DesignFullName =
"Xceed.Wpf.DataGrid,Version=" +
Version +
",Culture=neutral,PublicKeyToken=" + PublicKeyToken;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const string CurrentAssemblyPackUri =
"pack://application:,,,/Xceed.Wpf.DataGrid,Version=" + Version;
}

134
ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/Converters/ImageConverter.cs

@ -15,96 +15,92 @@
***********************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Windows;
using System.Windows.Data;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows;
using System.ComponentModel;
namespace Xceed.Wpf.DataGrid.Converters
{
[EditorBrowsable( EditorBrowsableState.Never )]
[ValueConversion( typeof( object ), typeof( ImageSource ) )]
public class ImageConverter : IValueConverter
{
#region IValueConverter Members
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1800:DoNotCastUnnecessarily" )]
public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
[EditorBrowsable(EditorBrowsableState.Never)]
[ValueConversion(typeof(object), typeof(ImageSource))]
public class ImageConverter : IValueConverter
{
if( !targetType.IsAssignableFrom( typeof( ImageSource ) ) )
return DependencyProperty.UnsetValue;
#region IValueConverter Members
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (!targetType.IsAssignableFrom(typeof(ImageSource)))
return DependencyProperty.UnsetValue;
if( ( value == null ) || ( value is ImageSource ) )
return value;
if ((value == null) || (value is ImageSource))
return value;
ImageSource imageSource = null;
ImageSource imageSource = null;
System.Drawing.Image image = value as System.Drawing.Image;
//System.Drawing.Image image = value as System.Drawing.Image;
if( image != null )
{
imageSource = ImageConverter.ConvertFromWinFormsImage( image );
}
else
{
byte[] byteArray = value as byte[];
//if (image != null)
//{
// imageSource = ImageConverter.ConvertFromWinFormsImage(image);
//}
//else
//{
byte[] byteArray = value as byte[];
if( byteArray != null )
{
imageSource = ImageConverter.ConvertFromByteArray( byteArray );
if (byteArray != null)
{
imageSource = ImageConverter.ConvertFromByteArray(byteArray);
}
//}
return imageSource;
}
}
return imageSource;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Binding.DoNothing;
}
public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
{
return Binding.DoNothing;
}
#endregion
#endregion
#region PRIVATE METHODS
#region PRIVATE METHODS
//private static ImageSource ConvertFromWinFormsImage(System.Drawing.Image image)
//{
// ImageSource imageSource = null;
private static ImageSource ConvertFromWinFormsImage( System.Drawing.Image image )
{
ImageSource imageSource = null;
// try
// {
// System.Drawing.ImageConverter imageConverter = new System.Drawing.ImageConverter();
try
{
System.Drawing.ImageConverter imageConverter = new System.Drawing.ImageConverter();
// byte[] imageBytes = (byte[])imageConverter.ConvertTo(image, typeof(byte[]));
byte[] imageBytes = ( byte[] )imageConverter.ConvertTo( image, typeof( byte[] ) );
// if (imageBytes != null)
// imageSource = ImageConverter.ConvertFromByteArray(imageBytes);
// }
// catch { }
if( imageBytes != null )
imageSource = ImageConverter.ConvertFromByteArray( imageBytes );
}
catch {}
// return imageSource;
//}
return imageSource;
}
private static ImageSource ConvertFromByteArray(byte[] imageBytes)
{
ImageSource imageSource = null;
try
{
ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
imageSource = imageSourceConverter.ConvertFrom(imageBytes) as ImageSource;
}
catch
{
}
return imageSource;
}
private static ImageSource ConvertFromByteArray( byte[] imageBytes )
{
ImageSource imageSource = null;
try
{
ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
imageSource = imageSourceConverter.ConvertFrom( imageBytes ) as ImageSource;
}
catch
{
}
return imageSource;
#endregion PRIVATE METHODS
}
#endregion PRIVATE METHODS
}
}

6776
ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/DataGridContext.cs

File diff suppressed because it is too large

568
ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/GenericContentTemplateSelector.cs

@ -31,370 +31,370 @@ using Xceed.Wpf.DataGrid.Converters;
namespace Xceed.Wpf.DataGrid
{
internal sealed class GenericContentTemplateSelector : DataTemplateSelector
{
#region Static Fields
internal sealed class GenericContentTemplateSelector : DataTemplateSelector
{
#region Static Fields
internal static readonly DataTemplate ForeignKeyCellContentTemplate;
internal static readonly DataTemplate ForeignKeyGroupValueTemplate;
internal static readonly DataTemplate ForeignKeyScrollTipContentTemplate;
internal static readonly DataTemplate ForeignKeyCellContentTemplate;
internal static readonly DataTemplate ForeignKeyGroupValueTemplate;
internal static readonly DataTemplate ForeignKeyScrollTipContentTemplate;
private static readonly DataTemplate BoolTemplate;
private static readonly DataTemplate CommonTemplate;
private static readonly DataTemplate ImageTemplate;
private static readonly DataTemplate BoolTemplate;
private static readonly DataTemplate CommonTemplate;
private static readonly DataTemplate ImageTemplate;
private static readonly List<KeyValuePair<Type, WeakReference>> DefaultTemplates = new List<KeyValuePair<Type, WeakReference>>( 0 );
private static readonly List<KeyValuePair<Type, WeakReference>> DefaultTemplates = new List<KeyValuePair<Type, WeakReference>>(0);
private static readonly GenericContentTemplateSelectorResources GenericContentTemplateResources = new GenericContentTemplateSelectorResources();
private static readonly GenericContentTemplateSelectorResources GenericContentTemplateResources = new GenericContentTemplateSelectorResources();
private static Func<DependencyObject, object, Type, object> FindTemplateResource; //null
private static Func<DependencyObject, object, Type, object> FindTemplateResource; //null
#endregion
#endregion
#region Constructors
#region Constructors
static GenericContentTemplateSelector()
{
// We need to initalize the ResourceDictionary before accessing since we access
// it in a static constructor and will be called before the Layout was performed
GenericContentTemplateSelector.GenericContentTemplateResources.InitializeComponent();
static GenericContentTemplateSelector()
{
// We need to initalize the ResourceDictionary before accessing since we access
// it in a static constructor and will be called before the Layout was performed
GenericContentTemplateSelector.GenericContentTemplateResources.InitializeComponent();
GenericContentTemplateSelector.BoolTemplate = GenericContentTemplateSelector.GenericContentTemplateResources[ "booleanDefaultContentTemplate" ] as DataTemplate;
Debug.Assert( GenericContentTemplateSelector.BoolTemplate != null );
GenericContentTemplateSelector.BoolTemplate.Seal();
GenericContentTemplateSelector.BoolTemplate = GenericContentTemplateSelector.GenericContentTemplateResources["booleanDefaultContentTemplate"] as DataTemplate;
Debug.Assert(GenericContentTemplateSelector.BoolTemplate != null);
GenericContentTemplateSelector.BoolTemplate.Seal();
GenericContentTemplateSelector.CommonTemplate = GenericContentTemplateSelector.GenericContentTemplateResources[ "commonDefaultContentTemplate" ] as DataTemplate;
Debug.Assert( GenericContentTemplateSelector.CommonTemplate != null );
GenericContentTemplateSelector.CommonTemplate.Seal();
GenericContentTemplateSelector.CommonTemplate = GenericContentTemplateSelector.GenericContentTemplateResources["commonDefaultContentTemplate"] as DataTemplate;
Debug.Assert(GenericContentTemplateSelector.CommonTemplate != null);
GenericContentTemplateSelector.CommonTemplate.Seal();
GenericContentTemplateSelector.ImageTemplate = GenericContentTemplateSelector.GenericContentTemplateResources[ "imageDefaultContentTemplate" ] as DataTemplate;
Debug.Assert( GenericContentTemplateSelector.ImageTemplate != null );
GenericContentTemplateSelector.ImageTemplate.Seal();
GenericContentTemplateSelector.ImageTemplate = GenericContentTemplateSelector.GenericContentTemplateResources["imageDefaultContentTemplate"] as DataTemplate;
Debug.Assert(GenericContentTemplateSelector.ImageTemplate != null);
GenericContentTemplateSelector.ImageTemplate.Seal();
GenericContentTemplateSelector.ForeignKeyCellContentTemplate = GenericContentTemplateSelector.GenericContentTemplateResources[ "foreignKeyDefaultContentTemplate" ] as DataTemplate;
Debug.Assert( GenericContentTemplateSelector.ForeignKeyCellContentTemplate != null );
GenericContentTemplateSelector.ForeignKeyCellContentTemplate.Seal();
GenericContentTemplateSelector.ForeignKeyCellContentTemplate = GenericContentTemplateSelector.GenericContentTemplateResources["foreignKeyDefaultContentTemplate"] as DataTemplate;
Debug.Assert(GenericContentTemplateSelector.ForeignKeyCellContentTemplate != null);
GenericContentTemplateSelector.ForeignKeyCellContentTemplate.Seal();
GenericContentTemplateSelector.ForeignKeyGroupValueTemplate = GenericContentTemplateSelector.GenericContentTemplateResources[ "foreignKeyGroupValueDefaultContentTemplate" ] as DataTemplate;
Debug.Assert( GenericContentTemplateSelector.ForeignKeyGroupValueTemplate != null );
GenericContentTemplateSelector.ForeignKeyGroupValueTemplate.Seal();
GenericContentTemplateSelector.ForeignKeyGroupValueTemplate = GenericContentTemplateSelector.GenericContentTemplateResources["foreignKeyGroupValueDefaultContentTemplate"] as DataTemplate;
Debug.Assert(GenericContentTemplateSelector.ForeignKeyGroupValueTemplate != null);
GenericContentTemplateSelector.ForeignKeyGroupValueTemplate.Seal();
GenericContentTemplateSelector.ForeignKeyScrollTipContentTemplate = GenericContentTemplateSelector.GenericContentTemplateResources[ "foreignKeyScrollTipDefaultContentTemplate" ] as DataTemplate;
Debug.Assert( GenericContentTemplateSelector.ForeignKeyScrollTipContentTemplate != null );
GenericContentTemplateSelector.ForeignKeyScrollTipContentTemplate.Seal();
}
GenericContentTemplateSelector.ForeignKeyScrollTipContentTemplate = GenericContentTemplateSelector.GenericContentTemplateResources["foreignKeyScrollTipDefaultContentTemplate"] as DataTemplate;
Debug.Assert(GenericContentTemplateSelector.ForeignKeyScrollTipContentTemplate != null);
GenericContentTemplateSelector.ForeignKeyScrollTipContentTemplate.Seal();
}
private GenericContentTemplateSelector()
{
}
private GenericContentTemplateSelector()
{
}
#endregion
#endregion
#region Instance Static Property
#region Instance Static Property
public static GenericContentTemplateSelector Instance
{
get
{
return m_instance;
}
}
public static GenericContentTemplateSelector Instance
{
get
{
return m_instance;
}
}
private static GenericContentTemplateSelector m_instance = new GenericContentTemplateSelector();
private static GenericContentTemplateSelector m_instance = new GenericContentTemplateSelector();
#endregion
#endregion
public override DataTemplate SelectTemplate( object item, DependencyObject container )
{
if( item == null )
return base.SelectTemplate( item, container );
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item == null)
return base.SelectTemplate(item, container);
DataTemplate template = null;
DataTemplate template = null;
if( ( item is byte[] ) || ( item is System.Drawing.Image ) )
{
bool useImageTemplate = false;
if ((item is byte[]) /*|| (item is System.Drawing.Image)*/)
{
bool useImageTemplate = false;
try
{
var converter = new ImageConverter();
useImageTemplate = (converter.Convert(item, typeof(ImageSource), null, CultureInfo.CurrentCulture) != null);
}
catch (NotSupportedException)
{
//suppress the exception, the byte[] is not an image. convertedValue will remain null
}
if (useImageTemplate)
{
template = GenericContentTemplateSelector.GetImageTemplate(container);
}
}
else if (item is ImageSource)
{
template = GenericContentTemplateSelector.GetImageTemplate(container);
}
else if (item is bool)
{
template = GenericContentTemplateSelector.BoolTemplate;
}
try
{
var converter = new ImageConverter();
useImageTemplate = ( converter.Convert( item, typeof( ImageSource ), null, CultureInfo.CurrentCulture ) != null );
if (template == null)
{
template = GenericContentTemplateSelector.GetCommonTemplate(item, container);
}
if (template != null)
return template;
return base.SelectTemplate(item, container);
}
catch( NotSupportedException )
private static DataTemplate GetImageTemplate(DependencyObject container)
{
//suppress the exception, the byte[] is not an image. convertedValue will remain null
return GenericContentTemplateSelector.ImageTemplate;
}
if( useImageTemplate )
private static DataTemplate GetCommonTemplate(object item, DependencyObject container)
{
template = GenericContentTemplateSelector.GetImageTemplate( container );
}
}
else if( item is ImageSource )
{
template = GenericContentTemplateSelector.GetImageTemplate( container );
}
else if( item is bool )
{
template = GenericContentTemplateSelector.BoolTemplate;
}
if( template == null )
{
template = GenericContentTemplateSelector.GetCommonTemplate( item, container );
}
if( template != null )
return template;
return base.SelectTemplate( item, container );
}
Debug.Assert(item != null);
private static DataTemplate GetImageTemplate( DependencyObject container )
{
return GenericContentTemplateSelector.ImageTemplate;
}
var itemType = item.GetType();
private static DataTemplate GetCommonTemplate( object item, DependencyObject container )
{
Debug.Assert( item != null );
// Do not provide a template for data types that are already optimized by the framework or
// for data types that have a default template.
if (GenericContentTemplateSelector.IsTypeOptimized(itemType)
|| GenericContentTemplateSelector.HasImplicitTemplate(item, itemType, container))
return null;
var itemType = item.GetType();
return GenericContentTemplateSelector.GetDefaultTemplate(itemType);
}
// Do not provide a template for data types that are already optimized by the framework or
// for data types that have a default template.
if( GenericContentTemplateSelector.IsTypeOptimized( itemType )
|| GenericContentTemplateSelector.HasImplicitTemplate( item, itemType, container ) )
return null;
private static DataTemplate GetDefaultTemplate(Type type)
{
Debug.Assert(type != null);
return GenericContentTemplateSelector.GetDefaultTemplate( itemType );
}
var converter = TypeDescriptor.GetConverter(type);
if ((converter == null) || (!converter.CanConvertTo(typeof(string))))
return GenericContentTemplateSelector.CommonTemplate;
private static DataTemplate GetDefaultTemplate( Type type )
{
Debug.Assert( type != null );
var templates = GenericContentTemplateSelector.DefaultTemplates;
lock (((ICollection)templates).SyncRoot)
{
for (int i = templates.Count - 1; i >= 0; i--)
{
var target = templates[i];
var targetTemplate = target.Value.Target as DataTemplate;
var converter = TypeDescriptor.GetConverter( type );
if( ( converter == null ) || ( !converter.CanConvertTo( typeof( string ) ) ) )
return GenericContentTemplateSelector.CommonTemplate;
// We have found the desired template.
if (target.Key == type)
{
if (targetTemplate != null)
return targetTemplate;
var templates = GenericContentTemplateSelector.DefaultTemplates;
lock( ( ( ICollection )templates ).SyncRoot )
{
for( int i = templates.Count - 1; i >= 0; i-- )
{
var target = templates[ i ];
var targetTemplate = target.Value.Target as DataTemplate;
// We have found the desired template.
if( target.Key == type )
{
if( targetTemplate != null )
return targetTemplate;
// Unfortunately, the template has been garbage collected.
templates.RemoveAt( i );
break;
}
}
// Unfortunately, the template has been garbage collected.
templates.RemoveAt(i);
break;
}
}
templates.TrimExcess();
templates.TrimExcess();
var template = GenericContentTemplateSelector.CreateDefaultTemplate( type, converter );
var template = GenericContentTemplateSelector.CreateDefaultTemplate(type, converter);
templates.Add( new KeyValuePair<Type, WeakReference>( type, new WeakReference( template ) ) );
templates.Add(new KeyValuePair<Type, WeakReference>(type, new WeakReference(template)));
return template;
}
}
return template;
}
}
private static DataTemplate CreateDefaultTemplate( Type type, TypeConverter converter )
{
Debug.Assert( type != null );
Debug.Assert( converter != null );
private static DataTemplate CreateDefaultTemplate(Type type, TypeConverter converter)
{
Debug.Assert(type != null);
Debug.Assert(converter != null);
var template = new DataTemplate();
var factory = new FrameworkElementFactory( typeof( TextBlock ) );
var template = new DataTemplate();
var factory = new FrameworkElementFactory(typeof(TextBlock));
var binding = new Binding();
binding.Mode = BindingMode.OneWay;
binding.Converter = new DefaultConverter( converter );
binding.ConverterCulture = CultureInfo.CurrentCulture;
var binding = new Binding();
binding.Mode = BindingMode.OneWay;
binding.Converter = new DefaultConverter(converter);
binding.ConverterCulture = CultureInfo.CurrentCulture;
factory.SetBinding( TextBlock.TextProperty, binding );
factory.SetBinding(TextBlock.TextProperty, binding);
template.VisualTree = factory;
template.Seal();
template.VisualTree = factory;
template.Seal();
return template;
}
return template;
}
private static bool IsTypeOptimized( Type type )
{
Debug.Assert( type != null );
private static bool IsTypeOptimized(Type type)
{
Debug.Assert(type != null);
if( typeof( string ).IsAssignableFrom( type )
|| typeof( UIElement ).IsAssignableFrom( type )
|| typeof( XmlNode ).IsAssignableFrom( type ) )
return true;
if (typeof(string).IsAssignableFrom(type)
|| typeof(UIElement).IsAssignableFrom(type)
|| typeof(XmlNode).IsAssignableFrom(type))
return true;
if( !typeof( Inline ).IsAssignableFrom( type ) )
{
var converter = TypeDescriptor.GetConverter( type );
if( ( converter != null ) && ( converter.CanConvertTo( typeof( UIElement ) ) ) )
return true;
}
if (!typeof(Inline).IsAssignableFrom(type))
{
var converter = TypeDescriptor.GetConverter(type);
if ((converter != null) && (converter.CanConvertTo(typeof(UIElement))))
return true;
}
return false;
}
return false;
}
private static bool HasImplicitTemplate( object item, Type type, DependencyObject container )
{
Debug.Assert( type != null );
private static bool HasImplicitTemplate(object item, Type type, DependencyObject container)
{
Debug.Assert(type != null);
var finder = GenericContentTemplateSelector.FindTemplateResource;
var finder = GenericContentTemplateSelector.FindTemplateResource;
if( finder == null )
{
finder = GenericContentTemplateSelector.GetFindTemplateResourceInternal();
if (finder == null)
{
finder = GenericContentTemplateSelector.GetFindTemplateResourceInternal();
if( finder == null )
{
finder = GenericContentTemplateSelector.FindTemplateResourceFallback;
}
if (finder == null)
{
finder = GenericContentTemplateSelector.FindTemplateResourceFallback;
}
GenericContentTemplateSelector.FindTemplateResource = finder;
}
GenericContentTemplateSelector.FindTemplateResource = finder;
}
Debug.Assert( finder != null );
Debug.Assert(finder != null);
return ( finder.Invoke( container, item, type ) != null );
}
return (finder.Invoke(container, item, type) != null);
}
private static Func<DependencyObject, object, Type, object> GetFindTemplateResourceInternal()
{
try
{
var methodInfo = typeof( FrameworkElement ).GetMethod(
"FindTemplateResourceInternal",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
null,
CallingConventions.Any,
new Type[] { typeof( DependencyObject ), typeof( object ), typeof( Type ) },
null );
if( methodInfo != null )
private static Func<DependencyObject, object, Type, object> GetFindTemplateResourceInternal()
{
var finder = ( Func<DependencyObject, object, Type, object> )Delegate.CreateDelegate( typeof( Func<DependencyObject, object, Type, object> ), methodInfo );
try
{
var methodInfo = typeof(FrameworkElement).GetMethod(
"FindTemplateResourceInternal",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
null,
CallingConventions.Any,
new Type[] { typeof(DependencyObject), typeof(object), typeof(Type) },
null);
if (methodInfo != null)
{
var finder = (Func<DependencyObject, object, Type, object>)Delegate.CreateDelegate(typeof(Func<DependencyObject, object, Type, object>), methodInfo);
return (container, item, type) => finder.Invoke(container, item, typeof(DataTemplate));
}
}
catch (AmbiguousMatchException)
{
// We swallow the exception and use a fallback method instead.
}
catch (MethodAccessException)
{
// We swallow the exception and use a fallback method instead.
}
return ( container, item, type ) => finder.Invoke( container, item, typeof( DataTemplate ) );
return null;
}
}
catch( AmbiguousMatchException )
{
// We swallow the exception and use a fallback method instead.
}
catch( MethodAccessException )
{
// We swallow the exception and use a fallback method instead.
}
return null;
}
private static object FindTemplateResourceFallback( DependencyObject container, object item, Type type )
{
var fe = container as FrameworkElement;
if( fe == null )
return null;
private static object FindTemplateResourceFallback(DependencyObject container, object item, Type type)
{
var fe = container as FrameworkElement;
if (fe == null)
return null;
return fe.TryFindResource( new DataTemplateKey( type ) );
}
return fe.TryFindResource(new DataTemplateKey(type));
}
#region DefaultConverter Private Class
#region DefaultConverter Private Class
private sealed class DefaultConverter : IValueConverter
{
internal DefaultConverter( TypeConverter converter )
{
if( converter == null )
throw new ArgumentNullException( "converter" );
private sealed class DefaultConverter : IValueConverter
{
internal DefaultConverter(TypeConverter converter)
{
if (converter == null)
throw new ArgumentNullException("converter");
m_converter = converter;
}
m_converter = converter;
}
public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
{
object result;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
object result;
if( DefaultConverter.TryConvertTo( value, targetType, culture, m_converter, out result ) )
return result;
if (DefaultConverter.TryConvertTo(value, targetType, culture, m_converter, out result))
return result;
if( value != null )
{
var valueType = value.GetType();
if (value != null)
{
var valueType = value.GetType();
if( DefaultConverter.TryConvertTo( value, targetType, culture, TypeDescriptor.GetConverter( valueType ), out result ) )
return result;
if (DefaultConverter.TryConvertTo(value, targetType, culture, TypeDescriptor.GetConverter(valueType), out result))
return result;
if( targetType.IsAssignableFrom( valueType ) )
return value;
}
else if( DefaultConverter.IsNullableType( targetType ) )
{
return value;
}
if (targetType.IsAssignableFrom(valueType))
return value;
}
else if (DefaultConverter.IsNullableType(targetType))
{
return value;
}
throw new ArgumentException( "Cannot convert to type " + targetType.FullName + ".", "value" );
}
public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture )
{
throw new NotSupportedException();
}
throw new ArgumentException("Cannot convert to type " + targetType.FullName + ".", "value");
}
private static bool TryConvertTo( object value, Type targetType, CultureInfo culture, TypeConverter converter, out object result )
{
if( converter != null )
{
try
{
result = converter.ConvertTo( null, culture, value, targetType );
return true;
}
catch
{
// We'll try to convert the value another way.
}
if( ( value != null ) && ( converter.CanConvertFrom( value.GetType() ) ) )
{
try
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var newValue = converter.ConvertFrom( null, culture, value );
result = converter.ConvertTo( null, culture, newValue, targetType );
return true;
throw new NotSupportedException();
}
catch
private static bool TryConvertTo(object value, Type targetType, CultureInfo culture, TypeConverter converter, out object result)
{
if (converter != null)
{
try
{
result = converter.ConvertTo(null, culture, value, targetType);
return true;
}
catch
{
// We'll try to convert the value another way.
}
if ((value != null) && (converter.CanConvertFrom(value.GetType())))
{
try
{
var newValue = converter.ConvertFrom(null, culture, value);
result = converter.ConvertTo(null, culture, newValue, targetType);
return true;
}
catch
{
}
}
}
result = null;
return false;
}
}
}
result = null;
return false;
}
private static bool IsNullableType(Type type)
{
return (!type.IsValueType)
|| (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Nullable<>)));
}
private static bool IsNullableType( Type type )
{
return ( !type.IsValueType )
|| ( type.IsGenericType && ( type.GetGenericTypeDefinition() == typeof( Nullable<> ) ) );
}
private readonly TypeConverter m_converter;
}
private readonly TypeConverter m_converter;
#endregion
}
#endregion
}
}

637
ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/GroupHeaderControl.cs

@ -16,426 +16,425 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using Xceed.Utils.Wpf;
using Xceed.Wpf.DataGrid.Utils;
namespace Xceed.Wpf.DataGrid
{
public class GroupHeaderControl : ContentControl, INotifyPropertyChanged, IDataGridItemContainer
{
#region Static Fields
internal static readonly string GroupPropertyName = PropertyHelper.GetPropertyName( ( GroupHeaderControl g ) => g.Group );
#endregion
static GroupHeaderControl()
public class GroupHeaderControl : ContentControl, INotifyPropertyChanged, IDataGridItemContainer
{
// This DefaultStyleKey will only be used in design-time.
DefaultStyleKeyProperty.OverrideMetadata( typeof( GroupHeaderControl ), new FrameworkPropertyMetadata( new Markup.ThemeKey( typeof( Views.TableView ), typeof( GroupHeaderControl ) ) ) );
#region Static Fields
DataGridControl.ParentDataGridControlPropertyKey.OverrideMetadata( typeof( GroupHeaderControl ), new FrameworkPropertyMetadata( new PropertyChangedCallback( OnParentGridControlChanged ) ) );
internal static readonly string GroupPropertyName = PropertyHelper.GetPropertyName((GroupHeaderControl g) => g.Group);
KeyboardNavigation.TabNavigationProperty.OverrideMetadata(
typeof( GroupHeaderControl ), new FrameworkPropertyMetadata( KeyboardNavigationMode.None ) );
}
#endregion
public GroupHeaderControl()
{
this.CommandBindings.Add( new CommandBinding( DataGridCommands.ExpandGroup,
this.OnExpandExecuted,
this.OnExpandCanExecute ) );
static GroupHeaderControl()
{
// This DefaultStyleKey will only be used in design-time.
DefaultStyleKeyProperty.OverrideMetadata(typeof(GroupHeaderControl), new FrameworkPropertyMetadata(new Markup.ThemeKey(typeof(Views.TableView), typeof(GroupHeaderControl))));
this.CommandBindings.Add( new CommandBinding( DataGridCommands.CollapseGroup,
this.OnCollapseExecuted,
this.OnCollapseCanExecute ) );
DataGridControl.ParentDataGridControlPropertyKey.OverrideMetadata(typeof(GroupHeaderControl), new FrameworkPropertyMetadata(new PropertyChangedCallback(OnParentGridControlChanged)));
this.CommandBindings.Add( new CommandBinding( DataGridCommands.ToggleGroupExpansion,
this.OnToggleExecuted,
this.OnToggleCanExecute ) );
KeyboardNavigation.TabNavigationProperty.OverrideMetadata(
typeof(GroupHeaderControl), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));
}
m_itemContainerManager = new DataGridItemContainerManager( this );
}
public GroupHeaderControl()
{
this.CommandBindings.Add(new CommandBinding(DataGridCommands.ExpandGroup,
this.OnExpandExecuted,
this.OnExpandCanExecute));
#region Group Internal Attached Property
this.CommandBindings.Add(new CommandBinding(DataGridCommands.CollapseGroup,
this.OnCollapseExecuted,
this.OnCollapseCanExecute));
internal static readonly DependencyProperty GroupProperty = DependencyProperty.RegisterAttached(
"Group", typeof( Group ), typeof( GroupHeaderControl ),
new FrameworkPropertyMetadata( null, FrameworkPropertyMetadataOptions.Inherits ) );
this.CommandBindings.Add(new CommandBinding(DataGridCommands.ToggleGroupExpansion,
this.OnToggleExecuted,
this.OnToggleCanExecute));
internal static Group GetGroup( DependencyObject obj )
{
return ( Group )obj.GetValue( GroupHeaderControl.GroupProperty );
}
m_itemContainerManager = new DataGridItemContainerManager(this);
}
internal static void SetGroup( DependencyObject obj, Group value )
{
obj.SetValue( GroupHeaderControl.GroupProperty, value );
}
#region Group Internal Attached Property
#endregion
internal static readonly DependencyProperty GroupProperty = DependencyProperty.RegisterAttached(
"Group", typeof(Group), typeof(GroupHeaderControl),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits));
#region Group Property
internal static Group GetGroup(DependencyObject obj)
{
return (Group)obj.GetValue(GroupHeaderControl.GroupProperty);
}
public Group Group
{
get
{
return m_group;
}
}
internal static void SetGroup(DependencyObject obj, Group value)
{
obj.SetValue(GroupHeaderControl.GroupProperty, value);
}
internal void SetGroup( Group group )
{
m_group = group;
this.Content = m_group;
GroupHeaderControl.SetGroup( this, group );
#endregion
this.RaisePropertyChanged( GroupHeaderControl.GroupPropertyName );
}
#region Group Property
private Group m_group;
public Group Group
{
get
{
return m_group;
}
}
#endregion
internal void SetGroup(Group group)
{
m_group = group;
this.Content = m_group;
GroupHeaderControl.SetGroup(this, group);
#region SelectionBackground Property
this.RaisePropertyChanged(GroupHeaderControl.GroupPropertyName);
}
public static readonly DependencyProperty SelectionBackgroundProperty = Cell.SelectionBackgroundProperty.AddOwner( typeof( GroupHeaderControl ) );
private Group m_group;
public Brush SelectionBackground
{
get
{
return ( Brush )this.GetValue( GroupHeaderControl.SelectionBackgroundProperty );
}
set
{
this.SetValue( GroupHeaderControl.SelectionBackgroundProperty, value );
}
}
#endregion
#endregion SelectionBackground Property
#region SelectionBackground Property
#region SelectionForeground Property
public static readonly DependencyProperty SelectionBackgroundProperty = Cell.SelectionBackgroundProperty.AddOwner(typeof(GroupHeaderControl));
public static readonly DependencyProperty SelectionForegroundProperty = Cell.SelectionForegroundProperty.AddOwner( typeof( GroupHeaderControl ) );
public Brush SelectionBackground
{
get
{
return (Brush)this.GetValue(GroupHeaderControl.SelectionBackgroundProperty);
}
set
{
this.SetValue(GroupHeaderControl.SelectionBackgroundProperty, value);
}
}
public Brush SelectionForeground
{
get
{
return ( Brush )this.GetValue( GroupHeaderControl.SelectionForegroundProperty );
}
set
{
this.SetValue( GroupHeaderControl.SelectionForegroundProperty, value );
}
}
#endregion SelectionBackground Property
#endregion SelectionForeground Property
#region SelectionForeground Property
#region InactiveSelectionBackground Property
public static readonly DependencyProperty SelectionForegroundProperty = Cell.SelectionForegroundProperty.AddOwner(typeof(GroupHeaderControl));
public static readonly DependencyProperty InactiveSelectionBackgroundProperty = Cell.InactiveSelectionBackgroundProperty.AddOwner( typeof( GroupHeaderControl ) );
public Brush SelectionForeground
{
get
{
return (Brush)this.GetValue(GroupHeaderControl.SelectionForegroundProperty);
}
set
{
this.SetValue(GroupHeaderControl.SelectionForegroundProperty, value);
}
}
public Brush InactiveSelectionBackground
{
get
{
return ( Brush )this.GetValue( GroupHeaderControl.InactiveSelectionBackgroundProperty );
}
set
{
this.SetValue( GroupHeaderControl.InactiveSelectionBackgroundProperty, value );
}
}
#endregion SelectionForeground Property
#endregion InactiveSelectionBackground Property
#region InactiveSelectionBackground Property
#region InactiveSelectionForeground Property
public static readonly DependencyProperty InactiveSelectionBackgroundProperty = Cell.InactiveSelectionBackgroundProperty.AddOwner(typeof(GroupHeaderControl));
public static readonly DependencyProperty InactiveSelectionForegroundProperty = Cell.InactiveSelectionForegroundProperty.AddOwner( typeof( GroupHeaderControl ) );
public Brush InactiveSelectionBackground
{
get
{
return (Brush)this.GetValue(GroupHeaderControl.InactiveSelectionBackgroundProperty);
}
set
{
this.SetValue(GroupHeaderControl.InactiveSelectionBackgroundProperty, value);
}
}
public Brush InactiveSelectionForeground
{
get
{
return ( Brush )this.GetValue( GroupHeaderControl.InactiveSelectionForegroundProperty );
}
set
{
this.SetValue( GroupHeaderControl.InactiveSelectionForegroundProperty, value );
}
}
#endregion InactiveSelectionBackground Property
#endregion InactiveSelectionForeground Property
#region InactiveSelectionForeground Property
#region CanBeRecycled Protected Property
public static readonly DependencyProperty InactiveSelectionForegroundProperty = Cell.InactiveSelectionForegroundProperty.AddOwner(typeof(GroupHeaderControl));
protected virtual bool CanBeRecycled
{
get
{
if( this.IsKeyboardFocused || this.IsKeyboardFocusWithin )
return false;
public Brush InactiveSelectionForeground
{
get
{
return (Brush)this.GetValue(GroupHeaderControl.InactiveSelectionForegroundProperty);
}
set
{
this.SetValue(GroupHeaderControl.InactiveSelectionForegroundProperty, value);
}
}
return m_itemContainerManager.CanBeRecycled;
}
}
#endregion InactiveSelectionForeground Property
#endregion
#region CanBeRecycled Protected Property
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
protected virtual bool CanBeRecycled
{
get
{
if (this.IsKeyboardFocused || this.IsKeyboardFocusWithin)
return false;
m_itemContainerManager.Update();
}
return m_itemContainerManager.CanBeRecycled;
}
}
#endregion
protected override void OnPreviewMouseLeftButtonUp( MouseButtonEventArgs e )
{
base.OnPreviewMouseLeftButtonUp( e );
return;
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
protected override void OnIsKeyboardFocusWithinChanged( DependencyPropertyChangedEventArgs e )
{
base.OnIsKeyboardFocusWithinChanged( e );
m_itemContainerManager.Update();
}
bool newValue = ( bool )e.NewValue;
if( newValue == true )
{
DataGridContext dataGridContext = DataGridControl.GetDataGridContext( this );
protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnPreviewMouseLeftButtonUp(e);
return;
}
if( dataGridContext != null )
protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
{
object item = dataGridContext.GetItemFromContainer( this );
base.OnIsKeyboardFocusWithinChanged(e);
if( ( item != null ) && ( dataGridContext.InternalCurrentItem != item ) )
{
try
bool newValue = (bool)e.NewValue;
if (newValue == true)
{
dataGridContext.SetCurrent( item, null, -1, dataGridContext.CurrentColumn, true, true, false, AutoScrollCurrentItemSourceTriggers.FocusChanged );
DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);
if (dataGridContext != null)
{
object item = dataGridContext.GetItemFromContainer(this);
if ((item != null) && (dataGridContext.InternalCurrentItem != item))
{
try
{
dataGridContext.SetCurrent(item, null, -1, dataGridContext.CurrentColumn, true, true, false, AutoScrollCurrentItemSourceTriggers.FocusChanged);
}
catch (DataGridException)
{
// We swallow the exception if it occurs because of a validation error or Cell was read-only or
// any other GridException.
}
}
}
}
catch( DataGridException )
}
protected virtual void PrepareContainer(DataGridContext dataGridContext, object item)
{
m_isRecyclingCandidate = false;
if (m_isContainerPrepared)
Debug.Fail("A GroupHeaderControl can't be prepared twice, it must be cleaned before PrepareContainer is called again");
Group group = null;
DataGridContext gridContext = DataGridControl.GetDataGridContext(this);
if (gridContext != null)
{
// We swallow the exception if it occurs because of a validation error or Cell was read-only or
// any other GridException.
object dataItem = gridContext.GetItemFromContainer(this);
if (dataItem != null)
{
group = gridContext.GetGroupFromItem(dataItem);
}
}
}
}
}
}
protected virtual void PrepareContainer( DataGridContext dataGridContext, object item )
{
m_isRecyclingCandidate = false;
this.SetGroup(group);
if( m_isContainerPrepared )
Debug.Fail( "A GroupHeaderControl can't be prepared twice, it must be cleaned before PrepareContainer is called again" );
m_itemContainerManager.Prepare(gridContext, item);
Group group = null;
DataGridContext gridContext = DataGridControl.GetDataGridContext( this );
m_isContainerPrepared = true;
}
if( gridContext != null )
{
object dataItem = gridContext.GetItemFromContainer( this );
if( dataItem != null )
protected virtual void ClearContainer()
{
group = gridContext.GetGroupFromItem( dataItem );
m_itemContainerManager.Clear(m_isRecyclingCandidate);
m_isContainerPrepared = false;
}
}
this.SetGroup( group );
m_itemContainerManager.Prepare( gridContext, item );
m_isContainerPrepared = true;
}
protected internal virtual void PrepareDefaultStyleKey(Xceed.Wpf.DataGrid.Views.ViewBase view)
{
this.DefaultStyleKey = view.GetDefaultStyleKey(typeof(GroupHeaderControl));
}
protected virtual void ClearContainer()
{
m_itemContainerManager.Clear( m_isRecyclingCandidate );
m_isContainerPrepared = false;
}
protected internal virtual bool ShouldHandleSelectionEvent(InputEventArgs eventArgs)
{
var targetChild = eventArgs.OriginalSource as DependencyObject;
protected internal virtual void PrepareDefaultStyleKey( Xceed.Wpf.DataGrid.Views.ViewBase view )
{
this.DefaultStyleKey = view.GetDefaultStyleKey( typeof( GroupHeaderControl ) );
}
// If the event is comming from a specific control inside the header (GroupNavigationControl or Collapsed button),
// ignore the event since it is not for selection purposes that the user targeted this control.
var collapsedButtonParent = TreeHelper.FindParent<ToggleButton>(targetChild, true, null, this);
if (collapsedButtonParent != null)
return false;
protected internal virtual bool ShouldHandleSelectionEvent( InputEventArgs eventArgs )
{
var targetChild = eventArgs.OriginalSource as DependencyObject;
var groupNavigationControlParent = TreeHelper.FindParent<GroupNavigationControl>(targetChild, true, null, this);
if (groupNavigationControlParent != null)
return false;
// If the event is comming from a specific control inside the header (GroupNavigationControl or Collapsed button),
// ignore the event since it is not for selection purposes that the user targeted this control.
var collapsedButtonParent = TreeHelper.FindParent<ToggleButton>( targetChild, true, null, this );
if( collapsedButtonParent != null )
return false;
return true;
}
var groupNavigationControlParent = TreeHelper.FindParent<GroupNavigationControl>( targetChild, true, null, this );
if( groupNavigationControlParent != null )
return false;
private static void OnParentGridControlChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
DataGridControl grid = e.NewValue as DataGridControl;
GroupHeaderControl groupHeaderControl = sender as GroupHeaderControl;
return true;
}
if ((groupHeaderControl != null) && (grid != null))
{
groupHeaderControl.PrepareDefaultStyleKey(grid.GetView());
}
}
private static void OnParentGridControlChanged( DependencyObject sender, DependencyPropertyChangedEventArgs e )
{
DataGridControl grid = e.NewValue as DataGridControl;
GroupHeaderControl groupHeaderControl = sender as GroupHeaderControl;
private void OnExpandCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = false;
if( ( groupHeaderControl != null ) && ( grid != null ) )
{
groupHeaderControl.PrepareDefaultStyleKey( grid.GetView() );
}
}
if (e.Parameter == null)
{
//can execute the Expand command if the group is NOT expanded.
e.CanExecute = !this.FindGroupCommandTarget(e.OriginalSource).IsExpanded;
}
}
private void OnExpandCanExecute( object sender, CanExecuteRoutedEventArgs e )
{
e.CanExecute = false;
private void OnExpandExecuted(object sender, ExecutedRoutedEventArgs e)
{
this.FindGroupCommandTarget(e.OriginalSource).IsExpanded = true;
}
if( e.Parameter == null )
{
//can execute the Expand command if the group is NOT expanded.
e.CanExecute = !this.FindGroupCommandTarget( e.OriginalSource ).IsExpanded;
}
}
private void OnCollapseCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = false;
private void OnExpandExecuted( object sender, ExecutedRoutedEventArgs e )
{
this.FindGroupCommandTarget( e.OriginalSource ).IsExpanded = true;
}
if (e.Parameter == null)
{
//can execute the Collapse command if the group is expanded.
e.CanExecute = this.FindGroupCommandTarget(e.OriginalSource).IsExpanded;
}
}
private void OnCollapseCanExecute( object sender, CanExecuteRoutedEventArgs e )
{
e.CanExecute = false;
private void OnCollapseExecuted(object sender, ExecutedRoutedEventArgs e)
{
this.FindGroupCommandTarget(e.OriginalSource).IsExpanded = false;
}
if( e.Parameter == null )
{
//can execute the Collapse command if the group is expanded.
e.CanExecute = this.FindGroupCommandTarget( e.OriginalSource ).IsExpanded;
}
}
private void OnToggleCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = false;
private void OnCollapseExecuted( object sender, ExecutedRoutedEventArgs e )
{
this.FindGroupCommandTarget( e.OriginalSource ).IsExpanded = false;
}
if (e.Parameter == null)
{
e.CanExecute = true; //can always toggle
}
}
private void OnToggleCanExecute( object sender, CanExecuteRoutedEventArgs e )
{
e.CanExecute = false;
private void OnToggleExecuted(object sender, ExecutedRoutedEventArgs e)
{
Group group = FindGroupCommandTarget(e.OriginalSource);
if( e.Parameter == null )
{
e.CanExecute = true; //can always toggle
}
}
group.IsExpanded = !group.IsExpanded;
}
private void OnToggleExecuted( object sender, ExecutedRoutedEventArgs e )
{
Group group = FindGroupCommandTarget( e.OriginalSource );
// We use an ItemsControl inside the GroupHeaderControl to represent the
// ancestors (ParentGroups) of this.Group, and each item in this ItemsControl
// is a Group templated to look like a single, stand-alone GroupHeaderControl.
//
// In the ItemTemplate for each Group in the ItemsControl, we have a Border that
// declares some InputBindings to the group commands. In this case, we want to
// execute the command on this specific instance of Group, which is the DataContext
// of the Border.
private Group FindGroupCommandTarget(object originalSource)
{
object dataContext = null;
group.IsExpanded = !group.IsExpanded;
}
FrameworkElement fe = originalSource as FrameworkElement;
if (fe != null)
{
dataContext = fe.DataContext;
}
else
{
FrameworkContentElement fce = originalSource as FrameworkContentElement;
if (fce != null)
{
dataContext = fce.DataContext;
}
}
// We use an ItemsControl inside the GroupHeaderControl to represent the
// ancestors (ParentGroups) of this.Group, and each item in this ItemsControl
// is a Group templated to look like a single, stand-alone GroupHeaderControl.
//
// In the ItemTemplate for each Group in the ItemsControl, we have a Border that
// declares some InputBindings to the group commands. In this case, we want to
// execute the command on this specific instance of Group, which is the DataContext
// of the Border.
private Group FindGroupCommandTarget( object originalSource )
{
object dataContext = null;
Group groupCommandTarget = dataContext as Group;
FrameworkElement fe = originalSource as FrameworkElement;
if( fe != null )
{
dataContext = fe.DataContext;
}
else
{
FrameworkContentElement fce = originalSource as FrameworkContentElement;
if( fce != null )
{
dataContext = fce.DataContext;
return (groupCommandTarget != null) ? groupCommandTarget : this.Group;
}
}
Group groupCommandTarget = dataContext as Group;
#region INotifyPropertyChanged Members
return ( groupCommandTarget != null ) ? groupCommandTarget : this.Group;
}
public event PropertyChangedEventHandler PropertyChanged;
#region INotifyPropertyChanged Members
private void RaisePropertyChanged(string propertyName)
{
var handler = this.PropertyChanged;
if (handler == null)
return;
public event PropertyChangedEventHandler PropertyChanged;
handler.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void RaisePropertyChanged( string propertyName )
{
var handler = this.PropertyChanged;
if( handler == null )
return;
#endregion
handler.Invoke( this, new PropertyChangedEventArgs( propertyName ) );
}
#region IDataGridItemContainer Members
#endregion
bool IDataGridItemContainer.CanBeRecycled
{
get
{
return this.CanBeRecycled;
}
}
#region IDataGridItemContainer Members
bool IDataGridItemContainer.IsRecyclingCandidate
{
get
{
return m_isRecyclingCandidate;
}
set
{
m_isRecyclingCandidate = value;
}
}
bool IDataGridItemContainer.CanBeRecycled
{
get
{
return this.CanBeRecycled;
}
}
void IDataGridItemContainer.PrepareContainer(DataGridContext dataGridContext, object item)
{
this.PrepareContainer(dataGridContext, item);
}
bool IDataGridItemContainer.IsRecyclingCandidate
{
get
{
return m_isRecyclingCandidate;
}
set
{
m_isRecyclingCandidate = value;
}
}
void IDataGridItemContainer.ClearContainer()
{
this.ClearContainer();
}
void IDataGridItemContainer.PrepareContainer( DataGridContext dataGridContext, object item )
{
this.PrepareContainer( dataGridContext, item );
}
void IDataGridItemContainer.CleanRecyclingCandidate()
{
m_itemContainerManager.CleanRecyclingCandidates();
}
void IDataGridItemContainer.ClearContainer()
{
this.ClearContainer();
}
#endregion
void IDataGridItemContainer.CleanRecyclingCandidate()
{
m_itemContainerManager.CleanRecyclingCandidates();
private readonly DataGridItemContainerManager m_itemContainerManager;
private bool m_isContainerPrepared;
private bool m_isRecyclingCandidate;
}
#endregion
private readonly DataGridItemContainerManager m_itemContainerManager;
private bool m_isContainerPrepared;
private bool m_isRecyclingCandidate;
}
}

4319
ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/ItemsSourceHelper.cs

File diff suppressed because it is too large

78
ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/Properties/AssemblyInfo.cs

@ -1,78 +0,0 @@
/*************************************************************************************
Extended WPF Toolkit
Copyright (C) 2007-2013 Xceed Software Inc.
This program is provided to you under the terms of the Microsoft Public
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
For more features, controls, and fast professional support,
pick up the Plus Edition at http://xceed.com/wpf_toolkit
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
***********************************************************************************/
#region Using directives
using System;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Windows;
using System.Windows.Markup;
#endregion
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle( "Xceed Toolkit for WPF - DataGrid" )]
[assembly: AssemblyDescription( "This assembly implements the Xceed.Wpf.DataGrid namespace, a data grid control for the Windows Presentation Framework." )]
[assembly: AssemblyCompany( "Xceed Software Inc." )]
[assembly: AssemblyProduct( "Xceed Toolkit for WPF - DataGrid" )]
[assembly: AssemblyCopyright( "Copyright (C) Xceed Software Inc. 2007-2017" )]
[assembly: CLSCompliant( true )]
[assembly: ComVisible( false )]
[assembly: XmlnsPrefix( "http://schemas.xceed.com/wpf/xaml/datagrid", "xcdg" )]
[assembly: XmlnsDefinition( "http://schemas.xceed.com/wpf/xaml/datagrid", "Xceed.Wpf.DataGrid")]
[assembly: XmlnsDefinition( "http://schemas.xceed.com/wpf/xaml/datagrid", "Xceed.Wpf.DataGrid.Converters")]
[assembly: XmlnsDefinition( "http://schemas.xceed.com/wpf/xaml/datagrid", "Xceed.Wpf.DataGrid.Markup")]
[assembly: XmlnsDefinition( "http://schemas.xceed.com/wpf/xaml/datagrid", "Xceed.Wpf.DataGrid.Views")]
[assembly: XmlnsDefinition( "http://schemas.xceed.com/wpf/xaml/datagrid", "Xceed.Wpf.DataGrid.ValidationRules")]
[assembly: SecurityRules( SecurityRuleSet.Level1 )]
[assembly: AllowPartiallyTrustedCallers]
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.SourceAssembly, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
#pragma warning disable 1699
[assembly: AssemblyDelaySign( false )]
[assembly: AssemblyKeyFile( @"..\..\sn.snk" )]
[assembly: AssemblyKeyName( "" )]
#pragma warning restore 1699

1142
ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/Utils/Wpf/DragDrop/DragSourceManagerBase.cs

File diff suppressed because it is too large

1182
ExtendedWPFToolkitSolution/Src/Xceed.Wpf.DataGrid/Xceed.Wpf.DataGrid.csproj

File diff suppressed because it is too large

2
ExtendedWPFToolkitSolution/Xceed.Wpf.Toolkit.sln

@ -5,7 +5,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xceed.Wpf.Toolkit.LiveExplo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xceed.Wpf.Toolkit", "Src\Xceed.Wpf.Toolkit\Xceed.Wpf.Toolkit.csproj", "{72E591D6-8F83-4D8C-8F67-9C325E623234}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xceed.Wpf.DataGrid", "Src\Xceed.Wpf.DataGrid\Xceed.Wpf.DataGrid.csproj", "{63648392-6CE9-4A60-96D4-F9FD718D29B0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xceed.Wpf.DataGrid", "Src\Xceed.Wpf.DataGrid\Xceed.Wpf.DataGrid.csproj", "{63648392-6CE9-4A60-96D4-F9FD718D29B0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xceed.Wpf.AvalonDock", "Src\Xceed.Wpf.AvalonDock\Xceed.Wpf.AvalonDock.csproj", "{DB81988F-E0F2-45A0-A1FD-8C37F3D35244}"
EndProject

Loading…
Cancel
Save