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;
using System.Collections; using System.Collections;
using System.ComponentModel; using System.ComponentModel;
using System.Data.Objects.DataClasses; using System.Data.Entity.Core.Objects.DataClasses;
using System.Reflection; using System.Reflection;
namespace Xceed.Wpf.DataGrid namespace Xceed.Wpf.DataGrid
{ {
internal class EntityDetailDescription : DataGridDetailDescription internal class EntityDetailDescription : DataGridDetailDescription
{
public EntityDetailDescription()
{ {
} public EntityDetailDescription()
{
public EntityDetailDescription( string propertyName ) }
: this()
{
if( string.IsNullOrEmpty( propertyName ) )
throw new ArgumentException( "The specified property name is null or empty", "propertyName" );
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 ) public event EventHandler<QueryEntityDetailsEventArgs> QueryDetails;
{
var handler = this.QueryDetails;
if( handler == null )
return;
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 ) #endregion
{
EntityObject entityObject = parentItem as EntityObject;
if( entityObject == null ) protected internal override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
return null; {
EntityObject entityObject = parentItem as EntityObject;
// Even if EntityObject is not in a loadable state, we must still return the IList if (entityObject == null)
// so that the ItemProperties can be extracted based on the elements type. return null;
bool entityObjectLoadable = ItemsSourceHelper.IsEntityObjectLoadable( entityObject );
// We let the user take charge of handling the details. // Even if EntityObject is not in a loadable state, we must still return the IList
QueryEntityDetailsEventArgs args = new QueryEntityDetailsEventArgs( entityObject ); // so that the ItemProperties can be extracted based on the elements type.
bool entityObjectLoadable = ItemsSourceHelper.IsEntityObjectLoadable(entityObject);
if( entityObjectLoadable ) // We let the user take charge of handling the details.
this.OnQueryDetails( args ); QueryEntityDetailsEventArgs args = new QueryEntityDetailsEventArgs(entityObject);
// The parentItem must implement IEntityWithRelationships if (entityObjectLoadable)
Type parentItemType = parentItem.GetType(); this.OnQueryDetails(args);
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( propertyInfo != null ) // The parentItem must implement IEntityWithRelationships
{ Type parentItemType = parentItem.GetType();
RelatedEnd relatedEnd = propertyInfo.GetValue( parentItem, null ) as RelatedEnd; if (typeof(IEntityWithRelationships).IsAssignableFrom(parentItemType))
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(); // 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; return null;
// Returns an IList to have proper change notification events.
if( listSource != null )
return listSource.GetList();
}
} }
}
return null;
} }
}
} }

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

@ -15,47 +15,43 @@
***********************************************************************************/ ***********************************************************************************/
using System; using System;
using System.Collections.Generic; using System.Data.Entity.Core.Objects.DataClasses;
using System.Linq;
using System.Text;
using System.Windows;
using System.Data.Objects.DataClasses;
namespace Xceed.Wpf.DataGrid namespace Xceed.Wpf.DataGrid
{ {
public class QueryEntityDetailsEventArgs : EventArgs public class QueryEntityDetailsEventArgs : EventArgs
{
#region CONSTRUCTORS
internal QueryEntityDetailsEventArgs( EntityObject parentItem )
: base()
{ {
if( parentItem == null ) #region CONSTRUCTORS
throw new ArgumentNullException( "parentItem" );
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 #region ParentItem Property
{
get;
private set;
}
#endregion ParentItem Property public EntityObject ParentItem
{
get;
private set;
}
#region Handled Property #endregion ParentItem Property
public bool Handled #region Handled Property
{
get;
set;
}
#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 internal static class _XceedVersionInfo
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const string BaseVersion = "3.4"; public const string BaseVersion = "3.4";
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const string Version = BaseVersion + ".0.0"; public const string Version = BaseVersion + ".0.0";
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const string PublicKeyToken = "ba83ff368b7563c6"; public const string PublicKeyToken = "ba83ff368b7563c6";
public const string FrameworkVersion = "4.0.0.0"; public const string FrameworkVersion = "4.0.0.0";
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const string DesignFullName = public const string DesignFullName =
"Xceed.Wpf.DataGrid,Version=" + "Xceed.Wpf.DataGrid,Version=" +
Version + Version +
",Culture=neutral,PublicKeyToken=" + PublicKeyToken; ",Culture=neutral,PublicKeyToken=" + PublicKeyToken;
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields" )] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const string CurrentAssemblyPackUri = public const string CurrentAssemblyPackUri =
"pack://application:,,,/Xceed.Wpf.DataGrid,Version=" + Version; "pack://application:,,,/Xceed.Wpf.DataGrid,Version=" + Version;
} }

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

@ -15,96 +15,92 @@
***********************************************************************************/ ***********************************************************************************/
using System; using System;
using System.Collections.Generic; using System.ComponentModel;
using System.Text; using System.Windows;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows;
using System.ComponentModel;
namespace Xceed.Wpf.DataGrid.Converters namespace Xceed.Wpf.DataGrid.Converters
{ {
[EditorBrowsable( EditorBrowsableState.Never )] [EditorBrowsable(EditorBrowsableState.Never)]
[ValueConversion( typeof( object ), typeof( ImageSource ) )] [ValueConversion(typeof(object), typeof(ImageSource))]
public class ImageConverter : IValueConverter 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 )
{ {
if( !targetType.IsAssignableFrom( typeof( ImageSource ) ) ) #region IValueConverter Members
return DependencyProperty.UnsetValue;
[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 ) ) if ((value == null) || (value is ImageSource))
return value; 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 ) //if (image != null)
{ //{
imageSource = ImageConverter.ConvertFromWinFormsImage( image ); // imageSource = ImageConverter.ConvertFromWinFormsImage(image);
} //}
else //else
{ //{
byte[] byteArray = value as byte[]; byte[] byteArray = value as byte[];
if( byteArray != null ) if (byteArray != null)
{ {
imageSource = ImageConverter.ConvertFromByteArray( byteArray ); 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 ) #endregion
{
return Binding.DoNothing;
}
#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 ) // try
{ // {
ImageSource imageSource = null; // System.Drawing.ImageConverter imageConverter = new System.Drawing.ImageConverter();
try // byte[] imageBytes = (byte[])imageConverter.ConvertTo(image, typeof(byte[]));
{
System.Drawing.ImageConverter imageConverter = new System.Drawing.ImageConverter();
byte[] imageBytes = ( byte[] )imageConverter.ConvertTo( image, typeof( byte[] ) ); // if (imageBytes != null)
// imageSource = ImageConverter.ConvertFromByteArray(imageBytes);
// }
// catch { }
if( imageBytes != null ) // return imageSource;
imageSource = ImageConverter.ConvertFromByteArray( imageBytes ); //}
}
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;
}
private static ImageSource ConvertFromByteArray( byte[] imageBytes ) #endregion PRIVATE METHODS
{
ImageSource imageSource = null;
try
{
ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
imageSource = imageSourceConverter.ConvertFrom( imageBytes ) as ImageSource;
}
catch
{
}
return imageSource;
} }
#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 namespace Xceed.Wpf.DataGrid
{ {
internal sealed class GenericContentTemplateSelector : DataTemplateSelector internal sealed class GenericContentTemplateSelector : DataTemplateSelector
{ {
#region Static Fields #region Static Fields
internal static readonly DataTemplate ForeignKeyCellContentTemplate; internal static readonly DataTemplate ForeignKeyCellContentTemplate;
internal static readonly DataTemplate ForeignKeyGroupValueTemplate; internal static readonly DataTemplate ForeignKeyGroupValueTemplate;
internal static readonly DataTemplate ForeignKeyScrollTipContentTemplate; internal static readonly DataTemplate ForeignKeyScrollTipContentTemplate;
private static readonly DataTemplate BoolTemplate; private static readonly DataTemplate BoolTemplate;
private static readonly DataTemplate CommonTemplate; private static readonly DataTemplate CommonTemplate;
private static readonly DataTemplate ImageTemplate; 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() static GenericContentTemplateSelector()
{ {
// We need to initalize the ResourceDictionary before accessing since we access // 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 // it in a static constructor and will be called before the Layout was performed
GenericContentTemplateSelector.GenericContentTemplateResources.InitializeComponent(); GenericContentTemplateSelector.GenericContentTemplateResources.InitializeComponent();
GenericContentTemplateSelector.BoolTemplate = GenericContentTemplateSelector.GenericContentTemplateResources[ "booleanDefaultContentTemplate" ] as DataTemplate; GenericContentTemplateSelector.BoolTemplate = GenericContentTemplateSelector.GenericContentTemplateResources["booleanDefaultContentTemplate"] as DataTemplate;
Debug.Assert( GenericContentTemplateSelector.BoolTemplate != null ); Debug.Assert(GenericContentTemplateSelector.BoolTemplate != null);
GenericContentTemplateSelector.BoolTemplate.Seal(); GenericContentTemplateSelector.BoolTemplate.Seal();
GenericContentTemplateSelector.CommonTemplate = GenericContentTemplateSelector.GenericContentTemplateResources[ "commonDefaultContentTemplate" ] as DataTemplate; GenericContentTemplateSelector.CommonTemplate = GenericContentTemplateSelector.GenericContentTemplateResources["commonDefaultContentTemplate"] as DataTemplate;
Debug.Assert( GenericContentTemplateSelector.CommonTemplate != null ); Debug.Assert(GenericContentTemplateSelector.CommonTemplate != null);
GenericContentTemplateSelector.CommonTemplate.Seal(); GenericContentTemplateSelector.CommonTemplate.Seal();
GenericContentTemplateSelector.ImageTemplate = GenericContentTemplateSelector.GenericContentTemplateResources[ "imageDefaultContentTemplate" ] as DataTemplate; GenericContentTemplateSelector.ImageTemplate = GenericContentTemplateSelector.GenericContentTemplateResources["imageDefaultContentTemplate"] as DataTemplate;
Debug.Assert( GenericContentTemplateSelector.ImageTemplate != null ); Debug.Assert(GenericContentTemplateSelector.ImageTemplate != null);
GenericContentTemplateSelector.ImageTemplate.Seal(); GenericContentTemplateSelector.ImageTemplate.Seal();
GenericContentTemplateSelector.ForeignKeyCellContentTemplate = GenericContentTemplateSelector.GenericContentTemplateResources[ "foreignKeyDefaultContentTemplate" ] as DataTemplate; GenericContentTemplateSelector.ForeignKeyCellContentTemplate = GenericContentTemplateSelector.GenericContentTemplateResources["foreignKeyDefaultContentTemplate"] as DataTemplate;
Debug.Assert( GenericContentTemplateSelector.ForeignKeyCellContentTemplate != null ); Debug.Assert(GenericContentTemplateSelector.ForeignKeyCellContentTemplate != null);
GenericContentTemplateSelector.ForeignKeyCellContentTemplate.Seal(); GenericContentTemplateSelector.ForeignKeyCellContentTemplate.Seal();
GenericContentTemplateSelector.ForeignKeyGroupValueTemplate = GenericContentTemplateSelector.GenericContentTemplateResources[ "foreignKeyGroupValueDefaultContentTemplate" ] as DataTemplate; GenericContentTemplateSelector.ForeignKeyGroupValueTemplate = GenericContentTemplateSelector.GenericContentTemplateResources["foreignKeyGroupValueDefaultContentTemplate"] as DataTemplate;
Debug.Assert( GenericContentTemplateSelector.ForeignKeyGroupValueTemplate != null ); Debug.Assert(GenericContentTemplateSelector.ForeignKeyGroupValueTemplate != null);
GenericContentTemplateSelector.ForeignKeyGroupValueTemplate.Seal(); GenericContentTemplateSelector.ForeignKeyGroupValueTemplate.Seal();
GenericContentTemplateSelector.ForeignKeyScrollTipContentTemplate = GenericContentTemplateSelector.GenericContentTemplateResources[ "foreignKeyScrollTipDefaultContentTemplate" ] as DataTemplate; GenericContentTemplateSelector.ForeignKeyScrollTipContentTemplate = GenericContentTemplateSelector.GenericContentTemplateResources["foreignKeyScrollTipDefaultContentTemplate"] as DataTemplate;
Debug.Assert( GenericContentTemplateSelector.ForeignKeyScrollTipContentTemplate != null ); Debug.Assert(GenericContentTemplateSelector.ForeignKeyScrollTipContentTemplate != null);
GenericContentTemplateSelector.ForeignKeyScrollTipContentTemplate.Seal(); GenericContentTemplateSelector.ForeignKeyScrollTipContentTemplate.Seal();
} }
private GenericContentTemplateSelector() private GenericContentTemplateSelector()
{ {
} }
#endregion #endregion
#region Instance Static Property #region Instance Static Property
public static GenericContentTemplateSelector Instance public static GenericContentTemplateSelector Instance
{ {
get get
{ {
return m_instance; 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 ) public override DataTemplate SelectTemplate(object item, DependencyObject container)
{ {
if( item == null ) if (item == null)
return base.SelectTemplate( item, container ); return base.SelectTemplate(item, container);
DataTemplate template = null; DataTemplate template = null;
if( ( item is byte[] ) || ( item is System.Drawing.Image ) ) if ((item is byte[]) /*|| (item is System.Drawing.Image)*/)
{ {
bool useImageTemplate = false; 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 if (template == null)
{ {
var converter = new ImageConverter(); template = GenericContentTemplateSelector.GetCommonTemplate(item, container);
useImageTemplate = ( converter.Convert( item, typeof( ImageSource ), null, CultureInfo.CurrentCulture ) != null ); }
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 ); Debug.Assert(item != null);
}
}
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 );
}
private static DataTemplate GetImageTemplate( DependencyObject container ) var itemType = item.GetType();
{
return GenericContentTemplateSelector.ImageTemplate;
}
private static DataTemplate GetCommonTemplate( object item, DependencyObject container ) // Do not provide a template for data types that are already optimized by the framework or
{ // for data types that have a default template.
Debug.Assert( item != null ); 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 private static DataTemplate GetDefaultTemplate(Type type)
// for data types that have a default template. {
if( GenericContentTemplateSelector.IsTypeOptimized( itemType ) Debug.Assert(type != null);
|| GenericContentTemplateSelector.HasImplicitTemplate( item, itemType, container ) )
return 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 ) var templates = GenericContentTemplateSelector.DefaultTemplates;
{ lock (((ICollection)templates).SyncRoot)
Debug.Assert( type != null ); {
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 ); // We have found the desired template.
if( ( converter == null ) || ( !converter.CanConvertTo( typeof( string ) ) ) ) if (target.Key == type)
return GenericContentTemplateSelector.CommonTemplate; {
if (targetTemplate != null)
return targetTemplate;
var templates = GenericContentTemplateSelector.DefaultTemplates; // Unfortunately, the template has been garbage collected.
lock( ( ( ICollection )templates ).SyncRoot ) templates.RemoveAt(i);
{ break;
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;
}
}
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 ) private static DataTemplate CreateDefaultTemplate(Type type, TypeConverter converter)
{ {
Debug.Assert( type != null ); Debug.Assert(type != null);
Debug.Assert( converter != null ); Debug.Assert(converter != null);
var template = new DataTemplate(); var template = new DataTemplate();
var factory = new FrameworkElementFactory( typeof( TextBlock ) ); var factory = new FrameworkElementFactory(typeof(TextBlock));
var binding = new Binding(); var binding = new Binding();
binding.Mode = BindingMode.OneWay; binding.Mode = BindingMode.OneWay;
binding.Converter = new DefaultConverter( converter ); binding.Converter = new DefaultConverter(converter);
binding.ConverterCulture = CultureInfo.CurrentCulture; binding.ConverterCulture = CultureInfo.CurrentCulture;
factory.SetBinding( TextBlock.TextProperty, binding ); factory.SetBinding(TextBlock.TextProperty, binding);
template.VisualTree = factory; template.VisualTree = factory;
template.Seal(); template.Seal();
return template; return template;
} }
private static bool IsTypeOptimized( Type type ) private static bool IsTypeOptimized(Type type)
{ {
Debug.Assert( type != null ); Debug.Assert(type != null);
if( typeof( string ).IsAssignableFrom( type ) if (typeof(string).IsAssignableFrom(type)
|| typeof( UIElement ).IsAssignableFrom( type ) || typeof(UIElement).IsAssignableFrom(type)
|| typeof( XmlNode ).IsAssignableFrom( type ) ) || typeof(XmlNode).IsAssignableFrom(type))
return true; return true;
if( !typeof( Inline ).IsAssignableFrom( type ) ) if (!typeof(Inline).IsAssignableFrom(type))
{ {
var converter = TypeDescriptor.GetConverter( type ); var converter = TypeDescriptor.GetConverter(type);
if( ( converter != null ) && ( converter.CanConvertTo( typeof( UIElement ) ) ) ) if ((converter != null) && (converter.CanConvertTo(typeof(UIElement))))
return true; return true;
} }
return false; return false;
} }
private static bool HasImplicitTemplate( object item, Type type, DependencyObject container ) private static bool HasImplicitTemplate(object item, Type type, DependencyObject container)
{ {
Debug.Assert( type != null ); Debug.Assert(type != null);
var finder = GenericContentTemplateSelector.FindTemplateResource; var finder = GenericContentTemplateSelector.FindTemplateResource;
if( finder == null ) if (finder == null)
{ {
finder = GenericContentTemplateSelector.GetFindTemplateResourceInternal(); finder = GenericContentTemplateSelector.GetFindTemplateResourceInternal();
if( finder == null ) if (finder == null)
{ {
finder = GenericContentTemplateSelector.FindTemplateResourceFallback; 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() 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 )
{ {
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 ) private static object FindTemplateResourceFallback(DependencyObject container, object item, Type type)
{ {
var fe = container as FrameworkElement; var fe = container as FrameworkElement;
if( fe == null ) if (fe == null)
return 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 private sealed class DefaultConverter : IValueConverter
{ {
internal DefaultConverter( TypeConverter converter ) internal DefaultConverter(TypeConverter converter)
{ {
if( converter == null ) if (converter == null)
throw new ArgumentNullException( "converter" ); throw new ArgumentNullException("converter");
m_converter = converter; m_converter = converter;
} }
public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {
object result; object result;
if( DefaultConverter.TryConvertTo( value, targetType, culture, m_converter, out result ) ) if (DefaultConverter.TryConvertTo(value, targetType, culture, m_converter, out result))
return result; return result;
if( value != null ) if (value != null)
{ {
var valueType = value.GetType(); var valueType = value.GetType();
if( DefaultConverter.TryConvertTo( value, targetType, culture, TypeDescriptor.GetConverter( valueType ), out result ) ) if (DefaultConverter.TryConvertTo(value, targetType, culture, TypeDescriptor.GetConverter(valueType), out result))
return result; return result;
if( targetType.IsAssignableFrom( valueType ) ) if (targetType.IsAssignableFrom(valueType))
return value; return value;
} }
else if( DefaultConverter.IsNullableType( targetType ) ) else if (DefaultConverter.IsNullableType(targetType))
{ {
return value; return value;
} }
throw new ArgumentException( "Cannot convert to type " + targetType.FullName + ".", "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();
}
private static bool TryConvertTo( object value, Type targetType, CultureInfo culture, TypeConverter converter, out object result ) public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
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 ); throw new NotSupportedException();
result = converter.ConvertTo( null, culture, newValue, targetType );
return true;
} }
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; private static bool IsNullableType(Type type)
return false; {
} return (!type.IsValueType)
|| (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Nullable<>)));
}
private static bool IsNullableType( Type type ) private readonly TypeConverter m_converter;
{ }
return ( !type.IsValueType )
|| ( type.IsGenericType && ( type.GetGenericTypeDefinition() == typeof( Nullable<> ) ) );
}
private readonly TypeConverter m_converter; #endregion
} }
#endregion
}
} }

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

@ -16,426 +16,425 @@
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
using System.Windows; using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using Xceed.Utils.Wpf; using Xceed.Utils.Wpf;
using Xceed.Wpf.DataGrid.Utils; using Xceed.Wpf.DataGrid.Utils;
namespace Xceed.Wpf.DataGrid namespace Xceed.Wpf.DataGrid
{ {
public class GroupHeaderControl : ContentControl, INotifyPropertyChanged, IDataGridItemContainer public class GroupHeaderControl : ContentControl, INotifyPropertyChanged, IDataGridItemContainer
{
#region Static Fields
internal static readonly string GroupPropertyName = PropertyHelper.GetPropertyName( ( GroupHeaderControl g ) => g.Group );
#endregion
static GroupHeaderControl()
{ {
// This DefaultStyleKey will only be used in design-time. #region Static Fields
DefaultStyleKeyProperty.OverrideMetadata( typeof( GroupHeaderControl ), new FrameworkPropertyMetadata( new Markup.ThemeKey( typeof( Views.TableView ), typeof( GroupHeaderControl ) ) ) );
DataGridControl.ParentDataGridControlPropertyKey.OverrideMetadata( typeof( GroupHeaderControl ), new FrameworkPropertyMetadata( new PropertyChangedCallback( OnParentGridControlChanged ) ) ); internal static readonly string GroupPropertyName = PropertyHelper.GetPropertyName((GroupHeaderControl g) => g.Group);
KeyboardNavigation.TabNavigationProperty.OverrideMetadata( #endregion
typeof( GroupHeaderControl ), new FrameworkPropertyMetadata( KeyboardNavigationMode.None ) );
}
public GroupHeaderControl() static GroupHeaderControl()
{ {
this.CommandBindings.Add( new CommandBinding( DataGridCommands.ExpandGroup, // This DefaultStyleKey will only be used in design-time.
this.OnExpandExecuted, DefaultStyleKeyProperty.OverrideMetadata(typeof(GroupHeaderControl), new FrameworkPropertyMetadata(new Markup.ThemeKey(typeof(Views.TableView), typeof(GroupHeaderControl))));
this.OnExpandCanExecute ) );
this.CommandBindings.Add( new CommandBinding( DataGridCommands.CollapseGroup, DataGridControl.ParentDataGridControlPropertyKey.OverrideMetadata(typeof(GroupHeaderControl), new FrameworkPropertyMetadata(new PropertyChangedCallback(OnParentGridControlChanged)));
this.OnCollapseExecuted,
this.OnCollapseCanExecute ) );
this.CommandBindings.Add( new CommandBinding( DataGridCommands.ToggleGroupExpansion, KeyboardNavigation.TabNavigationProperty.OverrideMetadata(
this.OnToggleExecuted, typeof(GroupHeaderControl), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));
this.OnToggleCanExecute ) ); }
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( this.CommandBindings.Add(new CommandBinding(DataGridCommands.ToggleGroupExpansion,
"Group", typeof( Group ), typeof( GroupHeaderControl ), this.OnToggleExecuted,
new FrameworkPropertyMetadata( null, FrameworkPropertyMetadataOptions.Inherits ) ); this.OnToggleCanExecute));
internal static Group GetGroup( DependencyObject obj ) m_itemContainerManager = new DataGridItemContainerManager(this);
{ }
return ( Group )obj.GetValue( GroupHeaderControl.GroupProperty );
}
internal static void SetGroup( DependencyObject obj, Group value ) #region Group Internal Attached Property
{
obj.SetValue( GroupHeaderControl.GroupProperty, value );
}
#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 internal static void SetGroup(DependencyObject obj, Group value)
{ {
get obj.SetValue(GroupHeaderControl.GroupProperty, value);
{ }
return m_group;
}
}
internal void SetGroup( Group group ) #endregion
{
m_group = group;
this.Content = m_group;
GroupHeaderControl.SetGroup( this, group );
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 #endregion
{
get
{
return ( Brush )this.GetValue( GroupHeaderControl.SelectionBackgroundProperty );
}
set
{
this.SetValue( GroupHeaderControl.SelectionBackgroundProperty, value );
}
}
#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 #endregion SelectionBackground Property
{
get
{
return ( Brush )this.GetValue( GroupHeaderControl.SelectionForegroundProperty );
}
set
{
this.SetValue( GroupHeaderControl.SelectionForegroundProperty, value );
}
}
#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 #endregion SelectionForeground Property
{
get
{
return ( Brush )this.GetValue( GroupHeaderControl.InactiveSelectionBackgroundProperty );
}
set
{
this.SetValue( GroupHeaderControl.InactiveSelectionBackgroundProperty, value );
}
}
#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 #endregion InactiveSelectionBackground Property
{
get
{
return ( Brush )this.GetValue( GroupHeaderControl.InactiveSelectionForegroundProperty );
}
set
{
this.SetValue( GroupHeaderControl.InactiveSelectionForegroundProperty, value );
}
}
#endregion InactiveSelectionForeground Property #region InactiveSelectionForeground Property
#region CanBeRecycled Protected Property public static readonly DependencyProperty InactiveSelectionForegroundProperty = Cell.InactiveSelectionForegroundProperty.AddOwner(typeof(GroupHeaderControl));
protected virtual bool CanBeRecycled public Brush InactiveSelectionForeground
{ {
get get
{ {
if( this.IsKeyboardFocused || this.IsKeyboardFocusWithin ) return (Brush)this.GetValue(GroupHeaderControl.InactiveSelectionForegroundProperty);
return false; }
set
{
this.SetValue(GroupHeaderControl.InactiveSelectionForegroundProperty, value);
}
}
return m_itemContainerManager.CanBeRecycled; #endregion InactiveSelectionForeground Property
}
}
#endregion #region CanBeRecycled Protected Property
public override void OnApplyTemplate() protected virtual bool CanBeRecycled
{ {
base.OnApplyTemplate(); get
{
if (this.IsKeyboardFocused || this.IsKeyboardFocusWithin)
return false;
m_itemContainerManager.Update(); return m_itemContainerManager.CanBeRecycled;
} }
}
#endregion
protected override void OnPreviewMouseLeftButtonUp( MouseButtonEventArgs e ) public override void OnApplyTemplate()
{ {
base.OnPreviewMouseLeftButtonUp( e ); base.OnApplyTemplate();
return;
}
protected override void OnIsKeyboardFocusWithinChanged( DependencyPropertyChangedEventArgs e ) m_itemContainerManager.Update();
{ }
base.OnIsKeyboardFocusWithinChanged( e );
bool newValue = ( bool )e.NewValue;
if( newValue == true ) protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
{ {
DataGridContext dataGridContext = DataGridControl.GetDataGridContext( this ); 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 ) ) bool newValue = (bool)e.NewValue;
{
try 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 object dataItem = gridContext.GetItemFromContainer(this);
// any other GridException. if (dataItem != null)
{
group = gridContext.GetGroupFromItem(dataItem);
}
} }
}
}
}
}
protected virtual void PrepareContainer( DataGridContext dataGridContext, object item ) this.SetGroup(group);
{
m_isRecyclingCandidate = false;
if( m_isContainerPrepared ) m_itemContainerManager.Prepare(gridContext, item);
Debug.Fail( "A GroupHeaderControl can't be prepared twice, it must be cleaned before PrepareContainer is called again" );
Group group = null; m_isContainerPrepared = true;
DataGridContext gridContext = DataGridControl.GetDataGridContext( this ); }
if( gridContext != null ) protected virtual void ClearContainer()
{
object dataItem = gridContext.GetItemFromContainer( this );
if( dataItem != null )
{ {
group = gridContext.GetGroupFromItem( dataItem ); m_itemContainerManager.Clear(m_isRecyclingCandidate);
m_isContainerPrepared = false;
} }
}
this.SetGroup( group );
m_itemContainerManager.Prepare( gridContext, item ); protected internal virtual void PrepareDefaultStyleKey(Xceed.Wpf.DataGrid.Views.ViewBase view)
{
m_isContainerPrepared = true; this.DefaultStyleKey = view.GetDefaultStyleKey(typeof(GroupHeaderControl));
} }
protected virtual void ClearContainer() protected internal virtual bool ShouldHandleSelectionEvent(InputEventArgs eventArgs)
{ {
m_itemContainerManager.Clear( m_isRecyclingCandidate ); var targetChild = eventArgs.OriginalSource as DependencyObject;
m_isContainerPrepared = false;
}
protected internal virtual void PrepareDefaultStyleKey( Xceed.Wpf.DataGrid.Views.ViewBase view ) // 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.
this.DefaultStyleKey = view.GetDefaultStyleKey( typeof( GroupHeaderControl ) ); var collapsedButtonParent = TreeHelper.FindParent<ToggleButton>(targetChild, true, null, this);
} if (collapsedButtonParent != null)
return false;
protected internal virtual bool ShouldHandleSelectionEvent( InputEventArgs eventArgs ) var groupNavigationControlParent = TreeHelper.FindParent<GroupNavigationControl>(targetChild, true, null, this);
{ if (groupNavigationControlParent != null)
var targetChild = eventArgs.OriginalSource as DependencyObject; return false;
// If the event is comming from a specific control inside the header (GroupNavigationControl or Collapsed button), return true;
// 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;
var groupNavigationControlParent = TreeHelper.FindParent<GroupNavigationControl>( targetChild, true, null, this ); private static void OnParentGridControlChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
if( groupNavigationControlParent != null ) {
return false; 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 ) private void OnExpandCanExecute(object sender, CanExecuteRoutedEventArgs e)
{ {
DataGridControl grid = e.NewValue as DataGridControl; e.CanExecute = false;
GroupHeaderControl groupHeaderControl = sender as GroupHeaderControl;
if( ( groupHeaderControl != null ) && ( grid != null ) ) if (e.Parameter == null)
{ {
groupHeaderControl.PrepareDefaultStyleKey( grid.GetView() ); //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 ) private void OnExpandExecuted(object sender, ExecutedRoutedEventArgs e)
{ {
e.CanExecute = false; this.FindGroupCommandTarget(e.OriginalSource).IsExpanded = true;
}
if( e.Parameter == null ) private void OnCollapseCanExecute(object sender, CanExecuteRoutedEventArgs e)
{ {
//can execute the Expand command if the group is NOT expanded. e.CanExecute = false;
e.CanExecute = !this.FindGroupCommandTarget( e.OriginalSource ).IsExpanded;
}
}
private void OnExpandExecuted( object sender, ExecutedRoutedEventArgs e ) if (e.Parameter == null)
{ {
this.FindGroupCommandTarget( e.OriginalSource ).IsExpanded = true; //can execute the Collapse command if the group is expanded.
} e.CanExecute = this.FindGroupCommandTarget(e.OriginalSource).IsExpanded;
}
}
private void OnCollapseCanExecute( object sender, CanExecuteRoutedEventArgs e ) private void OnCollapseExecuted(object sender, ExecutedRoutedEventArgs e)
{ {
e.CanExecute = false; this.FindGroupCommandTarget(e.OriginalSource).IsExpanded = false;
}
if( e.Parameter == null ) private void OnToggleCanExecute(object sender, CanExecuteRoutedEventArgs e)
{ {
//can execute the Collapse command if the group is expanded. e.CanExecute = false;
e.CanExecute = this.FindGroupCommandTarget( e.OriginalSource ).IsExpanded;
}
}
private void OnCollapseExecuted( object sender, ExecutedRoutedEventArgs e ) if (e.Parameter == null)
{ {
this.FindGroupCommandTarget( e.OriginalSource ).IsExpanded = false; e.CanExecute = true; //can always toggle
} }
}
private void OnToggleCanExecute( object sender, CanExecuteRoutedEventArgs e ) private void OnToggleExecuted(object sender, ExecutedRoutedEventArgs e)
{ {
e.CanExecute = false; Group group = FindGroupCommandTarget(e.OriginalSource);
if( e.Parameter == null ) group.IsExpanded = !group.IsExpanded;
{ }
e.CanExecute = true; //can always toggle
}
}
private void OnToggleExecuted( object sender, ExecutedRoutedEventArgs e ) // We use an ItemsControl inside the GroupHeaderControl to represent the
{ // ancestors (ParentGroups) of this.Group, and each item in this ItemsControl
Group group = FindGroupCommandTarget( e.OriginalSource ); // 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 Group groupCommandTarget = dataContext as Group;
// 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;
FrameworkElement fe = originalSource as FrameworkElement; return (groupCommandTarget != null) ? groupCommandTarget : this.Group;
if( fe != null )
{
dataContext = fe.DataContext;
}
else
{
FrameworkContentElement fce = originalSource as FrameworkContentElement;
if( fce != null )
{
dataContext = fce.DataContext;
} }
}
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 ) #endregion
{
var handler = this.PropertyChanged;
if( handler == null )
return;
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 void IDataGridItemContainer.PrepareContainer(DataGridContext dataGridContext, object item)
{ {
get this.PrepareContainer(dataGridContext, item);
{ }
return this.CanBeRecycled;
}
}
bool IDataGridItemContainer.IsRecyclingCandidate void IDataGridItemContainer.ClearContainer()
{ {
get this.ClearContainer();
{ }
return m_isRecyclingCandidate;
}
set
{
m_isRecyclingCandidate = value;
}
}
void IDataGridItemContainer.PrepareContainer( DataGridContext dataGridContext, object item ) void IDataGridItemContainer.CleanRecyclingCandidate()
{ {
this.PrepareContainer( dataGridContext, item ); m_itemContainerManager.CleanRecyclingCandidates();
} }
void IDataGridItemContainer.ClearContainer() #endregion
{
this.ClearContainer();
}
void IDataGridItemContainer.CleanRecyclingCandidate() private readonly DataGridItemContainerManager m_itemContainerManager;
{ private bool m_isContainerPrepared;
m_itemContainerManager.CleanRecyclingCandidates(); 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 EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xceed.Wpf.Toolkit", "Src\Xceed.Wpf.Toolkit\Xceed.Wpf.Toolkit.csproj", "{72E591D6-8F83-4D8C-8F67-9C325E623234}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xceed.Wpf.Toolkit", "Src\Xceed.Wpf.Toolkit\Xceed.Wpf.Toolkit.csproj", "{72E591D6-8F83-4D8C-8F67-9C325E623234}"
EndProject 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 EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xceed.Wpf.AvalonDock", "Src\Xceed.Wpf.AvalonDock\Xceed.Wpf.AvalonDock.csproj", "{DB81988F-E0F2-45A0-A1FD-8C37F3D35244}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xceed.Wpf.AvalonDock", "Src\Xceed.Wpf.AvalonDock\Xceed.Wpf.AvalonDock.csproj", "{DB81988F-E0F2-45A0-A1FD-8C37F3D35244}"
EndProject EndProject

Loading…
Cancel
Save