Init
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*************************************************************************************
|
||||
|
||||
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
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using Xceed.Wpf.Toolkit.PropertyGrid.Converters;
|
||||
using System.Windows;
|
||||
using Xceed.Wpf.Toolkit.Core.Utilities;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit.PropertyGrid
|
||||
{
|
||||
public abstract class DefinitionBase : DependencyObject
|
||||
{
|
||||
private bool _isLocked;
|
||||
|
||||
internal bool IsLocked
|
||||
{
|
||||
get { return _isLocked; }
|
||||
}
|
||||
|
||||
internal void ThrowIfLocked<TMember>( Expression<Func<TMember>> propertyExpression )
|
||||
{
|
||||
//In XAML, when using any properties of PropertyDefinition, the error of ThrowIfLocked is always thrown => prevent it !
|
||||
if( DesignerProperties.GetIsInDesignMode( this ) )
|
||||
return;
|
||||
|
||||
if( this.IsLocked )
|
||||
{
|
||||
string propertyName = ReflectionHelper.GetPropertyOrFieldName( propertyExpression );
|
||||
string message = string.Format(
|
||||
@"Cannot modify {0} once the definition has beed added to a collection.",
|
||||
propertyName );
|
||||
throw new InvalidOperationException( message );
|
||||
}
|
||||
}
|
||||
|
||||
internal virtual void Lock()
|
||||
{
|
||||
if( !_isLocked )
|
||||
{
|
||||
_isLocked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*************************************************************************************
|
||||
|
||||
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
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit.PropertyGrid
|
||||
{
|
||||
public abstract class EditorDefinitionBase : PropertyDefinitionBase
|
||||
{
|
||||
|
||||
internal EditorDefinitionBase() { }
|
||||
|
||||
internal FrameworkElement GenerateEditingElementInternal( PropertyItemBase propertyItem )
|
||||
{
|
||||
return this.GenerateEditingElement( propertyItem );
|
||||
}
|
||||
|
||||
protected virtual FrameworkElement GenerateEditingElement( PropertyItemBase propertyItem ) { return null; }
|
||||
|
||||
internal void UpdateProperty( FrameworkElement element, DependencyProperty elementProp, DependencyProperty definitionProperty )
|
||||
{
|
||||
object currentValue = this.GetValue( definitionProperty );
|
||||
object localValue = this.ReadLocalValue( definitionProperty );
|
||||
object elementValue = element.GetValue( elementProp );
|
||||
bool areEquals = false;
|
||||
|
||||
// Avoid setting values if it does not affect anything
|
||||
// because setting a local value may prevent a style setter from being active.
|
||||
if( localValue != DependencyProperty.UnsetValue )
|
||||
{
|
||||
if( ( elementValue != null ) && ( currentValue != null ) )
|
||||
{
|
||||
areEquals = ( elementValue.GetType().IsValueType && currentValue.GetType().IsValueType )
|
||||
? elementValue.Equals( currentValue ) // Value Types
|
||||
: currentValue == element.GetValue( elementProp ); // Reference Types
|
||||
}
|
||||
|
||||
if( !areEquals )
|
||||
{
|
||||
element.SetValue( elementProp, currentValue );
|
||||
}
|
||||
else
|
||||
{
|
||||
element.ClearValue( elementProp );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*************************************************************************************
|
||||
|
||||
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
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit.PropertyGrid
|
||||
{
|
||||
public class EditorTemplateDefinition : EditorDefinitionBase
|
||||
{
|
||||
|
||||
|
||||
#region EditingTemplate
|
||||
public static readonly DependencyProperty EditingTemplateProperty =
|
||||
DependencyProperty.Register( "EditingTemplate", typeof( DataTemplate ), typeof( EditorTemplateDefinition ), new UIPropertyMetadata( null ) );
|
||||
|
||||
public DataTemplate EditingTemplate
|
||||
{
|
||||
get { return ( DataTemplate )GetValue( EditingTemplateProperty ); }
|
||||
set { SetValue( EditingTemplateProperty, value ); }
|
||||
}
|
||||
#endregion //EditingTemplate
|
||||
|
||||
protected override sealed FrameworkElement GenerateEditingElement( PropertyItemBase propertyItem )
|
||||
{
|
||||
return ( this.EditingTemplate != null )
|
||||
? this.EditingTemplate.LoadContent() as FrameworkElement
|
||||
: null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*************************************************************************************
|
||||
|
||||
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
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using Xceed.Wpf.Toolkit.PropertyGrid.Converters;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit.PropertyGrid
|
||||
{
|
||||
public abstract class PropertyDefinitionBase : DefinitionBase
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
internal PropertyDefinitionBase()
|
||||
{
|
||||
_targetProperties = new List<object>();
|
||||
this.PropertyDefinitions = new PropertyDefinitionCollection();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
#region TargetProperties
|
||||
|
||||
[TypeConverter(typeof(ListConverter))]
|
||||
public IList TargetProperties
|
||||
{
|
||||
get { return _targetProperties; }
|
||||
set
|
||||
{
|
||||
this.ThrowIfLocked( () => this.TargetProperties );
|
||||
_targetProperties = value;
|
||||
}
|
||||
}
|
||||
|
||||
private IList _targetProperties;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PropertyDefinitions
|
||||
|
||||
public PropertyDefinitionCollection PropertyDefinitions
|
||||
{
|
||||
get
|
||||
{
|
||||
return _propertyDefinitions;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.ThrowIfLocked( () => this.PropertyDefinitions );
|
||||
_propertyDefinitions = value;
|
||||
}
|
||||
}
|
||||
|
||||
private PropertyDefinitionCollection _propertyDefinitions;
|
||||
|
||||
#endregion //PropertyDefinitions
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
internal override void Lock()
|
||||
{
|
||||
if( this.IsLocked )
|
||||
return;
|
||||
|
||||
base.Lock();
|
||||
|
||||
// Just create a new copy of the properties target to ensure
|
||||
// that the list doesn't ever get modified.
|
||||
|
||||
List<object> newList = new List<object>();
|
||||
if( _targetProperties != null )
|
||||
{
|
||||
foreach( object p in _targetProperties )
|
||||
{
|
||||
object prop = p;
|
||||
// Convert all TargetPropertyType to Types
|
||||
var targetType = prop as TargetPropertyType;
|
||||
if( targetType != null )
|
||||
{
|
||||
prop = targetType.Type;
|
||||
}
|
||||
newList.Add( prop );
|
||||
}
|
||||
}
|
||||
|
||||
//In Designer Mode, the Designer is broken if using a ReadOnlyCollection
|
||||
_targetProperties = DesignerProperties.GetIsInDesignMode( this )
|
||||
? new Collection<object>( newList )
|
||||
: new ReadOnlyCollection<object>( newList ) as IList;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user