diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Images/Delete16.png b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Images/Delete16.png deleted file mode 100644 index dee2496a..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Images/Delete16.png and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Images/Duplicate.png b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Images/Duplicate.png deleted file mode 100644 index 51b048bc..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Images/Duplicate.png and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControl.Icon.bmp b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControl.Icon.bmp deleted file mode 100644 index 76f9520f..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControl.Icon.bmp and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControl.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControl.cs deleted file mode 100644 index 7a0021a6..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControl.cs +++ /dev/null @@ -1,712 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using Xceed.Wpf.Toolkit.Core.Utilities; -using Xceed.Wpf.Toolkit.PropertyGrid; -using System.Windows.Threading; -using System.Reflection; - -namespace Xceed.Wpf.Toolkit -{ - [TemplatePart( Name = PART_NewItemTypesComboBox, Type = typeof( ComboBox ) )] - [TemplatePart( Name = PART_PropertyGrid, Type = typeof( PropertyGrid.PropertyGrid ) )] - [TemplatePart( Name = PART_ListBox, Type = typeof( ListBox ) )] - public class CollectionControl : Control - { - private const string PART_NewItemTypesComboBox = "PART_NewItemTypesComboBox"; - private const string PART_PropertyGrid = "PART_PropertyGrid"; - private const string PART_ListBox = "PART_ListBox"; - - #region Private Members - - private ComboBox _newItemTypesComboBox; - private PropertyGrid.PropertyGrid _propertyGrid; - private ListBox _listBox; - private bool _isCollectionUpdated; - - #endregion - - #region Properties - - #region IsReadOnly Property - - public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register( "IsReadOnly", typeof( bool ), typeof( CollectionControl ), new UIPropertyMetadata( false ) ); - public bool IsReadOnly - { - get - { - return ( bool )GetValue( IsReadOnlyProperty ); - } - set - { - SetValue( IsReadOnlyProperty, value ); - } - } - - #endregion //Items - - #region Items Property - - public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register( "Items", typeof( ObservableCollection ), typeof( CollectionControl ), new UIPropertyMetadata( null ) ); - public ObservableCollection Items - { - get - { - return ( ObservableCollection )GetValue( ItemsProperty ); - } - set - { - SetValue( ItemsProperty, value ); - } - } - - #endregion //Items - - #region ItemsSource Property - - public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register( "ItemsSource", typeof( IEnumerable ), typeof( CollectionControl ), new UIPropertyMetadata( null, OnItemsSourceChanged ) ); - public IEnumerable ItemsSource - { - get - { - return (IEnumerable)GetValue( ItemsSourceProperty ); - } - set - { - SetValue( ItemsSourceProperty, value ); - } - } - - private static void OnItemsSourceChanged( DependencyObject d, DependencyPropertyChangedEventArgs e ) - { - var CollectionControl = ( CollectionControl )d; - if( CollectionControl != null ) - CollectionControl.OnItemSourceChanged( (IEnumerable)e.OldValue, (IEnumerable)e.NewValue ); - } - - public void OnItemSourceChanged( IEnumerable oldValue, IEnumerable newValue ) - { - if( newValue != null ) - { - var dict = newValue as IDictionary; - if( dict != null ) - { - // A Dictionary contains KeyValuePair that can't be edited. - // We need to Add EditableKeyValuePairs from DictionaryEntries. - foreach( DictionaryEntry item in dict ) - { - var keyType = (item.Key != null) - ? item.Key.GetType() - : (dict.GetType().GetGenericArguments().Count() > 0) ? dict.GetType().GetGenericArguments()[0] : typeof( object ); - var valueType = (item.Value != null) - ? item.Value.GetType() - : (dict.GetType().GetGenericArguments().Count() > 1) ? dict.GetType().GetGenericArguments()[ 1 ] : typeof( object ); - var editableKeyValuePair = ListUtilities.CreateEditableKeyValuePair( item.Key - , keyType - , item.Value - , valueType ); - this.Items.Add( editableKeyValuePair ); - } - } - else - { - foreach( var item in newValue ) - { - if( item != null ) - { - Items.Add( item ); - } - } - } - } - } - - #endregion //ItemsSource - - #region ItemsSourceType Property - - public static readonly DependencyProperty ItemsSourceTypeProperty = DependencyProperty.Register( "ItemsSourceType", typeof( Type ), typeof( CollectionControl ), new UIPropertyMetadata( null ) ); - public Type ItemsSourceType - { - get - { - return ( Type )GetValue( ItemsSourceTypeProperty ); - } - set - { - SetValue( ItemsSourceTypeProperty, value ); - } - } - - #endregion //ItemsSourceType - - #region NewItemType Property - - public static readonly DependencyProperty NewItemTypesProperty = DependencyProperty.Register( "NewItemTypes", typeof( IList ), typeof( CollectionControl ), new UIPropertyMetadata( null ) ); - public IList NewItemTypes - { - get - { - return ( IList )GetValue( NewItemTypesProperty ); - } - set - { - SetValue( NewItemTypesProperty, value ); - } - } - - #endregion //NewItemType - - #region PropertiesLabel Property - - public static readonly DependencyProperty PropertiesLabelProperty = DependencyProperty.Register( "PropertiesLabel", typeof( object ), typeof( CollectionControl ), new UIPropertyMetadata( "Properties:" ) ); - public object PropertiesLabel - { - get - { - return ( object )GetValue( PropertiesLabelProperty ); - } - set - { - SetValue( PropertiesLabelProperty, value ); - } - } - - #endregion //PropertiesLabel - - #region SelectedItem Property - - public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register( "SelectedItem", typeof( object ), typeof( CollectionControl ), new UIPropertyMetadata( null ) ); - public object SelectedItem - { - get - { - return ( object )GetValue( SelectedItemProperty ); - } - set - { - SetValue( SelectedItemProperty, value ); - } - } - - #endregion //EditorDefinitions - - #region TypeSelectionLabel Property - - public static readonly DependencyProperty TypeSelectionLabelProperty = DependencyProperty.Register( "TypeSelectionLabel", typeof( object ), typeof( CollectionControl ), new UIPropertyMetadata( "Select type:" ) ); - public object TypeSelectionLabel - { - get - { - return ( object )GetValue( TypeSelectionLabelProperty ); - } - set - { - SetValue( TypeSelectionLabelProperty, value ); - } - } - - #endregion //TypeSelectionLabel - - #region EditorDefinitions Property - - public static readonly DependencyProperty EditorDefinitionsProperty = DependencyProperty.Register( "EditorDefinitions", typeof( EditorDefinitionCollection ), typeof( CollectionControl ), new UIPropertyMetadata( null ) ); - public EditorDefinitionCollection EditorDefinitions - { - get - { - return ( EditorDefinitionCollection )GetValue( EditorDefinitionsProperty ); - } - set - { - SetValue( EditorDefinitionsProperty, value ); - } - } - - #endregion //EditorDefinitions - - #endregion //Properties - - #region Override Methods - - public override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - if( _newItemTypesComboBox != null ) - { - _newItemTypesComboBox.Loaded -= new RoutedEventHandler( this.NewItemTypesComboBox_Loaded ); - } - _newItemTypesComboBox = GetTemplateChild( PART_NewItemTypesComboBox ) as ComboBox; - if( _newItemTypesComboBox != null ) - { - _newItemTypesComboBox.Loaded += new RoutedEventHandler( this.NewItemTypesComboBox_Loaded ); - } - - _listBox = this.GetTemplateChild( PART_ListBox ) as ListBox; - - if( _propertyGrid != null ) - { - _propertyGrid.PropertyValueChanged -= this.PropertyGrid_PropertyValueChanged; - } - _propertyGrid = GetTemplateChild( PART_PropertyGrid ) as PropertyGrid.PropertyGrid; - if( _propertyGrid != null ) - { - _propertyGrid.PropertyValueChanged += this.PropertyGrid_PropertyValueChanged; - } - } - - public PropertyGrid.PropertyGrid PropertyGrid - { - get - { - if( _propertyGrid == null ) - { - this.ApplyTemplate(); - } - return _propertyGrid; - } - } - - - - - #endregion - - #region Constructors - - static CollectionControl() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( CollectionControl ), new FrameworkPropertyMetadata( typeof( CollectionControl ) ) ); - } - - public CollectionControl() - { - Items = new ObservableCollection(); - CommandBindings.Add( new CommandBinding( ApplicationCommands.New, this.AddNew, this.CanAddNew ) ); - CommandBindings.Add( new CommandBinding( ApplicationCommands.Delete, this.Delete, this.CanDelete ) ); - CommandBindings.Add( new CommandBinding( ApplicationCommands.Copy, this.Duplicate, this.CanDuplicate ) ); - CommandBindings.Add( new CommandBinding( ComponentCommands.MoveDown, this.MoveDown, this.CanMoveDown ) ); - CommandBindings.Add( new CommandBinding( ComponentCommands.MoveUp, this.MoveUp, this.CanMoveUp ) ); - } - - #endregion //Constructors - - #region Events - - #region ItemDeleting Event - - public delegate void ItemDeletingRoutedEventHandler( object sender, ItemDeletingEventArgs e ); - - public static readonly RoutedEvent ItemDeletingEvent = EventManager.RegisterRoutedEvent( "ItemDeleting", RoutingStrategy.Bubble, typeof( ItemDeletingRoutedEventHandler ), typeof( CollectionControl ) ); - public event ItemDeletingRoutedEventHandler ItemDeleting - { - add - { - AddHandler( ItemDeletingEvent, value ); - } - remove - { - RemoveHandler( ItemDeletingEvent, value ); - } - } - - #endregion //ItemDeleting Event - - #region ItemDeleted Event - - public delegate void ItemDeletedRoutedEventHandler( object sender, ItemEventArgs e ); - - public static readonly RoutedEvent ItemDeletedEvent = EventManager.RegisterRoutedEvent( "ItemDeleted", RoutingStrategy.Bubble, typeof( ItemDeletedRoutedEventHandler ), typeof( CollectionControl ) ); - public event ItemDeletedRoutedEventHandler ItemDeleted - { - add - { - AddHandler( ItemDeletedEvent, value ); - } - remove - { - RemoveHandler( ItemDeletedEvent, value ); - } - } - - #endregion //ItemDeleted Event - - #region ItemAdding Event - - public delegate void ItemAddingRoutedEventHandler( object sender, ItemAddingEventArgs e ); - - public static readonly RoutedEvent ItemAddingEvent = EventManager.RegisterRoutedEvent( "ItemAdding", RoutingStrategy.Bubble, typeof( ItemAddingRoutedEventHandler ), typeof( CollectionControl ) ); - public event ItemAddingRoutedEventHandler ItemAdding - { - add - { - AddHandler( ItemAddingEvent, value ); - } - remove - { - RemoveHandler( ItemAddingEvent, value ); - } - } - - #endregion //ItemAdding Event - - #region ItemAdded Event - - public delegate void ItemAddedRoutedEventHandler( object sender, ItemEventArgs e ); - - public static readonly RoutedEvent ItemAddedEvent = EventManager.RegisterRoutedEvent( "ItemAdded", RoutingStrategy.Bubble, typeof( ItemAddedRoutedEventHandler ), typeof( CollectionControl ) ); - public event ItemAddedRoutedEventHandler ItemAdded - { - add - { - AddHandler( ItemAddedEvent, value ); - } - remove - { - RemoveHandler( ItemAddedEvent, value ); - } - } - - #endregion //ItemAdded Event - - #region ItemMovedDown Event - - public delegate void ItemMovedDownRoutedEventHandler( object sender, ItemEventArgs e ); - - public static readonly RoutedEvent ItemMovedDownEvent = EventManager.RegisterRoutedEvent( "ItemMovedDown", RoutingStrategy.Bubble, typeof( ItemMovedDownRoutedEventHandler ), typeof( CollectionControl ) ); - public event ItemMovedDownRoutedEventHandler ItemMovedDown - { - add - { - AddHandler( ItemMovedDownEvent, value ); - } - remove - { - RemoveHandler( ItemMovedDownEvent, value ); - } - } - - #endregion //ItemMovedDown Event - - #region ItemMovedUp Event - - public delegate void ItemMovedUpRoutedEventHandler( object sender, ItemEventArgs e ); - - public static readonly RoutedEvent ItemMovedUpEvent = EventManager.RegisterRoutedEvent( "ItemMovedUp", RoutingStrategy.Bubble, typeof( ItemMovedUpRoutedEventHandler ), typeof( CollectionControl ) ); - public event ItemMovedUpRoutedEventHandler ItemMovedUp - { - add - { - AddHandler( ItemMovedUpEvent, value ); - } - remove - { - RemoveHandler( ItemMovedUpEvent, value ); - } - } - - #endregion //ItemMovedUp Event - - #endregion - - #region EventHandlers - - void NewItemTypesComboBox_Loaded( object sender, RoutedEventArgs e ) - { - if( _newItemTypesComboBox != null ) - _newItemTypesComboBox.SelectedIndex = 0; - } - - private void PropertyGrid_PropertyValueChanged( object sender, PropertyGrid.PropertyValueChangedEventArgs e ) - { - if( _listBox != null ) - { - _isCollectionUpdated = true; - _listBox.Dispatcher.BeginInvoke( DispatcherPriority.Input, new Action( () => - { - _listBox.Items.Refresh(); - } - ) ); - } - } - - #endregion - - #region Commands - - private void AddNew( object sender, ExecutedRoutedEventArgs e ) - { - var newItem = this.CreateNewItem( ( Type )e.Parameter ); - - this.AddNewCore( newItem ); - } - - private void CanAddNew( object sender, CanExecuteRoutedEventArgs e ) - { - var t = e.Parameter as Type; - this.CanAddNewCore( t, e ); - } - - private void CanAddNewCore( Type t, CanExecuteRoutedEventArgs e ) - { - if( ( t != null ) && !this.IsReadOnly ) - { - var isComplexStruct = t.IsValueType && !t.IsEnum && !t.IsPrimitive; - - if( isComplexStruct || ( t.GetConstructor( Type.EmptyTypes ) != null ) ) - { - e.CanExecute = true; - } - } - } - - private void AddNewCore( object newItem ) - { - if( newItem == null ) - throw new ArgumentNullException( "newItem" ); - - var eventArgs = new ItemAddingEventArgs( ItemAddingEvent, newItem ); - this.RaiseEvent( eventArgs ); - if( eventArgs.Cancel ) - return; - newItem = eventArgs.Item; - - this.Items.Add( newItem ); - - this.RaiseEvent( new ItemEventArgs( ItemAddedEvent, newItem ) ); - _isCollectionUpdated = true; - - this.SelectedItem = newItem; - } - - private void Delete( object sender, ExecutedRoutedEventArgs e ) - { - var eventArgs = new ItemDeletingEventArgs( ItemDeletingEvent, e.Parameter ); - this.RaiseEvent( eventArgs ); - if( eventArgs.Cancel ) - return; - - this.Items.Remove( e.Parameter ); - - this.RaiseEvent( new ItemEventArgs( ItemDeletedEvent, e.Parameter ) ); - _isCollectionUpdated = true; - } - - private void CanDelete( object sender, CanExecuteRoutedEventArgs e ) - { - e.CanExecute = e.Parameter != null && !this.IsReadOnly; - } - - private void Duplicate( object sender, ExecutedRoutedEventArgs e ) - { - var newItem = this.DuplicateItem( e ); - this.AddNewCore( newItem ); - } - - private void CanDuplicate( object sender, CanExecuteRoutedEventArgs e ) - { - var t = (e.Parameter != null) ? e.Parameter.GetType() : null; - this.CanAddNewCore( t, e ); - } - - private object DuplicateItem( ExecutedRoutedEventArgs e ) - { - if( e == null ) - throw new ArgumentNullException( "e" ); - - var baseItem = e.Parameter; - var newItemType = baseItem.GetType(); - var newItem = this.CreateNewItem( newItemType ); - - var type = newItemType; - while( type != null ) - { - var baseProperties = type.GetFields( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance ); - foreach( var prop in baseProperties ) - { - prop.SetValue( newItem, prop.GetValue( baseItem ) ); - } - type = type.BaseType; - } - - return newItem; - } - - private void MoveDown( object sender, ExecutedRoutedEventArgs e ) - { - var selectedItem = e.Parameter; - var index = Items.IndexOf( selectedItem ); - Items.RemoveAt( index ); - Items.Insert( ++index, selectedItem ); - - this.RaiseEvent( new ItemEventArgs( ItemMovedDownEvent, selectedItem ) ); - _isCollectionUpdated = true; - - this.SelectedItem = selectedItem; - } - - private void CanMoveDown( object sender, CanExecuteRoutedEventArgs e ) - { - if( e.Parameter != null && Items.IndexOf( e.Parameter ) < ( Items.Count - 1 ) && !this.IsReadOnly ) - e.CanExecute = true; - } - - private void MoveUp( object sender, ExecutedRoutedEventArgs e ) - { - var selectedItem = e.Parameter; - var index = Items.IndexOf( selectedItem ); - this.Items.RemoveAt( index ); - this.Items.Insert( --index, selectedItem ); - - this.RaiseEvent( new ItemEventArgs( ItemMovedUpEvent, selectedItem ) ); - _isCollectionUpdated = true; - - this.SelectedItem = selectedItem; - } - - private void CanMoveUp( object sender, CanExecuteRoutedEventArgs e ) - { - if( e.Parameter != null && Items.IndexOf( e.Parameter ) > 0 && !this.IsReadOnly ) - e.CanExecute = true; - } - - #endregion //Commands - - #region Methods - - public bool PersistChanges() - { - this.PersistChanges( this.Items ); - return _isCollectionUpdated; - } - - internal void PersistChanges( IList sourceList ) - { - var collection = ComputeItemsSource(); - if( collection == null ) - return; - - //IDictionary and IDictionary - if( collection is IDictionary ) - { - //For a Dictionary, we need to parse the list of EditableKeyValuePair and add KeyValuePair to the Dictionary. - var dict = (IDictionary)collection; - //the easiest way to persist changes to the source is to just clear the source list and then add all items to it. - dict.Clear(); - - foreach( var item in sourceList ) - { - var propInfoKey = item.GetType().GetProperty( "Key" ); - var propInfoValue = item.GetType().GetProperty( "Value" ); - if( (propInfoKey != null) && (propInfoValue != null) ) - { - dict.Add( propInfoKey.GetValue( item, null ), propInfoValue.GetValue( item, null ) ); - } - } - } - //IList - else if( collection is IList ) - { - var list = (IList)collection; - - //the easiest way to persist changes to the source is to just clear the source list and then add all items to it. - list.Clear(); - - if( list.IsFixedSize ) - { - if( sourceList.Count > list.Count ) - throw new IndexOutOfRangeException("Exceeding array size."); - - for( int i = 0; i < sourceList.Count; ++i ) - list[ i ] = sourceList[ i ]; - } - else - { - foreach( var item in sourceList ) - { - list.Add( item ); - } - } - } - else - { - //ICollection (or IList) - var collectionType = collection.GetType(); - var iCollectionOfTInterface = collectionType.GetInterfaces().FirstOrDefault( x => x.IsGenericType && (x.GetGenericTypeDefinition() == typeof( ICollection<> )) ); - if( iCollectionOfTInterface != null ) - { - var argumentType = iCollectionOfTInterface.GetGenericArguments().FirstOrDefault(); - if( argumentType != null ) - { - var iCollectionOfTType = typeof( ICollection<> ).MakeGenericType( argumentType ); - - //the easiest way to persist changes to the source is to just clear the source list and then add all items to it. - iCollectionOfTType.GetMethod( "Clear" ).Invoke( collection, null ); - - foreach( var item in sourceList ) - { - iCollectionOfTType.GetMethod( "Add" ).Invoke( collection, new object[] { item } ); - } - } - } - } - } - - private IEnumerable CreateItemsSource() - { - IEnumerable collection = null; - - if( ItemsSourceType != null ) - { - var constructor = ItemsSourceType.GetConstructor( Type.EmptyTypes ); - if( constructor != null ) - { - collection = ( IEnumerable )constructor.Invoke( null ); - } - else if( ItemsSourceType.IsArray ) - { - collection = Array.CreateInstance( ItemsSourceType.GetElementType(), Items.Count ); - } - } - - return collection; - } - - private object CreateNewItem( Type type ) - { - return Activator.CreateInstance( type ); - } - - private IEnumerable ComputeItemsSource() - { - if( ItemsSource == null ) - ItemsSource = CreateItemsSource(); - - return ItemsSource; - } - - #endregion //Methods - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControlButton.Icon.bmp b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControlButton.Icon.bmp deleted file mode 100644 index 76f9520f..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControlButton.Icon.bmp and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControlButton.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControlButton.cs deleted file mode 100644 index a1698cd9..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControlButton.cs +++ /dev/null @@ -1,178 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using Xceed.Wpf.Toolkit.PropertyGrid; - -namespace Xceed.Wpf.Toolkit -{ - public class CollectionControlButton : Button - { - #region Constructors - - static CollectionControlButton() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( CollectionControlButton ), new FrameworkPropertyMetadata( typeof( CollectionControlButton ) ) ); - } - - public CollectionControlButton() - { - this.Click += this.CollectionControlButton_Click; - } - - #endregion //Constructors - - #region Properties - - #region EditorDefinitions Property - - public static readonly DependencyProperty EditorDefinitionsProperty = DependencyProperty.Register( "EditorDefinitions", typeof( EditorDefinitionCollection ), typeof( CollectionControlButton ), new UIPropertyMetadata( null ) ); - public EditorDefinitionCollection EditorDefinitions - { - get - { - return ( EditorDefinitionCollection )GetValue( EditorDefinitionsProperty ); - } - set - { - SetValue( EditorDefinitionsProperty, value ); - } - } - - #endregion //EditorDefinitions - - #region IsReadOnly Property - - public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register( "IsReadOnly", typeof( bool ), typeof( CollectionControlButton ), new UIPropertyMetadata( false ) ); - public bool IsReadOnly - { - get - { - return ( bool )GetValue( IsReadOnlyProperty ); - } - set - { - SetValue( IsReadOnlyProperty, value ); - } - } - - #endregion //IsReadOnly - - #region ItemsSource Property - - public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register( "ItemsSource", typeof( IEnumerable ), typeof( CollectionControlButton ), new UIPropertyMetadata( null ) ); - public IEnumerable ItemsSource - { - get - { - return ( IEnumerable )GetValue( ItemsSourceProperty ); - } - set - { - SetValue( ItemsSourceProperty, value ); - } - } - - #endregion //ItemsSource - - #region ItemsSourceType Property - - public static readonly DependencyProperty ItemsSourceTypeProperty = DependencyProperty.Register( "ItemsSourceType", typeof( Type ), typeof( CollectionControlButton ), new UIPropertyMetadata( null ) ); - public Type ItemsSourceType - { - get - { - return ( Type )GetValue( ItemsSourceTypeProperty ); - } - set - { - SetValue( ItemsSourceTypeProperty, value ); - } - } - - #endregion //ItemsSourceType - - #region NewItemTypes Property - - public static readonly DependencyProperty NewItemTypesProperty = DependencyProperty.Register( "NewItemTypes", typeof( IList ), typeof( CollectionControlButton ), new UIPropertyMetadata( null ) ); - public IList NewItemTypes - { - get - { - return ( IList )GetValue( NewItemTypesProperty ); - } - set - { - SetValue( NewItemTypesProperty, value ); - } - } - - #endregion //NewItemTypes - - #endregion - - #region Base Class Overrides - - - #endregion - - #region Methods - - private void CollectionControlButton_Click( object sender, RoutedEventArgs e ) - { - var collectionControlDialog = new CollectionControlDialog(); - var binding = new Binding( "ItemsSource" ) { Source = this, Mode = BindingMode.TwoWay }; - BindingOperations.SetBinding( collectionControlDialog, CollectionControlDialog.ItemsSourceProperty, binding ); - collectionControlDialog.NewItemTypes = this.NewItemTypes; - collectionControlDialog.ItemsSourceType = this.ItemsSourceType; - collectionControlDialog.IsReadOnly = this.IsReadOnly; - collectionControlDialog.EditorDefinitions = this.EditorDefinitions; - var collectionUpdated = collectionControlDialog.ShowDialog(); - if( collectionUpdated.HasValue && collectionUpdated.Value ) - { - this.RaiseEvent( new RoutedEventArgs( CollectionControlButton.CollectionUpdatedEvent, this ) ); - } - } - - #endregion - - #region Events - - #region CollectionUpdated Event - - public static readonly RoutedEvent CollectionUpdatedEvent = EventManager.RegisterRoutedEvent( "CollectionUpdated", RoutingStrategy.Bubble, typeof( EventHandler ), typeof( CollectionControlButton ) ); - public event RoutedEventHandler CollectionUpdated - { - add - { - AddHandler( CollectionUpdatedEvent, value ); - } - remove - { - RemoveHandler( CollectionUpdatedEvent, value ); - } - } - - #endregion //CollectionUpdated Event - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControlDialog.xaml b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControlDialog.xaml deleted file mode 100644 index 08dfc0d0..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControlDialog.xaml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControlDialog.xaml.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControlDialog.xaml.cs deleted file mode 100644 index 7c002b6a..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/CollectionControlDialog.xaml.cs +++ /dev/null @@ -1,353 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics; -using System.Windows; -using System.Windows.Media; -using Xceed.Wpf.Toolkit.Core.Utilities; -using System.Linq; -using System.Runtime.Serialization; -using System.Security; -using System.IO; -using System.Runtime.Serialization.Formatters.Binary; -using Xceed.Wpf.Toolkit.PropertyGrid; - -namespace Xceed.Wpf.Toolkit -{ - public partial class CollectionControlDialogBase : - Window - { - } - - /// - /// Interaction logic for CollectionControlDialog.xaml - /// - public partial class CollectionControlDialog : CollectionControlDialogBase - { - #region Private Members - - private IList originalData = new List(); - - #endregion - - #region Properties - - public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register( "ItemsSource", typeof( IEnumerable ), typeof( CollectionControlDialog ), new UIPropertyMetadata( null ) ); - public IEnumerable ItemsSource - { - get - { - return ( IEnumerable )GetValue( ItemsSourceProperty ); - } - set - { - SetValue( ItemsSourceProperty, value ); - } - } - - public static readonly DependencyProperty ItemsSourceTypeProperty = DependencyProperty.Register( "ItemsSourceType", typeof( Type ), typeof( CollectionControlDialog ), new UIPropertyMetadata( null ) ); - public Type ItemsSourceType - { - get - { - return ( Type )GetValue( ItemsSourceTypeProperty ); - } - set - { - SetValue( ItemsSourceTypeProperty, value ); - } - } - - public static readonly DependencyProperty NewItemTypesProperty = DependencyProperty.Register( "NewItemTypes", typeof( IList ), typeof( CollectionControlDialog ), new UIPropertyMetadata( null ) ); - public IList NewItemTypes - { - get - { - return ( IList )GetValue( NewItemTypesProperty ); - } - set - { - SetValue( NewItemTypesProperty, value ); - } - } - - public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register( "IsReadOnly", typeof( bool ), typeof( CollectionControlDialog ), new UIPropertyMetadata( false ) ); - public bool IsReadOnly - { - get - { - return ( bool )GetValue( IsReadOnlyProperty ); - } - set - { - SetValue( IsReadOnlyProperty, value ); - } - } - - public static readonly DependencyProperty EditorDefinitionsProperty = DependencyProperty.Register( "EditorDefinitions", typeof( EditorDefinitionCollection ), typeof( CollectionControlDialog ), new UIPropertyMetadata( null ) ); - public EditorDefinitionCollection EditorDefinitions - { - get - { - return ( EditorDefinitionCollection )GetValue( EditorDefinitionsProperty ); - } - set - { - SetValue( EditorDefinitionsProperty, value ); - } - } - - public CollectionControl CollectionControl - { - get - { - return _collectionControl; - } - } - - #endregion //Properties - - #region Constructors - - public CollectionControlDialog() - { - InitializeComponent(); - } - - public CollectionControlDialog( Type itemsourceType ) - : this() - { - ItemsSourceType = itemsourceType; - } - - public CollectionControlDialog( Type itemsourceType, IList newItemTypes ) - : this( itemsourceType ) - { - NewItemTypes = newItemTypes; - } - - #endregion //Constructors - - #region Overrides - - protected override void OnSourceInitialized( EventArgs e ) - { - base.OnSourceInitialized( e ); - - //Backup data if case "Cancel" is clicked. - if( this.ItemsSource != null ) - { - foreach( var item in this.ItemsSource ) - { - originalData.Add( this.Clone( item ) ); - } - } - } - - #endregion - - #region Event Handlers - - private void OkButton_Click( object sender, RoutedEventArgs e ) - { - if( this.ItemsSource is IDictionary ) - { - if( !this.AreDictionaryKeysValid() ) - { - MessageBox.Show( "All dictionary items should have distinct non-null Key values.", "Warning" ); - return; - } - } - - this.DialogResult = _collectionControl.PersistChanges(); - this.Close(); - } - - private void CancelButton_Click( object sender, RoutedEventArgs e ) - { - _collectionControl.PersistChanges( originalData ); - this.DialogResult = false; - this.Close(); - } - - #endregion //Event Hanlders - - #region Private Methods - - [SecuritySafeCritical] - private object Clone( object source ) - { - if( source == null ) - return null; - - object result = null; - var sourceType = source.GetType(); - - if( source is Array ) - { - using( var stream = new MemoryStream() ) - { - var formatter = new BinaryFormatter(); - formatter.Serialize( stream, source ); - stream.Seek( 0, SeekOrigin.Begin ); - result = ( Array )formatter.Deserialize( stream ); - } - } - // For IDictionary, we need to create EditableKeyValuePair to edit the Key-Value. - else if( ( this.ItemsSource is IDictionary ) - && sourceType.IsGenericType - && typeof( KeyValuePair<,> ).IsAssignableFrom( sourceType.GetGenericTypeDefinition() ) ) - { - result = this.GenerateEditableKeyValuePair( source ); - } - else - { - // Initialized a new object with default values - try - { - result = FormatterServices.GetUninitializedObject( sourceType ); - } - catch( Exception ) - { - } - - var constructor = sourceType.GetConstructor( Type.EmptyTypes ); - if( constructor != null ) - { - constructor.Invoke( result, null ); - } - else - { - result = source; - } - } - Debug.Assert( result != null ); - if( result != null ) - { - var properties = sourceType.GetProperties(); - - foreach( var propertyInfo in properties ) - { - try - { - var parameters = propertyInfo.GetIndexParameters(); - var index = parameters.GetLength( 0 ) == 0 ? null : new object[] { parameters.GetLength( 0 ) - 1 }; - var propertyInfoValue = propertyInfo.GetValue( source, index ); - - if( propertyInfo.CanWrite ) - { - // Look for nested object - if( propertyInfo.PropertyType.IsClass - && ( propertyInfo.PropertyType != typeof( Transform ) ) - && !propertyInfo.PropertyType.Equals( typeof( string ) ) ) - { - // We have a Collection/List of T. - if( propertyInfo.PropertyType.IsGenericType ) - { - // Clone sub-objects if the T are non-primitive types objects. - var arg = propertyInfo.PropertyType.GetGenericArguments().FirstOrDefault(); - if( ( arg != null ) && !arg.IsPrimitive && !arg.Equals( typeof( String ) ) && !arg.IsEnum ) - { - var nestedObject = this.Clone( propertyInfoValue ); - propertyInfo.SetValue( result, nestedObject, null ); - } - else - { - // copy object if the T are primitive types objects. - propertyInfo.SetValue( result, propertyInfoValue, null ); - } - } - else - { - var nestedObject = this.Clone( propertyInfoValue ); - if( nestedObject != null ) - { - // For T object included in List/Collections, Add it to the List/Collection of T. - if( index != null ) - { - result.GetType().GetMethod( "Add" ).Invoke( result, new[] { nestedObject } ); - } - else - { - propertyInfo.SetValue( result, nestedObject, null ); - } - } - } - } - else - { - // For T object included in List/Collections, Add it to the List/Collection of T. - if( index != null ) - { - result.GetType().GetMethod( "Add" ).Invoke( result, new[] { propertyInfoValue } ); - } - else - { - // copy regular object - propertyInfo.SetValue( result, propertyInfoValue, null ); - } - } - } - } - catch( Exception ) - { - } - } - } - - return result; - } - - private object GenerateEditableKeyValuePair( object source ) - { - var sourceType = source.GetType(); - if( ( sourceType.GetGenericArguments() == null ) || ( sourceType.GetGenericArguments().GetLength( 0 ) != 2 ) ) - return null; - - var propInfoKey = sourceType.GetProperty( "Key" ); - var propInfoValue = sourceType.GetProperty( "Value" ); - if( ( propInfoKey != null ) && ( propInfoValue != null ) ) - { - return ListUtilities.CreateEditableKeyValuePair( propInfoKey.GetValue( source, null ) - , sourceType.GetGenericArguments()[ 0 ] - , propInfoValue.GetValue( source, null ) - , sourceType.GetGenericArguments()[ 1 ] ); - } - return null; - } - - private bool AreDictionaryKeysValid() - { - var keys = _collectionControl.Items.Select( x => - { - var keyType = x.GetType().GetProperty( "Key" ); - if( keyType != null ) - { - return keyType.GetValue( x, null ); - } - return null; - } ); - - return ( keys.Distinct().Count() == _collectionControl.Items.Count ) - && keys.All( x => x != null ); - } - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/Converters/NewItemTypesComboBoxConverter.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/Converters/NewItemTypesComboBoxConverter.cs deleted file mode 100644 index d924872f..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/Converters/NewItemTypesComboBoxConverter.cs +++ /dev/null @@ -1,74 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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.Data; -using System.Globalization; -using Xceed.Wpf.Toolkit.Core.Utilities; - -namespace Xceed.Wpf.Toolkit.Converters -{ - /// - /// This multi-value converter is used in the CollectionControl template - /// to determine the list of possible new item types that will be shown in the combo box. - /// - /// If the second value (i.e., CollectionControl.NewItemTypes) is not null, this list will be used. - /// Otherwise, if the first value (i.e., CollectionControl.ItemsSourceType) is a "IList<T>" - /// type, the new item type list will contain "T". - /// - /// - public class NewItemTypesComboBoxConverter : IMultiValueConverter - { - public object Convert( object[] values, Type targetType, object parameter, CultureInfo culture ) - { - - if( values.Length != 2 ) - throw new ArgumentException("The 'values' argument should contain 2 objects."); - - if( values[ 1 ] != null ) - { - if( !values[ 1 ].GetType().IsGenericType || !(values[ 1 ].GetType().GetGenericArguments().First().GetType() is Type) ) - throw new ArgumentException( "The 'value' argument is not of the correct type." ); - - return values[ 1 ]; - } - else if( values[ 0 ] != null ) - { - if( !( values[ 0 ].GetType() is Type ) ) - throw new ArgumentException( "The 'value' argument is not of the correct type." ); - - List types = new List(); - Type listType = ListUtilities.GetListItemType( ( Type )values[ 0 ] ); - if( listType != null ) - { - types.Add( listType ); - } - - return types; - } - - return null; - } - - public object[] ConvertBack( object value, Type[] targetTypes, object parameter, CultureInfo culture ) - { - throw new NotImplementedException(); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/ItemAddingEventArgs.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/ItemAddingEventArgs.cs deleted file mode 100644 index 85ae0dc7..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/ItemAddingEventArgs.cs +++ /dev/null @@ -1,52 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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 Xceed.Wpf.Toolkit.Core; -using System.Windows; - -namespace Xceed.Wpf.Toolkit -{ - public class ItemAddingEventArgs : CancelRoutedEventArgs - { - #region Constructor - - public ItemAddingEventArgs( RoutedEvent itemAddingEvent, object itemAdding ) - : base( itemAddingEvent ) - { - Item = itemAdding; - } - - #endregion - - #region Properties - - #region Item Property - - public object Item - { - get; - set; - } - - #endregion - - #endregion //Properties - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/ItemDeletingEventArgs.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/ItemDeletingEventArgs.cs deleted file mode 100644 index 0e6df660..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/ItemDeletingEventArgs.cs +++ /dev/null @@ -1,56 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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 Xceed.Wpf.Toolkit.Core; -using System.Windows; - -namespace Xceed.Wpf.Toolkit -{ - public class ItemDeletingEventArgs : CancelRoutedEventArgs - { - #region Private Members - - private object _item; - - #endregion - - #region Constructor - - public ItemDeletingEventArgs( RoutedEvent itemDeletingEvent, object itemDeleting ) - : base( itemDeletingEvent ) - { - _item = itemDeleting; - } - - #region Property Item - - public object Item - { - get - { - return _item; - } - } - - #endregion - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/ItemEventArgs.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/ItemEventArgs.cs deleted file mode 100644 index 43adf0bf..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/ItemEventArgs.cs +++ /dev/null @@ -1,55 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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 -{ - public class ItemEventArgs : RoutedEventArgs - { - #region Protected Members - - private object _item; - - #endregion - - #region Constructor - - internal ItemEventArgs( RoutedEvent routedEvent, object newItem ) - : base( routedEvent ) - { - _item = newItem; - } - - #endregion - - #region Property Item - - public object Item - { - get - { - return _item; - } - } - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/PrimitiveTypeCollectionControl.Icon.bmp b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/PrimitiveTypeCollectionControl.Icon.bmp deleted file mode 100644 index 76f9520f..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/PrimitiveTypeCollectionControl.Icon.bmp and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/PrimitiveTypeCollectionControl.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/PrimitiveTypeCollectionControl.cs deleted file mode 100644 index 557f1500..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Implementation/PrimitiveTypeCollectionControl.cs +++ /dev/null @@ -1,314 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; -using System.Text; -using System.Windows; -using System.Windows.Controls; - -namespace Xceed.Wpf.Toolkit -{ - public class PrimitiveTypeCollectionControl : ContentControl - { - #region Members - - bool _surpressTextChanged; - bool _conversionFailed; - - #endregion //Members - - #region Properties - - #region IsOpen - - public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register( "IsOpen", typeof( bool ), typeof( PrimitiveTypeCollectionControl ), new UIPropertyMetadata( false, OnIsOpenChanged ) ); - public bool IsOpen - { - get - { - return ( bool )GetValue( IsOpenProperty ); - } - set - { - SetValue( IsOpenProperty, value ); - } - } - - private static void OnIsOpenChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PrimitiveTypeCollectionControl primitiveTypeCollectionControl = o as PrimitiveTypeCollectionControl; - if( primitiveTypeCollectionControl != null ) - primitiveTypeCollectionControl.OnIsOpenChanged( ( bool )e.OldValue, ( bool )e.NewValue ); - } - - protected virtual void OnIsOpenChanged( bool oldValue, bool newValue ) - { - - } - - #endregion //IsOpen - - #region ItemsSource - - public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register( "ItemsSource", typeof( IList ), typeof( PrimitiveTypeCollectionControl ), new UIPropertyMetadata( null, OnItemsSourceChanged ) ); - public IList ItemsSource - { - get - { - return ( IList )GetValue( ItemsSourceProperty ); - } - set - { - SetValue( ItemsSourceProperty, value ); - } - } - - private static void OnItemsSourceChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PrimitiveTypeCollectionControl primitiveTypeCollectionControl = o as PrimitiveTypeCollectionControl; - if( primitiveTypeCollectionControl != null ) - primitiveTypeCollectionControl.OnItemsSourceChanged( ( IList )e.OldValue, ( IList )e.NewValue ); - } - - protected virtual void OnItemsSourceChanged( IList oldValue, IList newValue ) - { - if( newValue == null ) - return; - - if( ItemsSourceType == null ) - ItemsSourceType = newValue.GetType(); - - if( ItemType == null && newValue.GetType().ContainsGenericParameters ) - ItemType = newValue.GetType().GetGenericArguments()[ 0 ]; - - SetText( newValue ); - } - - #endregion //ItemsSource - - #region IsReadOnly - - public static readonly DependencyProperty IsReadOnlyProperty = - DependencyProperty.Register( "IsReadOnly", typeof( bool ), typeof( PrimitiveTypeCollectionControl ), new UIPropertyMetadata( false ) ); - - public bool IsReadOnly - { - get { return ( bool )GetValue( IsReadOnlyProperty ); } - set { SetValue( IsReadOnlyProperty, value ); } - } - - #endregion //IsReadOnly - - #region ItemsSourceType - - public static readonly DependencyProperty ItemsSourceTypeProperty = DependencyProperty.Register( "ItemsSourceType", typeof( Type ), typeof( PrimitiveTypeCollectionControl ), new UIPropertyMetadata( null ) ); - public Type ItemsSourceType - { - get - { - return ( Type )GetValue( ItemsSourceTypeProperty ); - } - set - { - SetValue( ItemsSourceTypeProperty, value ); - } - } - - #endregion ItemsSourceType - - #region ItemType - - public static readonly DependencyProperty ItemTypeProperty = DependencyProperty.Register( "ItemType", typeof( Type ), typeof( PrimitiveTypeCollectionControl ), new UIPropertyMetadata( null ) ); - public Type ItemType - { - get - { - return ( Type )GetValue( ItemTypeProperty ); - } - set - { - SetValue( ItemTypeProperty, value ); - } - } - - #endregion ItemType - - #region Text - - public static readonly DependencyProperty TextProperty = DependencyProperty.Register( "Text", typeof( string ), typeof( PrimitiveTypeCollectionControl ), new UIPropertyMetadata( null, OnTextChanged ) ); - public string Text - { - get - { - return ( string )GetValue( TextProperty ); - } - set - { - SetValue( TextProperty, value ); - } - } - - private static void OnTextChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PrimitiveTypeCollectionControl primitiveTypeCollectionControl = o as PrimitiveTypeCollectionControl; - if( primitiveTypeCollectionControl != null ) - primitiveTypeCollectionControl.OnTextChanged( ( string )e.OldValue, ( string )e.NewValue ); - } - - protected virtual void OnTextChanged( string oldValue, string newValue ) - { - if( !_surpressTextChanged ) - PersistChanges(); - } - - #endregion //Text - - #endregion //Properties - - #region Constructors - - static PrimitiveTypeCollectionControl() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PrimitiveTypeCollectionControl ), new FrameworkPropertyMetadata( typeof( PrimitiveTypeCollectionControl ) ) ); - } - - public PrimitiveTypeCollectionControl() - { - } - - #endregion //Constructors - - #region Overrides - - -#endregion - - #region Methods - - private void PersistChanges() - { - IList list = ComputeItemsSource(); - if( list == null ) - return; - - IList items = ComputeItems(); - - //the easiest way to persist changes to the source is to just clear the source list and then add all items to it. - list.Clear(); - - int counter = 0; - foreach( var item in items ) - { - if( list is Array ) - { - ( ( Array )list ).SetValue( item, counter++); - } - else - { - list.Add( item ); - } - }; - - // if something went wrong during conversion we want to reload the text to show only valid entries - if( _conversionFailed ) - SetText( list ); - } - - private IList ComputeItems() - { - IList items = new List(); - - if( ItemType == null ) - return items; - - string[] textArray = Text.Split( '\n' ); - - foreach( string s in textArray ) - { - string valueString = s.TrimEnd( '\r' ); - if( !String.IsNullOrEmpty( valueString ) ) - { - object value = null; - try - { - if( ItemType.IsEnum ) - { - value = Enum.Parse( ItemType, valueString ); - } - else - { - value = Convert.ChangeType( valueString, ItemType ); - } - } - catch - { - //a conversion failed - _conversionFailed = true; - } - - if( value != null ) - items.Add( value ); - } - } - - return items; - } - - private IList ComputeItemsSource() - { - if( ItemsSource == null ) - { - // Save current text since creating the ItemsSource will reset it - string currentText = this.Text; - ItemsSource = CreateItemsSource(); - this.Text = currentText; - } - - return ItemsSource; - } - - private IList CreateItemsSource() - { - IList list = null; - - if( ItemsSourceType != null ) - { - ConstructorInfo constructor = ItemsSourceType.GetConstructor( Type.EmptyTypes ); - list = ( IList )constructor.Invoke( null ); - } - - return list; - } - - private void SetText( IEnumerable collection ) - { - _surpressTextChanged = true; - StringBuilder builder = new StringBuilder(); - foreach( object obj2 in collection ) - { - builder.Append( obj2.ToString() ); - builder.AppendLine(); - } - Text = builder.ToString().Trim(); - _surpressTextChanged = false; - } - - #endregion //Methods - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Themes/Aero2.NormalColor.xaml b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Themes/Aero2.NormalColor.xaml deleted file mode 100644 index 9ac26f02..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/CollectionControl/Themes/Aero2.NormalColor.xaml +++ /dev/null @@ -1,334 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/MessageBox/Themes/Generic.xaml b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/MessageBox/Themes/Generic.xaml deleted file mode 100644 index a8d2e712..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/MessageBox/Themes/Generic.xaml +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Primitives/WindowContainer.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Primitives/WindowContainer.cs index 5646214a..d0f93fd9 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Primitives/WindowContainer.cs +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Primitives/WindowContainer.cs @@ -15,437 +15,419 @@ ***********************************************************************************/ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Windows.Controls; using System.Windows; -using System.ComponentModel; +using System.Windows.Controls; using System.Windows.Input; -using System.Windows.Controls.Primitives; using System.Windows.Media; -using Xceed.Wpf.Toolkit.Core; namespace Xceed.Wpf.Toolkit.Primitives { - public class WindowContainer : Canvas - { - #region Constructors - - static WindowContainer() + public class WindowContainer : Canvas { - // The default background must be transparent in order to be able to trap - // all mouse events when a modal window is displayed. - var defaultModalBackgroundBrush = new SolidColorBrush( Colors.Transparent ); - defaultModalBackgroundBrush.Freeze(); - ModalBackgroundBrushProperty = DependencyProperty.Register( "ModalBackgroundBrush", typeof( Brush ), typeof( WindowContainer ), new UIPropertyMetadata( defaultModalBackgroundBrush, OnModalBackgroundBrushChanged ) ); - } + #region Constructors + static WindowContainer() + { + // The default background must be transparent in order to be able to trap + // all mouse events when a modal window is displayed. + var defaultModalBackgroundBrush = new SolidColorBrush(Colors.Transparent); + defaultModalBackgroundBrush.Freeze(); + ModalBackgroundBrushProperty = DependencyProperty.Register("ModalBackgroundBrush", typeof(Brush), typeof(WindowContainer), new UIPropertyMetadata(defaultModalBackgroundBrush, OnModalBackgroundBrushChanged)); + } - public WindowContainer() - { - this.SizeChanged += new SizeChangedEventHandler( this.WindowContainer_SizeChanged ); - this.LayoutUpdated += new EventHandler( this.WindowContainer_LayoutUpdated ); - this.Loaded += new RoutedEventHandler( WindowContainer_Loaded ); - this.ClipToBounds = true; - } - void WindowContainer_Loaded( object sender, RoutedEventArgs e ) - { - foreach( WindowControl window in this.Children ) - { - window.SetIsActiveInternal( false ); - } - this.SetNextActiveWindow( null ); - } + public WindowContainer() + { + this.SizeChanged += new SizeChangedEventHandler(this.WindowContainer_SizeChanged); + this.LayoutUpdated += new EventHandler(this.WindowContainer_LayoutUpdated); + this.Loaded += new RoutedEventHandler(WindowContainer_Loaded); + this.ClipToBounds = true; + } - #endregion //Constructors + void WindowContainer_Loaded(object sender, RoutedEventArgs e) + { + foreach (WindowControl window in this.Children) + { + window.SetIsActiveInternal(false); + } + this.SetNextActiveWindow(null); + } - #region Members + #endregion //Constructors - private Brush _defaultBackgroundBrush; - private bool _isModalBackgroundApplied; + #region Members - #endregion + private Brush _defaultBackgroundBrush; + private bool _isModalBackgroundApplied; - #region Properties + #endregion - #region ModalBackgroundBrush + #region Properties - /// - /// Identifies the ModalBackgroundBrush dependency property. - /// - // Initialized in the static constructor. - public static readonly DependencyProperty ModalBackgroundBrushProperty; + #region ModalBackgroundBrush - /// - /// When using a modal window in the WindowContainer, a ModalBackgroundBrush can be set - /// for the WindowContainer. - /// - public Brush ModalBackgroundBrush - { - get - { - return ( Brush )GetValue( ModalBackgroundBrushProperty ); - } - set - { - SetValue( ModalBackgroundBrushProperty, value ); - } - } + /// + /// Identifies the ModalBackgroundBrush dependency property. + /// + // Initialized in the static constructor. + public static readonly DependencyProperty ModalBackgroundBrushProperty; - private static void OnModalBackgroundBrushChanged( DependencyObject d, DependencyPropertyChangedEventArgs e ) - { - WindowContainer windowContainer = ( WindowContainer )d; - if( windowContainer != null ) - windowContainer.OnModalBackgroundBrushChanged( ( Brush )e.OldValue, ( Brush )e.NewValue ); - } + /// + /// When using a modal window in the WindowContainer, a ModalBackgroundBrush can be set + /// for the WindowContainer. + /// + public Brush ModalBackgroundBrush + { + get + { + return (Brush)GetValue(ModalBackgroundBrushProperty); + } + set + { + SetValue(ModalBackgroundBrushProperty, value); + } + } - protected virtual void OnModalBackgroundBrushChanged( Brush oldValue, Brush newValue ) - { - this.SetModalBackground(); - } + private static void OnModalBackgroundBrushChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + WindowContainer windowContainer = (WindowContainer)d; + if (windowContainer != null) + windowContainer.OnModalBackgroundBrushChanged((Brush)e.OldValue, (Brush)e.NewValue); + } - #endregion //ModalBackgroundBrush + protected virtual void OnModalBackgroundBrushChanged(Brush oldValue, Brush newValue) + { + this.SetModalBackground(); + } - #endregion + #endregion //ModalBackgroundBrush - #region Base Class Override + #endregion - /// - /// Measure the size of the WindowContainer based on its children. - /// - protected override Size MeasureOverride( Size constraint ) - { - Size size = base.MeasureOverride( constraint ); - - if( this.Children.Count > 0 ) - { - double width = double.IsNaN( this.Width ) - ? this.Children.OfType().Max( ( w ) => w.Left + w.DesiredSize.Width ) - : this.Width; - double height = double.IsNaN( this.Height ) - ? this.Children.OfType().Max( ( w ) => w.Top + w.DesiredSize.Height ) - : this.Height; - return new Size( Math.Min( width, constraint.Width), Math.Min( height, constraint.Height) ); - } - - return size; - } + #region Base Class Override - /// - /// Register and unregister to children events. - /// - protected override void OnVisualChildrenChanged( DependencyObject visualAdded, DependencyObject visualRemoved ) - { - base.OnVisualChildrenChanged( visualAdded, visualRemoved ); - - if( visualAdded != null && !( visualAdded is WindowControl ) ) - throw new InvalidOperationException( "WindowContainer can only contain WindowControl types." ); - - if( visualRemoved != null ) - { - WindowControl removedChild = ( WindowControl )visualRemoved; - removedChild.LeftChanged -= new EventHandler( this.Child_LeftChanged ); - removedChild.TopChanged -= new EventHandler( this.Child_TopChanged ); - removedChild.PreviewMouseLeftButtonDown -= new MouseButtonEventHandler( this.Child_PreviewMouseLeftButtonDown ); - removedChild.IsVisibleChanged -= new DependencyPropertyChangedEventHandler( this.Child_IsVisibleChanged ); - removedChild.IsKeyboardFocusWithinChanged -= new DependencyPropertyChangedEventHandler( this.Child_IsKeyboardFocusWithinChanged ); - if( removedChild is ChildWindow ) + /// + /// Measure the size of the WindowContainer based on its children. + /// + protected override Size MeasureOverride(Size constraint) { - ( ( ChildWindow )removedChild ).IsModalChanged -= new EventHandler( this.Child_IsModalChanged ); + Size size = base.MeasureOverride(constraint); + + if (this.Children.Count > 0) + { + double width = double.IsNaN(this.Width) + ? this.Children.OfType().Max((w) => w.Left + w.DesiredSize.Width) + : this.Width; + double height = double.IsNaN(this.Height) + ? this.Children.OfType().Max((w) => w.Top + w.DesiredSize.Height) + : this.Height; + return new Size(Math.Min(width, constraint.Width), Math.Min(height, constraint.Height)); + } + + return size; } - } - - if( visualAdded != null ) - { - WindowControl addedChild = ( WindowControl )visualAdded; - addedChild.LeftChanged += new EventHandler( this.Child_LeftChanged ); - addedChild.TopChanged += new EventHandler( this.Child_TopChanged ); - addedChild.PreviewMouseLeftButtonDown += new MouseButtonEventHandler( this.Child_PreviewMouseLeftButtonDown ); - addedChild.IsVisibleChanged += new DependencyPropertyChangedEventHandler( this.Child_IsVisibleChanged ); - addedChild.IsKeyboardFocusWithinChanged += new DependencyPropertyChangedEventHandler( this.Child_IsKeyboardFocusWithinChanged ); - if( addedChild is ChildWindow ) + + /// + /// Register and unregister to children events. + /// + protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved) { - ( ( ChildWindow )addedChild ).IsModalChanged += new EventHandler( this.Child_IsModalChanged ); + base.OnVisualChildrenChanged(visualAdded, visualRemoved); + + if (visualAdded != null && !(visualAdded is WindowControl)) + throw new InvalidOperationException("WindowContainer can only contain WindowControl types."); + + if (visualRemoved != null) + { + WindowControl removedChild = (WindowControl)visualRemoved; + removedChild.LeftChanged -= new EventHandler(this.Child_LeftChanged); + removedChild.TopChanged -= new EventHandler(this.Child_TopChanged); + removedChild.PreviewMouseLeftButtonDown -= new MouseButtonEventHandler(this.Child_PreviewMouseLeftButtonDown); + removedChild.IsVisibleChanged -= new DependencyPropertyChangedEventHandler(this.Child_IsVisibleChanged); + removedChild.IsKeyboardFocusWithinChanged -= new DependencyPropertyChangedEventHandler(this.Child_IsKeyboardFocusWithinChanged); + if (removedChild is ChildWindow) + { + ((ChildWindow)removedChild).IsModalChanged -= new EventHandler(this.Child_IsModalChanged); + } + } + + if (visualAdded != null) + { + WindowControl addedChild = (WindowControl)visualAdded; + addedChild.LeftChanged += new EventHandler(this.Child_LeftChanged); + addedChild.TopChanged += new EventHandler(this.Child_TopChanged); + addedChild.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.Child_PreviewMouseLeftButtonDown); + addedChild.IsVisibleChanged += new DependencyPropertyChangedEventHandler(this.Child_IsVisibleChanged); + addedChild.IsKeyboardFocusWithinChanged += new DependencyPropertyChangedEventHandler(this.Child_IsKeyboardFocusWithinChanged); + if (addedChild is ChildWindow) + { + ((ChildWindow)addedChild).IsModalChanged += new EventHandler(this.Child_IsModalChanged); + } + } } - } - } - - #endregion - #region Event Handler + #endregion + #region Event Handler - private void Child_LeftChanged( object sender, EventArgs e ) - { - WindowControl windowControl = ( WindowControl )sender; - if( windowControl != null ) - { - windowControl.Left = this.GetRestrictedLeft( windowControl ); - } - Canvas.SetLeft( windowControl, windowControl.Left ); - } - - private void Child_TopChanged( object sender, EventArgs e ) - { - WindowControl windowControl = ( WindowControl )sender; - if( windowControl != null ) - { - windowControl.Top = this.GetRestrictedTop( windowControl ); - } - - Canvas.SetTop( windowControl, windowControl.Top ); - } + private void Child_LeftChanged(object sender, EventArgs e) + { + WindowControl windowControl = (WindowControl)sender; + if (windowControl != null) + { + windowControl.Left = this.GetRestrictedLeft(windowControl); + } - private void Child_PreviewMouseLeftButtonDown( object sender, RoutedEventArgs e ) - { - WindowControl windowControl = ( WindowControl )sender; + Canvas.SetLeft(windowControl, windowControl.Left); + } - WindowControl modalWindow = this.GetModalWindow(); - if( modalWindow == null ) - { - this.SetNextActiveWindow( windowControl ); - } - } + private void Child_TopChanged(object sender, EventArgs e) + { + WindowControl windowControl = (WindowControl)sender; + if (windowControl != null) + { + windowControl.Top = this.GetRestrictedTop(windowControl); + } - private void Child_IsModalChanged( object sender, EventArgs e ) - { - this.SetModalBackground(); - } + Canvas.SetTop(windowControl, windowControl.Top); + } - private void Child_IsVisibleChanged( object sender, DependencyPropertyChangedEventArgs e ) - { - WindowControl windowControl = ( WindowControl )sender; - - //Do not give access to data behind the WindowContainer as long as any child of WindowContainer is visible. - WindowControl firstVisibleChild = this.Children.OfType().FirstOrDefault( ( x ) => x.Visibility == Visibility.Visible ); - this.IsHitTestVisible = ( firstVisibleChild != null ); - - if( ( bool )e.NewValue ) - { - this.SetChildPos( windowControl ); - this.SetNextActiveWindow( windowControl ); - } - else - { - this.SetNextActiveWindow( null ); - } - - WindowControl modalWindow = this.GetModalWindow(); - foreach( WindowControl window in this.Children ) - { - window.IsBlockMouseInputsPanelActive = ( modalWindow != null ) && !object.Equals( modalWindow, window ); - } - - this.SetModalBackground(); - } + private void Child_PreviewMouseLeftButtonDown(object sender, RoutedEventArgs e) + { + WindowControl windowControl = (WindowControl)sender; - private void Child_IsKeyboardFocusWithinChanged( object sender, DependencyPropertyChangedEventArgs e ) - { - WindowControl windowControl = ( WindowControl )sender; - if( ( bool )e.NewValue ) - { - this.SetNextActiveWindow( windowControl ); - } - } + WindowControl modalWindow = this.GetModalWindow(); + if (modalWindow == null) + { + this.SetNextActiveWindow(windowControl); + } + } - private void WindowContainer_LayoutUpdated( object sender, EventArgs e ) - { - foreach( WindowControl windowControl in this.Children ) - { - //we only want to set the start position if this is the first time the control has bee initialized - if( !windowControl.IsStartupPositionInitialized && ( windowControl.ActualWidth != 0 ) && ( windowControl.ActualHeight != 0 ) ) + private void Child_IsModalChanged(object sender, EventArgs e) { - this.SetChildPos( windowControl ); - windowControl.IsStartupPositionInitialized = true; + this.SetModalBackground(); } - } - } - private void WindowContainer_SizeChanged( object sender, SizeChangedEventArgs e ) - { - foreach( WindowControl windowControl in this.Children ) - { - //reposition our windows - windowControl.Left = this.GetRestrictedLeft( windowControl ); - windowControl.Top = this.GetRestrictedTop( windowControl ); - } - } + private void Child_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) + { + WindowControl windowControl = (WindowControl)sender; + + //Do not give access to data behind the WindowContainer as long as any child of WindowContainer is visible. + WindowControl firstVisibleChild = this.Children.OfType().FirstOrDefault((x) => x.Visibility == Visibility.Visible); + this.IsHitTestVisible = (firstVisibleChild != null); + + if ((bool)e.NewValue) + { + this.SetChildPos(windowControl); + this.SetNextActiveWindow(windowControl); + } + else + { + this.SetNextActiveWindow(null); + } + + WindowControl modalWindow = this.GetModalWindow(); + foreach (WindowControl window in this.Children) + { + window.IsBlockMouseInputsPanelActive = (modalWindow != null) && !object.Equals(modalWindow, window); + } + + this.SetModalBackground(); + } - private void ExpandWindowControl( WindowControl windowControl ) - { - if( windowControl != null ) - { - windowControl.Left = 0; - windowControl.Top = 0; - windowControl.Width = Math.Min( this.ActualWidth, windowControl.MaxWidth ); - windowControl.Height = Math.Min( this.ActualHeight, windowControl.MaxHeight ); - } - } + private void Child_IsKeyboardFocusWithinChanged(object sender, DependencyPropertyChangedEventArgs e) + { + WindowControl windowControl = (WindowControl)sender; + if ((bool)e.NewValue) + { + this.SetNextActiveWindow(windowControl); + } + } - #endregion + private void WindowContainer_LayoutUpdated(object sender, EventArgs e) + { + foreach (WindowControl windowControl in this.Children) + { + //we only want to set the start position if this is the first time the control has bee initialized + if (!windowControl.IsStartupPositionInitialized && (windowControl.ActualWidth != 0) && (windowControl.ActualHeight != 0)) + { + this.SetChildPos(windowControl); + windowControl.IsStartupPositionInitialized = true; + } + } + } - #region Private Methods + private void WindowContainer_SizeChanged(object sender, SizeChangedEventArgs e) + { + foreach (WindowControl windowControl in this.Children) + { + //reposition our windows + windowControl.Left = this.GetRestrictedLeft(windowControl); + windowControl.Top = this.GetRestrictedTop(windowControl); + } + } - private void SetChildPos( WindowControl windowControl ) - { - // A MessageBox with no X and Y will be centered. - // A ChildWindow with WindowStartupLocation == Center will be centered. - if( ( ( windowControl is MessageBox ) && ( windowControl.Left == 0 ) && ( windowControl.Top == 0 ) ) - || ( ( windowControl is ChildWindow ) && ( ( ( ChildWindow )windowControl ).WindowStartupLocation == WindowStartupLocation.Center ) ) ) - { - this.CenterChild( windowControl ); - } - else - { - Canvas.SetLeft( windowControl, windowControl.Left ); - Canvas.SetTop( windowControl, windowControl.Top ); - } - } + #endregion - private void CenterChild( WindowControl windowControl ) - { - windowControl.UpdateLayout(); - - if( ( windowControl.ActualWidth != 0 ) && ( windowControl.ActualHeight != 0 ) ) - { - windowControl.Left = ( this.ActualWidth - windowControl.ActualWidth ) / 2.0; - windowControl.Left += (windowControl.Margin.Left - windowControl.Margin.Right); - windowControl.Top = ( this.ActualHeight - windowControl.ActualHeight ) / 2.0; - windowControl.Top += ( windowControl.Margin.Top - windowControl.Margin.Bottom ); - } - } + #region Private Methods - private void SetNextActiveWindow( WindowControl windowControl ) - { - if( !this.IsLoaded ) - return; - - if( this.IsModalWindow( windowControl ) ) - { - this.BringToFront( windowControl ); - } - else - { - WindowControl modalWindow = this.GetModalWindow(); - // Modal window is always in front - if( modalWindow != null ) + private void SetChildPos(WindowControl windowControl) { - this.BringToFront( modalWindow ); + // A MessageBox with no X and Y will be centered. + // A ChildWindow with WindowStartupLocation == Center will be centered. + if (((windowControl is ChildWindow) && (((ChildWindow)windowControl).WindowStartupLocation == WindowStartupLocation.Center))) + { + this.CenterChild(windowControl); + } + else + { + Canvas.SetLeft(windowControl, windowControl.Left); + Canvas.SetTop(windowControl, windowControl.Top); + } } - else if( windowControl != null ) + + private void CenterChild(WindowControl windowControl) { - this.BringToFront( windowControl ); + windowControl.UpdateLayout(); + + if ((windowControl.ActualWidth != 0) && (windowControl.ActualHeight != 0)) + { + windowControl.Left = (this.ActualWidth - windowControl.ActualWidth) / 2.0; + windowControl.Left += (windowControl.Margin.Left - windowControl.Margin.Right); + windowControl.Top = (this.ActualHeight - windowControl.ActualHeight) / 2.0; + windowControl.Top += (windowControl.Margin.Top - windowControl.Margin.Bottom); + } } - else + + private void SetNextActiveWindow(WindowControl windowControl) { - this.BringToFront( this.Children.OfType() - .OrderByDescending( ( x ) => Canvas.GetZIndex( x ) ) - .FirstOrDefault( ( x ) => x.Visibility == Visibility.Visible ) ); + if (!this.IsLoaded) + return; + + if (this.IsModalWindow(windowControl)) + { + this.BringToFront(windowControl); + } + else + { + WindowControl modalWindow = this.GetModalWindow(); + // Modal window is always in front + if (modalWindow != null) + { + this.BringToFront(modalWindow); + } + else if (windowControl != null) + { + this.BringToFront(windowControl); + } + else + { + this.BringToFront(this.Children.OfType() + .OrderByDescending((x) => Canvas.GetZIndex(x)) + .FirstOrDefault((x) => x.Visibility == Visibility.Visible)); + } + } } - } - } - - private void BringToFront( WindowControl windowControl ) - { - if( windowControl != null ) - { - int maxZIndez = this.Children.OfType().Max( ( x ) => Canvas.GetZIndex( x ) ); - Canvas.SetZIndex( windowControl, maxZIndez + 1 ); - this.SetActiveWindow( windowControl ); - } - } + private void BringToFront(WindowControl windowControl) + { + if (windowControl != null) + { + int maxZIndez = this.Children.OfType().Max((x) => Canvas.GetZIndex(x)); + Canvas.SetZIndex(windowControl, maxZIndez + 1); - private void SetActiveWindow( WindowControl windowControl ) - { - if( windowControl.IsActive ) - return; - - foreach( WindowControl window in this.Children ) - { - window.SetIsActiveInternal( false ); - } - windowControl.SetIsActiveInternal( true ); - } + this.SetActiveWindow(windowControl); + } + } - private bool IsModalWindow( WindowControl windowControl ) - { - return ( ( ( windowControl is MessageBox ) && (windowControl.Visibility == Visibility.Visible) ) - || ( ( windowControl is ChildWindow ) && ( ( ChildWindow )windowControl ).IsModal && ( ( ChildWindow )windowControl).WindowState == WindowState.Open ) ); - } + private void SetActiveWindow(WindowControl windowControl) + { + if (windowControl.IsActive) + return; + + foreach (WindowControl window in this.Children) + { + window.SetIsActiveInternal(false); + } + windowControl.SetIsActiveInternal(true); + } - private WindowControl GetModalWindow() - { - return this.Children.OfType() - .OrderByDescending( ( x ) => Canvas.GetZIndex( x ) ) - .FirstOrDefault( ( x ) => IsModalWindow( x ) && (x.Visibility == Visibility.Visible) ); - } + private bool IsModalWindow(WindowControl windowControl) + { + return (((windowControl is ChildWindow) && ((ChildWindow)windowControl).IsModal && ((ChildWindow)windowControl).WindowState == WindowState.Open)); + } - private double GetRestrictedLeft( WindowControl windowControl ) - { - if( windowControl.Left < 0 ) - return 0; + private WindowControl GetModalWindow() + { + return this.Children.OfType() + .OrderByDescending((x) => Canvas.GetZIndex(x)) + .FirstOrDefault((x) => IsModalWindow(x) && (x.Visibility == Visibility.Visible)); + } - if( ( ( windowControl.Left + windowControl.ActualWidth ) > this.ActualWidth ) && ( this.ActualWidth != 0 ) ) - { - double x = this.ActualWidth - windowControl.ActualWidth; - return x < 0 ? 0 : x; - } + private double GetRestrictedLeft(WindowControl windowControl) + { + if (windowControl.Left < 0) + return 0; - return windowControl.Left; - } + if (((windowControl.Left + windowControl.ActualWidth) > this.ActualWidth) && (this.ActualWidth != 0)) + { + double x = this.ActualWidth - windowControl.ActualWidth; + return x < 0 ? 0 : x; + } - private double GetRestrictedTop( WindowControl windowControl ) - { - if( windowControl.Top < 0 ) - return 0; + return windowControl.Left; + } - if( ( ( windowControl.Top + windowControl.ActualHeight ) > this.ActualHeight ) && ( this.ActualHeight != 0 ) ) - { - double y = this.ActualHeight - windowControl.ActualHeight; - return y < 0 ? 0 : y; - } + private double GetRestrictedTop(WindowControl windowControl) + { + if (windowControl.Top < 0) + return 0; - return windowControl.Top; - } + if (((windowControl.Top + windowControl.ActualHeight) > this.ActualHeight) && (this.ActualHeight != 0)) + { + double y = this.ActualHeight - windowControl.ActualHeight; + return y < 0 ? 0 : y; + } - private void SetModalBackground() - { - // We have a modal window and a ModalBackgroundBrush set. - if( ( this.GetModalWindow() != null ) && ( this.ModalBackgroundBrush != null ) ) - { - if( !_isModalBackgroundApplied ) - { - _defaultBackgroundBrush = this.Background; - _isModalBackgroundApplied = true; + return windowControl.Top; } - this.Background = this.ModalBackgroundBrush; - - } - else - { - if( _isModalBackgroundApplied ) + private void SetModalBackground() { - this.Background = _defaultBackgroundBrush; - _defaultBackgroundBrush = null; - _isModalBackgroundApplied = false; + // We have a modal window and a ModalBackgroundBrush set. + if ((this.GetModalWindow() != null) && (this.ModalBackgroundBrush != null)) + { + if (!_isModalBackgroundApplied) + { + _defaultBackgroundBrush = this.Background; + _isModalBackgroundApplied = true; + } + + this.Background = this.ModalBackgroundBrush; + + } + else + { + if (_isModalBackgroundApplied) + { + this.Background = _defaultBackgroundBrush; + _defaultBackgroundBrush = null; + _isModalBackgroundApplied = false; + } + } } - } - } - #endregion - } + #endregion + } } diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Properties/AssemblyInfo.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Properties/AssemblyInfo.cs index 163472ba..8b729d17 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Properties/AssemblyInfo.cs +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Properties/AssemblyInfo.cs @@ -85,4 +85,7 @@ using System.Windows.Markup; [assembly: XmlnsDefinition("http://schemas.xceed.com/wpf/xaml/toolkit", "Xceed.Wpf.Toolkit.Zoombox")] [assembly: XmlnsDefinition("http://schemas.xceed.com/wpf/xaml/toolkit", "Xceed.Wpf.Toolkit.Panels")] - +#if NET +[assembly: System.Runtime.Versioning.TargetPlatform("Windows")] +[assembly: System.Runtime.Versioning.SupportedOSPlatform("Windows")] +#endif diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/AdvancedProperties11.png b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/AdvancedProperties11.png deleted file mode 100644 index 0146e932..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/AdvancedProperties11.png and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Categorize16.png b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Categorize16.png deleted file mode 100644 index 51510df8..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Categorize16.png and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/ClearFilter16.png b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/ClearFilter16.png deleted file mode 100644 index aeaeab8d..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/ClearFilter16.png and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Database11.png b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Database11.png deleted file mode 100644 index 0f523fbd..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Database11.png and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Inheritance11.png b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Inheritance11.png deleted file mode 100644 index 7dd3b491..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Inheritance11.png and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Local11.png b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Local11.png deleted file mode 100644 index ec521dd4..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Local11.png and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Resource11.png b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Resource11.png deleted file mode 100644 index 7275c981..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Resource11.png and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/SortAscending16.png b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/SortAscending16.png deleted file mode 100644 index b3138ba3..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/SortAscending16.png and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Style11.png b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Style11.png deleted file mode 100644 index 7a6005d6..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Images/Style11.png and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/CategoryOrderAttribute.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/CategoryOrderAttribute.cs deleted file mode 100644 index 806d9f65..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/CategoryOrderAttribute.cs +++ /dev/null @@ -1,76 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Attributes -{ - [AttributeUsage( AttributeTargets.Class, AllowMultiple = true )] - public class CategoryOrderAttribute : Attribute - { - #region Properties - - #region Order - - public int Order - { - get; - set; - } - - #endregion - - #region Category - - public virtual string Category - { - get - { - return CategoryValue; - } - } - - #endregion - - #region CategoryValue - - public string CategoryValue - { - get; - private set; - } - - #endregion - - #endregion - - #region constructor - - public CategoryOrderAttribute() - { - } - - public CategoryOrderAttribute( string categoryName, int order ) - :this() - { - CategoryValue = categoryName; - Order = order; - } - - #endregion - } -} - diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/ExpandableObjectAttribute.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/ExpandableObjectAttribute.cs deleted file mode 100644 index 4eb15152..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/ExpandableObjectAttribute.cs +++ /dev/null @@ -1,39 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Attributes -{ - public class ExpandableObjectAttribute : Attribute - { - #region Constructors - - public ExpandableObjectAttribute() - { - } - - - #endregion - - #region Properties - - - - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/IItemsSource.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/IItemsSource.cs deleted file mode 100644 index 0d7fe4ac..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/IItemsSource.cs +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Collections.Generic; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Attributes -{ - public interface IItemsSource - { - ItemCollection GetValues(); - } - - public class Item - { - public string DisplayName - { - get; - set; - } - public object Value - { - get; - set; - } - } - - public class ItemCollection : List - { - public void Add( object value ) - { - Item item = new Item(); - item.DisplayName = value.ToString(); - item.Value = value; - base.Add( item ); - } - - public void Add( object value, string displayName ) - { - Item newItem = new Item(); - newItem.DisplayName = displayName; - newItem.Value = value; - base.Add( newItem ); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/ItemsSourceAttribute.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/ItemsSourceAttribute.cs deleted file mode 100644 index 26673ffc..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/ItemsSourceAttribute.cs +++ /dev/null @@ -1,38 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Attributes -{ - public class ItemsSourceAttribute : Attribute - { - public Type Type - { - get; - set; - } - - public ItemsSourceAttribute( Type type ) - { - var valueSourceInterface = type.GetInterface( typeof( IItemsSource ).FullName ); - if( valueSourceInterface == null ) - throw new ArgumentException( "Type must implement the IItemsSource interface.", "type" ); - - Type = type; - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/NewItemTypesAttribute.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/NewItemTypesAttribute.cs deleted file mode 100644 index 16a3a13a..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/NewItemTypesAttribute.cs +++ /dev/null @@ -1,45 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Attributes -{ - /// - /// This attribute can decorate the collection properties (i.e., IList) - /// of your selected object in order to control the types that will be allowed - /// to be instantiated in the CollectionControl. - /// - [AttributeUsage( AttributeTargets.Property, AllowMultiple = false, Inherited = true )] - public class NewItemTypesAttribute : Attribute - { - public IList Types - { - get; - set; - } - - public NewItemTypesAttribute( params Type[] types ) - { - this.Types = new List( types ); - } - - public NewItemTypesAttribute() - { - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/PropertyOrderAttribute.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/PropertyOrderAttribute.cs deleted file mode 100644 index c28cd169..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Attributes/PropertyOrderAttribute.cs +++ /dev/null @@ -1,70 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Attributes -{ - public enum UsageContextEnum - { - Alphabetical, - Categorized, - Both - } - - [AttributeUsage( AttributeTargets.Property, AllowMultiple = true, Inherited = true )] - public class PropertyOrderAttribute : Attribute - { - #region Properties - - public int Order - { - get; - set; - } - - public UsageContextEnum UsageContext - { - get; - set; - } - - public override object TypeId - { - get - { - return this; - } - } - - #endregion - - #region Initialization - - public PropertyOrderAttribute( int order ) - : this( order, UsageContextEnum.Both ) - { - } - - public PropertyOrderAttribute( int order, UsageContextEnum usageContext ) - { - Order = order; - UsageContext = usageContext; - } - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/CategoryGroupStyleSelector.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/CategoryGroupStyleSelector.cs deleted file mode 100644 index 5ba0af64..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/CategoryGroupStyleSelector.cs +++ /dev/null @@ -1,65 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.ComponentModel; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Media; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - public class CategoryGroupStyleSelector : StyleSelector - { - public Style SingleDefaultCategoryItemGroupStyle - { - get; - set; - } - public Style ItemGroupStyle - { - get; - set; - } - - public override Style SelectStyle( object item, DependencyObject container ) - { - var group = item as CollectionViewGroup; - // Category is not "Misc" => use regular ItemGroupStyle - if( (group.Name != null) && !group.Name.Equals( CategoryAttribute.Default.Category ) ) - return this.ItemGroupStyle; - - // Category is "Misc" - while( container != null ) - { - container = VisualTreeHelper.GetParent( container ); - if( container is ItemsControl ) - break; - } - - var itemsControl = container as ItemsControl; - if( itemsControl != null ) - { - // Category is "Misc" and this is the only category => use SingleDefaultCategoryItemGroupContainerStyle - if( (itemsControl.Items.Count > 0) && (itemsControl.Items.Groups.Count == 1) ) - return this.SingleDefaultCategoryItemGroupStyle; - } - - // Category is "Misc" and this is NOT the only category => use regular ItemGroupStyle - return this.ItemGroupStyle; - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Commands/PropertyGridCommands.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Commands/PropertyGridCommands.cs deleted file mode 100644 index e5eedbbd..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Commands/PropertyGridCommands.cs +++ /dev/null @@ -1,32 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Windows.Input; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Commands -{ - public class PropertyGridCommands - { - private static RoutedCommand _clearFilterCommand = new RoutedCommand(); - public static RoutedCommand ClearFilter - { - get - { - return _clearFilterCommand; - } - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Commands/PropertyItemCommands.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Commands/PropertyItemCommands.cs deleted file mode 100644 index fa75a25c..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Commands/PropertyItemCommands.cs +++ /dev/null @@ -1,32 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Windows.Input; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Commands -{ - public static class PropertyItemCommands - { - private static RoutedCommand _resetValueCommand = new RoutedCommand(); - public static RoutedCommand ResetValue - { - get - { - return _resetValueCommand; - } - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/CommonPropertyExceptionValidationRule.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/CommonPropertyExceptionValidationRule.cs deleted file mode 100644 index 79ec6af1..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/CommonPropertyExceptionValidationRule.cs +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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.Controls; -using System.ComponentModel; -using Xceed.Wpf.Toolkit.Core.Utilities; -using System.Globalization; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - internal class CommonPropertyExceptionValidationRule : ValidationRule - { - private TypeConverter _propertyTypeConverter; - private Type _type; - - internal CommonPropertyExceptionValidationRule( Type type ) - { - _propertyTypeConverter = TypeDescriptor.GetConverter( type ); - _type = type; - } - - public override ValidationResult Validate( object value, CultureInfo cultureInfo ) - { - ValidationResult result = new ValidationResult( true, null ); - - if( GeneralUtilities.CanConvertValue( value, _type ) ) - { - try - { - _propertyTypeConverter.ConvertFrom( value ); - } - catch( Exception e ) - { - // Will display a red border in propertyGrid - result = new ValidationResult( false, e.Message ); - } - } - return result; - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/ContainerHelperBase.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/ContainerHelperBase.cs deleted file mode 100644 index bcc652e3..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/ContainerHelperBase.cs +++ /dev/null @@ -1,238 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Collections.Generic; -using System.Collections; -using System; -using System.Windows; -using System.ComponentModel; -using Xceed.Wpf.Toolkit.Core.Utilities; -using System.Windows.Data; -using System.Diagnostics; -using System.Windows.Controls; -using System.Windows.Controls.Primitives; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - internal abstract class ContainerHelperBase - { - protected readonly IPropertyContainer PropertyContainer; - - public ContainerHelperBase(IPropertyContainer propertyContainer) - { - if( propertyContainer == null ) - throw new ArgumentNullException( "propertyContainer" ); - - PropertyContainer = propertyContainer; - - var propChange = propertyContainer as INotifyPropertyChanged; - if( propChange != null ) - { - propChange.PropertyChanged += new PropertyChangedEventHandler( OnPropertyContainerPropertyChanged ); - } - } - - #region IsGenerated attached property - - internal static readonly DependencyProperty IsGeneratedProperty = DependencyProperty.RegisterAttached( - "IsGenerated", - typeof( bool ), - typeof( ContainerHelperBase ), - new PropertyMetadata( false ) ); - - internal static bool GetIsGenerated( DependencyObject obj ) - { - return ( bool )obj.GetValue( ContainerHelperBase.IsGeneratedProperty ); - } - - internal static void SetIsGenerated( DependencyObject obj, bool value ) - { - obj.SetValue( ContainerHelperBase.IsGeneratedProperty, value ); - } - - #endregion IsGenerated attached property - - public abstract IList Properties - { - get; - } - - internal ItemsControl ChildrenItemsControl - { - get; - set; - } - - internal bool IsCleaning - { - get; - private set; - } - - public virtual void ClearHelper() - { - this.IsCleaning = true; - - var propChange = PropertyContainer as INotifyPropertyChanged; - if( propChange != null ) - { - propChange.PropertyChanged -= new PropertyChangedEventHandler( OnPropertyContainerPropertyChanged ); - } - - // Calling RemoveAll() will force the ItemsContol displaying the - // properties to clear all the current container (i.e., ClearContainerForItem). - // This will make the call at "ClearChildrenPropertyItem" for every prepared - // container. Fortunately, the ItemsContainer will not re-prepare the items yet - // (i.e., probably made on next measure pass), allowing us to set up the new - // parent helper. - if( ChildrenItemsControl != null ) - { - ( ( IItemContainerGenerator )ChildrenItemsControl.ItemContainerGenerator ).RemoveAll(); - } - this.IsCleaning = false; - } - - public virtual void PrepareChildrenPropertyItem( PropertyItemBase propertyItem, object item ) - { - // Initialize the parent node - propertyItem.ParentNode = PropertyContainer; - - PropertyGrid.RaisePreparePropertyItemEvent( ( UIElement )PropertyContainer, propertyItem, item ); - } - - public virtual void ClearChildrenPropertyItem( PropertyItemBase propertyItem, object item ) - { - - propertyItem.ParentNode = null; - - PropertyGrid.RaiseClearPropertyItemEvent( ( UIElement )PropertyContainer, propertyItem, item ); - } - - protected FrameworkElement GenerateCustomEditingElement( Type definitionKey, PropertyItemBase propertyItem ) - { - return ( PropertyContainer.EditorDefinitions != null ) - ? this.CreateCustomEditor( PropertyContainer.EditorDefinitions.GetRecursiveBaseTypes( definitionKey ), propertyItem ) - : null; - } - - protected FrameworkElement GenerateCustomEditingElement( object definitionKey, PropertyItemBase propertyItem ) - { - return ( PropertyContainer.EditorDefinitions != null ) - ? this.CreateCustomEditor( PropertyContainer.EditorDefinitions[ definitionKey ], propertyItem ) - : null; - } - - protected FrameworkElement CreateCustomEditor( EditorDefinitionBase customEditor, PropertyItemBase propertyItem ) - { - return ( customEditor != null ) - ? customEditor.GenerateEditingElementInternal( propertyItem ) - : null; - } - - protected virtual void OnPropertyContainerPropertyChanged( object sender, PropertyChangedEventArgs e ) - { - var propertyName = e.PropertyName; - IPropertyContainer ps = null; - if( propertyName == ReflectionHelper.GetPropertyOrFieldName( () => ps.FilterInfo ) ) - { - this.OnFilterChanged(); - } - else if( propertyName == ReflectionHelper.GetPropertyOrFieldName( () => ps.IsCategorized ) ) - { - this.OnCategorizationChanged(); - } - else if( propertyName == ReflectionHelper.GetPropertyOrFieldName( () => ps.AutoGenerateProperties ) ) - { - this.OnAutoGeneratePropertiesChanged(); - } - else if( propertyName == ReflectionHelper.GetPropertyOrFieldName( () => ps.HideInheritedProperties ) ) - { - this.OnHideInheritedPropertiesChanged(); - } - else if(propertyName == ReflectionHelper.GetPropertyOrFieldName( () => ps.EditorDefinitions )) - { - this.OnEditorDefinitionsChanged(); - } - else if(propertyName == ReflectionHelper.GetPropertyOrFieldName( () => ps.PropertyDefinitions )) - { - this.OnPropertyDefinitionsChanged(); - } - } - - protected virtual void OnCategorizationChanged() { } - - protected virtual void OnFilterChanged() { } - - protected virtual void OnAutoGeneratePropertiesChanged() { } - - protected virtual void OnHideInheritedPropertiesChanged() { } - - protected virtual void OnEditorDefinitionsChanged() { } - - protected virtual void OnPropertyDefinitionsChanged() { } - - - public virtual void OnEndInit() { } - - public abstract PropertyItemBase ContainerFromItem( object item ); - - public abstract object ItemFromContainer( PropertyItemBase container ); - - public abstract Binding CreateChildrenDefaultBinding( PropertyItemBase propertyItem ); - - public virtual void NotifyEditorDefinitionsCollectionChanged() { } - public virtual void NotifyPropertyDefinitionsCollectionChanged() { } - - public abstract void UpdateValuesFromSource(); - - protected internal virtual void SetPropertiesExpansion( bool isExpanded ) - { - foreach( var item in this.Properties ) - { - var propertyItem = item as PropertyItemBase; - if( (propertyItem != null) && propertyItem.IsExpandable ) - { - if( propertyItem.ContainerHelper != null ) - { - propertyItem.ContainerHelper.SetPropertiesExpansion( isExpanded ); - } - propertyItem.IsExpanded = isExpanded; - } - } - } - - protected internal virtual void SetPropertiesExpansion( string propertyName, bool isExpanded ) - { - foreach( var item in this.Properties ) - { - var propertyItem = item as PropertyItemBase; - if( (propertyItem != null) && propertyItem.IsExpandable ) - { - if( propertyItem.DisplayName == propertyName ) - { - propertyItem.IsExpanded = isExpanded; - break; - } - - if( propertyItem.ContainerHelper != null ) - { - propertyItem.ContainerHelper.SetPropertiesExpansion( propertyName, isExpanded ); - } - } - } - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/EditorTimeSpanConverter.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/EditorTimeSpanConverter.cs deleted file mode 100644 index a4d59497..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/EditorTimeSpanConverter.cs +++ /dev/null @@ -1,52 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Globalization; -using System.Windows.Data; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Converters -{ - /// - /// Converts a TimeSpan value to a DateTime value. - /// - /// This converter can be used in conjunction with a TimePicker in order - /// to create a TimeSpan edit control. - /// - public sealed class EditorTimeSpanConverter : IValueConverter - { - public bool AllowNulls { get; set; } - - object IValueConverter.Convert( object value, Type targetType, object parameter, CultureInfo culture ) - { - if( this.AllowNulls && value == null ) - return null; - - TimeSpan timeSpan = ( value != null ) ? ( TimeSpan )value : TimeSpan.Zero; - return DateTime.Today + timeSpan; - } - - object IValueConverter.ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) - { - if( this.AllowNulls && value == null ) - return null; - - return ( value != null ) - ? ( ( DateTime )value ).TimeOfDay - : TimeSpan.Zero; - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/ExpandableObjectMarginConverter.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/ExpandableObjectMarginConverter.cs deleted file mode 100644 index e0b14558..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/ExpandableObjectMarginConverter.cs +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Windows; -using System.Windows.Data; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Converters -{ - public class ExpandableObjectMarginConverter : IValueConverter - { - public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) - { - int childLevel = ( int )value; - return new Thickness( childLevel * 15, 0, 0, 0 ); - } - - public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) - { - throw new NotImplementedException(); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/IsDefaultCategoryConverter.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/IsDefaultCategoryConverter.cs deleted file mode 100644 index a8f93645..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/IsDefaultCategoryConverter.cs +++ /dev/null @@ -1,45 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Windows.Data; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Converters -{ - public class IsDefaultCategoryConverter : IValueConverter - { - public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) - { - string categoryName = value as string; - if( categoryName != null ) - { - return ( categoryName == CategoryAttribute.Default.Category ); - } - - return false; - } - - public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) - { - throw new NotImplementedException(); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/IsStringEmptyConverter.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/IsStringEmptyConverter.cs deleted file mode 100644 index 473ee4e0..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/IsStringEmptyConverter.cs +++ /dev/null @@ -1,40 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Globalization; -using System.Windows.Data; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Converters -{ - public class IsStringEmptyConverter : IValueConverter - { - public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) - { - if( value is string ) - { - return string.IsNullOrEmpty( ( string )value ); - } - - return false; - } - - public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) - { - throw new NotImplementedException(); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/ListConverter.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/ListConverter.cs deleted file mode 100644 index 20725efd..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/ListConverter.cs +++ /dev/null @@ -1,105 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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.ComponentModel; -using System.Collections; -using System.Collections.ObjectModel; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Converters -{ - internal class ListConverter : TypeConverter - { - public override bool CanConvertFrom( ITypeDescriptorContext context, Type sourceType ) - { - return true; - } - - public override bool CanConvertTo( ITypeDescriptorContext context, Type destinationType ) - { - return ( destinationType == typeof( string ) ); - } - - public override object ConvertFrom( ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value ) - { - if( value == null ) - return null; - - string names = value as string; - - var list = new List(); - if( names == null && value != null ) - { - list.Add( value ); - } - else - { - if( names == null ) - return null; - - foreach( var name in names.Split( ',' ) ) - { - list.Add( name.Trim() ); - } - } - - return new ReadOnlyCollection( list ); - } - - public override object ConvertTo( ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType ) - { - if( destinationType != typeof( string ) ) - throw new InvalidOperationException( "Can only convert to string." ); - - - IList strs = ( IList )value; - - if( strs == null ) - return null; - - StringBuilder sb = new StringBuilder(); - bool first = true; - foreach( object o in strs ) - { - if( o == null ) - throw new InvalidOperationException( "Property names cannot be null." ); - - string s = o as string; - if( s == null ) - throw new InvalidOperationException( "Does not support serialization of non-string property names." ); - - if( s.Contains( ',' ) ) - throw new InvalidOperationException( "Property names cannot contain commas." ); - - if( s.Trim().Length != s.Length ) - throw new InvalidOperationException( "Property names cannot start or end with whitespace characters." ); - - if( !first ) - { - sb.Append( ", " ); - } - first = false; - - sb.Append( s ); - } - - return sb.ToString(); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/ObjectToUIElementConverter.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/ObjectToUIElementConverter.cs deleted file mode 100644 index f656f41c..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/ObjectToUIElementConverter.cs +++ /dev/null @@ -1,43 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Converters -{ - public class ObjectToUIElementConverter : IValueConverter - { - public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) - { - if( value is UIElement ) - return value; - - return new Control(); - } - - public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) - { - throw new NotImplementedException(); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/PropertyItemEditorConverter.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/PropertyItemEditorConverter.cs deleted file mode 100644 index 21948fbb..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/PropertyItemEditorConverter.cs +++ /dev/null @@ -1,87 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Globalization; -using System.Windows; -using System.Windows.Controls.Primitives; -using System.Windows.Data; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Converters -{ - public class PropertyItemEditorConverter : IMultiValueConverter - { - public object Convert( object[] values, Type targetType, object parameter, CultureInfo culture ) - { - if( ( values == null ) || ( values.Length != 2 ) ) - return null; - - var editor = values[ 0 ]; - var isReadOnly = values[ 1 ] as bool?; - - if( ( editor == null ) || !isReadOnly.HasValue ) - return editor; - - // Get Editor.IsReadOnly - var editorType = editor.GetType(); - var editorIsReadOnlyPropertyInfo = editorType.GetProperty( "IsReadOnly" ); - if( editorIsReadOnlyPropertyInfo != null ) - { - if( !this.IsPropertySetLocally( editor, TextBoxBase.IsReadOnlyProperty ) ) - { - // Set Editor.IsReadOnly to PropertyGrid.IsReadOnly. - editorIsReadOnlyPropertyInfo.SetValue( editor, isReadOnly, null ); - } - } - // No Editor.IsReadOnly property, set the Editor.IsEnabled property. - else - { - var editorIsEnabledPropertyInfo = editorType.GetProperty( "IsEnabled" ); - if( editorIsEnabledPropertyInfo != null ) - { - if( !this.IsPropertySetLocally( editor, UIElement.IsEnabledProperty ) ) - { - // Set Editor.IsEnabled to !PropertyGrid.IsReadOnly. - editorIsEnabledPropertyInfo.SetValue( editor, !isReadOnly, null ); - } - } - } - - return editor; - } - - public object[] ConvertBack( object value, Type[] targetTypes, object parameter, CultureInfo culture ) - { - throw new NotImplementedException(); - } - - private bool IsPropertySetLocally( object editor, DependencyProperty dp ) - { - if( dp == null ) - return false; - - var editorObject = editor as DependencyObject; - if( editorObject == null ) - return false; - - var valueSource = DependencyPropertyHelper.GetValueSource( editorObject, dp ); - if( valueSource == null ) - return false; - - return ( valueSource.BaseValueSource == BaseValueSource.Local ); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/SelectedObjectConverter.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/SelectedObjectConverter.cs deleted file mode 100644 index 73f45cd4..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Converters/SelectedObjectConverter.cs +++ /dev/null @@ -1,116 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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.Data; -using System.Globalization; -using System.ComponentModel; -using System.Windows; -using System.Reflection; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Converters -{ - public class SelectedObjectConverter : IValueConverter - { - private const string ValidParameterMessage = @"parameter must be one of the following strings: 'Type', 'TypeName', 'SelectedObjectName'"; - #region IValueConverter Members - - public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) - { - if( parameter == null ) - throw new ArgumentNullException( "parameter" ); - - if( !( parameter is string ) ) - throw new ArgumentException( SelectedObjectConverter.ValidParameterMessage ); - - if( this.CompareParam(parameter, "Type") ) - { - return this.ConvertToType( value, culture ); - } - else if( this.CompareParam( parameter, "TypeName" ) ) - { - return this.ConvertToTypeName( value, culture ); - } - else if( this.CompareParam( parameter, "SelectedObjectName" ) ) - { - return this.ConvertToSelectedObjectName( value, culture ); - } - else - { - throw new ArgumentException( SelectedObjectConverter.ValidParameterMessage ); - } - } - - private bool CompareParam(object parameter, string parameterValue ) - { - return string.Compare( ( string )parameter, parameterValue, true ) == 0; - } - - private object ConvertToType( object value, CultureInfo culture ) - { - return ( value != null ) - ? value.GetType() - : null; - } - - private object ConvertToTypeName( object value, CultureInfo culture ) - { - if( value == null ) - return string.Empty; - - Type newType = value.GetType(); - - //ICustomTypeProvider is only available in .net 4.5 and over. Use reflection so the .net 4.0 and .net 3.5 still works. - if( newType.GetInterface( "ICustomTypeProvider", true ) != null ) - { - var methodInfo = newType.GetMethod( "GetCustomType" ); - newType = methodInfo.Invoke( value, null ) as Type; - } - - DisplayNameAttribute displayNameAttribute = newType.GetCustomAttributes( false ).OfType().FirstOrDefault(); - - return (displayNameAttribute == null) - ? newType.Name - : displayNameAttribute.DisplayName; - } - - private object ConvertToSelectedObjectName( object value, CultureInfo culture ) - { - if( value == null ) - return String.Empty; - - Type newType = value.GetType(); - PropertyInfo[] properties = newType.GetProperties(); - foreach( PropertyInfo property in properties ) - { - if( property.Name == "Name" ) - return property.GetValue( value, null ); - } - - return String.Empty; - } - - public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) - { - throw new NotImplementedException(); - } - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/CustomPropertyItem.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/CustomPropertyItem.cs deleted file mode 100644 index 7118badc..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/CustomPropertyItem.cs +++ /dev/null @@ -1,182 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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; -using System.Windows.Data; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - /// - /// Used when properties are provided using a list source of items (eg. Properties or PropertiesSource). - /// - /// An instance of this class can be used as an item to easily customize the - /// display of the property directly by modifying the values of this class - /// (e.g., DisplayName, value, Category, etc.). - /// - public class CustomPropertyItem : PropertyItemBase - { - #region Constructors - - internal CustomPropertyItem() { } - - internal CustomPropertyItem( bool isPropertyGridCategorized, bool isSortedAlphabetically ) - { - _isPropertyGridCategorized = isPropertyGridCategorized; - _isSortedAlphabetically = isSortedAlphabetically; - } - - - #endregion - - #region Properties - - #region Category - - public static readonly DependencyProperty CategoryProperty = - DependencyProperty.Register( "Category", typeof( string ), typeof( CustomPropertyItem ), new UIPropertyMetadata( null ) ); - - public string Category - { - get { return ( string )GetValue( CategoryProperty ); } - set { SetValue( CategoryProperty, value ); } - } - - #endregion //Category - - #region CategoryOrder - - public int CategoryOrder - { - get - { - return _categoryOrder; - } - set - { - if( _categoryOrder != value ) - { - _categoryOrder = value; - // Notify the parent helper since this property may affect ordering. - this.RaisePropertyChanged( () => this.CategoryOrder ); - } - } - } - - private int _categoryOrder; - - #endregion //CategoryOrder - - - - - - #region PropertyOrder - - public static readonly DependencyProperty PropertyOrderProperty = - DependencyProperty.Register( "PropertyOrder", typeof( int ), typeof( CustomPropertyItem ), new UIPropertyMetadata( 0 ) ); - - public int PropertyOrder - { - get - { - return ( int )GetValue( PropertyOrderProperty ); - } - set - { - SetValue( PropertyOrderProperty, value ); - } - } - - #endregion //PropertyOrder - - #region Value - - public static readonly DependencyProperty ValueProperty = DependencyProperty.Register( "Value", typeof( object ), typeof( CustomPropertyItem ), new UIPropertyMetadata( null, OnValueChanged, OnCoerceValueChanged ) ); - public object Value - { - get - { - return ( object )GetValue( ValueProperty ); - } - set - { - SetValue( ValueProperty, value ); - } - } - - private static object OnCoerceValueChanged( DependencyObject o, object baseValue ) - { - CustomPropertyItem prop = o as CustomPropertyItem; - if( prop != null ) - return prop.OnCoerceValueChanged( baseValue ); - - return baseValue; - } - - protected virtual object OnCoerceValueChanged( object baseValue ) - { - return baseValue; - } - - private static void OnValueChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - CustomPropertyItem propertyItem = o as CustomPropertyItem; - if( propertyItem != null ) - { - propertyItem.OnValueChanged( ( object )e.OldValue, ( object )e.NewValue ); - } - } - - protected virtual void OnValueChanged( object oldValue, object newValue ) - { - if( IsInitialized ) - { - RaiseEvent( new PropertyValueChangedEventArgs( PropertyGrid.PropertyValueChangedEvent, this, oldValue, newValue ) ); - } - } - - #endregion //Value - - #endregion - - #region Overrides - - protected override Type GetPropertyItemType() - { - return this.Value.GetType(); - } - - protected override void OnEditorChanged( FrameworkElement oldValue, FrameworkElement newValue ) - { - if( oldValue != null ) - { - oldValue.DataContext = null; - } - - //case 166547 : Do not overwrite a custom Editor's DataContext set by the user. - if( ( newValue != null ) && ( newValue.DataContext == null ) ) - { - newValue.DataContext = this; - } - } - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Definitions/DefinitionBase.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Definitions/DefinitionBase.cs deleted file mode 100644 index 42ae7b13..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Definitions/DefinitionBase.cs +++ /dev/null @@ -1,64 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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( Expression> 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; - } - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Definitions/EditorDefinitionBase.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Definitions/EditorDefinitionBase.cs deleted file mode 100644 index 4ab5dd0a..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Definitions/EditorDefinitionBase.cs +++ /dev/null @@ -1,70 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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 ); - } - } - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Definitions/EditorTemplateDefinition.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Definitions/EditorTemplateDefinition.cs deleted file mode 100644 index 48a1f977..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Definitions/EditorTemplateDefinition.cs +++ /dev/null @@ -1,47 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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; - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Definitions/PropertyDefinitionBase.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Definitions/PropertyDefinitionBase.cs deleted file mode 100644 index d3145e86..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Definitions/PropertyDefinitionBase.cs +++ /dev/null @@ -1,113 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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(); - 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 newList = new List(); - 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( newList ) - : new ReadOnlyCollection( newList ) as IList; - } - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/DescriptorPropertyDefinition.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/DescriptorPropertyDefinition.cs deleted file mode 100644 index 72f90f80..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/DescriptorPropertyDefinition.cs +++ /dev/null @@ -1,267 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Linq; -using System.Windows; -using System.Windows.Data; -#if !VS2008 -using System.ComponentModel.DataAnnotations; -#endif -using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; -using Xceed.Wpf.Toolkit.PropertyGrid.Editors; -using System.Globalization; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - internal class DescriptorPropertyDefinition : DescriptorPropertyDefinitionBase - { - #region Members - - private object _selectedObject; - private PropertyDescriptor _propertyDescriptor; - private DependencyPropertyDescriptor _dpDescriptor; - private static Dictionary _dictEditorTypeName = new Dictionary(); - - #endregion - - #region Constructor - - internal DescriptorPropertyDefinition( PropertyDescriptor propertyDescriptor, object selectedObject, IPropertyContainer propertyContainer ) - : base( propertyContainer.IsCategorized - ) - { - this.Init( propertyDescriptor, selectedObject ); - } - - #endregion - - #region Custom Properties - - internal override PropertyDescriptor PropertyDescriptor - { - get - { - return _propertyDescriptor; - } - } - - private object SelectedObject - { - get - { - return _selectedObject; - } - } - - #endregion - - #region Override Methods - - internal override ObjectContainerHelperBase CreateContainerHelper( IPropertyContainer parent ) - { - return new ObjectContainerHelper( parent, this.Value ); - } - - internal override void OnValueChanged( object oldValue, object newValue ) - { - base.OnValueChanged( oldValue, newValue ); - this.RaiseContainerHelperInvalidated(); - } - - protected override BindingBase CreateValueBinding() - { - var selectedObject = this.SelectedObject; - var propertyName = this.PropertyDescriptor.Name; - - //Bind the value property with the source object. - var binding = new Binding( propertyName ) - { - Source = this.GetValueInstance( selectedObject ), - Mode = PropertyDescriptor.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay, - ValidatesOnDataErrors = true, - ValidatesOnExceptions = true, - ConverterCulture = CultureInfo.CurrentCulture - }; - - return binding; - } - - protected override bool ComputeIsReadOnly() - { - return PropertyDescriptor.IsReadOnly; - } - - internal override ITypeEditor CreateDefaultEditor( PropertyItem propertyItem ) - { - return PropertyGridUtilities.CreateDefaultEditor( PropertyDescriptor.PropertyType, PropertyDescriptor.Converter, propertyItem ); - } - - protected override bool ComputeCanResetValue() - { - if( !PropertyDescriptor.IsReadOnly ) - { - var defaultValue = this.ComputeDefaultValueAttribute(); - if( defaultValue != null) - return !defaultValue.Equals( this.Value ); // can Reset if different from defaultValue. - - return PropertyDescriptor.CanResetValue( SelectedObject ); - } - - return false; - } - - protected override object ComputeAdvancedOptionsTooltip() - { - object tooltip; - UpdateAdvanceOptionsForItem( SelectedObject as DependencyObject, _dpDescriptor, out tooltip ); - - return tooltip; - } - - protected override string ComputeCategory() - { -#if VS2008 - return PropertyDescriptor.Category; -#else - var displayAttribute = PropertyGridUtilities.GetAttribute( PropertyDescriptor ); - return ( (displayAttribute != null) && (displayAttribute.GetGroupName() != null) ) ? displayAttribute.GetGroupName() : PropertyDescriptor.Category; -#endif - } - - protected override string ComputeCategoryValue() - { - return PropertyDescriptor.Category; - } - - protected override bool ComputeExpandableAttribute() - { - return ( bool )this.ComputeExpandableAttributeForItem( PropertyDescriptor ); - } - - protected override object ComputeDefaultValueAttribute() - { - return this.ComputeDefaultValueAttributeForItem( PropertyDescriptor ); - } - - protected override bool ComputeIsExpandable() - { - return ( this.Value != null ) - ; - } - - protected override IList ComputeNewItemTypes() - { - return ( IList )ComputeNewItemTypesForItem( PropertyDescriptor ); - } - protected override string ComputeDescription() - { - return ( string )ComputeDescriptionForItem( PropertyDescriptor ); - } - - protected override int ComputeDisplayOrder( bool isPropertyGridCategorized ) - { - this.IsPropertyGridCategorized = isPropertyGridCategorized; - return ( int )ComputeDisplayOrderForItem( PropertyDescriptor ); - } - - protected override void ResetValue() - { - this.PropertyDescriptor.ResetValue( this.SelectedObject ); - base.ResetValue(); - } - - internal override ITypeEditor CreateAttributeEditor() - { - var editorAttribute = GetAttribute(); - if( editorAttribute != null ) - { - Type type = null; - if( !_dictEditorTypeName.TryGetValue( editorAttribute.EditorTypeName, out type ) ) - { -#if VS2008 - type = Type.GetType( editorAttribute.EditorTypeName ); -#else - try - { - var typeDef = editorAttribute.EditorTypeName.Split( new char[] { ',' } ); - if( typeDef.Length >= 2 ) - { - var assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault( a => a.FullName.Contains( typeDef[ 1 ].Trim() ) ); - if( assembly != null ) - { - type = assembly.GetTypes().FirstOrDefault( t => (t != null) && (t.FullName != null) && t.FullName.Contains( typeDef[ 0 ] ) ); - } - } - } - catch( Exception ) - { - } -#endif - if( type == null ) - { - type = Type.GetType( editorAttribute.EditorTypeName ); - } - _dictEditorTypeName.Add( editorAttribute.EditorTypeName, type ); - } - - // If the editor does not have any public parameterless constructor, forget it. - if( typeof( ITypeEditor ).IsAssignableFrom( type ) - && ( type.GetConstructor( new Type[ 0 ] ) != null ) ) - { - var instance = Activator.CreateInstance( type ) as ITypeEditor; - Debug.Assert( instance != null, "Type was expected to be ITypeEditor with public constructor." ); - if( instance != null ) - return instance; - } - } - - var itemsSourceAttribute = GetAttribute(); - if( itemsSourceAttribute != null ) - return new ItemsSourceAttributeEditor( itemsSourceAttribute ); - - return null; - } - - #endregion - - #region Private Methods - - private T GetAttribute() where T : Attribute - { - return PropertyGridUtilities.GetAttribute( PropertyDescriptor ); - } - - private void Init( PropertyDescriptor propertyDescriptor, object selectedObject ) - { - if( propertyDescriptor == null ) - throw new ArgumentNullException( "propertyDescriptor" ); - - if( selectedObject == null ) - throw new ArgumentNullException( "selectedObject" ); - - _propertyDescriptor = propertyDescriptor; - _selectedObject = selectedObject; - _dpDescriptor = DependencyPropertyDescriptor.FromProperty( propertyDescriptor ); - } - - #endregion //Private Methods - - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/DescriptorPropertyDefinitionBase.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/DescriptorPropertyDefinitionBase.cs deleted file mode 100644 index a24619d5..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/DescriptorPropertyDefinitionBase.cs +++ /dev/null @@ -1,693 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Windows; -using System.Windows.Input; -using Xceed.Wpf.Toolkit.PropertyGrid.Commands; -using System.Windows.Media; -using Xceed.Wpf.Toolkit.PropertyGrid.Editors; -using System.Diagnostics; -using System.ComponentModel; -using System.Windows.Markup.Primitives; -using System.Windows.Data; -#if !VS2008 -using System.ComponentModel.DataAnnotations; -#endif -using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - internal abstract class DescriptorPropertyDefinitionBase : DependencyObject - { - #region Members - - private string _category; - private string _categoryValue; - private string _description; - private string _displayName; - private object _defaultValue; - private int _displayOrder; - private bool _expandableAttribute; - private bool _isReadOnly; - private IList _newItemTypes; - private IEnumerable _commandBindings; - - #endregion - - internal abstract PropertyDescriptor PropertyDescriptor - { - get; - } - - #region Initialization - - - internal DescriptorPropertyDefinitionBase( bool isPropertyGridCategorized - ) - { - this.IsPropertyGridCategorized = isPropertyGridCategorized; - } - - #endregion - - #region Virtual Methods - - protected virtual string ComputeCategory() - { - return null; - } - - protected virtual string ComputeCategoryValue() - { - return null; - } - - protected virtual string ComputeDescription() - { - return null; - } - - - - protected virtual int ComputeDisplayOrder( bool isPropertyGridCategorized ) - { - return int.MaxValue; - } - - protected virtual bool ComputeExpandableAttribute() - { - return false; - } - - protected virtual object ComputeDefaultValueAttribute() - { - return null; - } - - protected abstract bool ComputeIsExpandable(); - - protected virtual IList ComputeNewItemTypes() - { - return null; - } - - protected virtual bool ComputeIsReadOnly() - { - return false; - } - - protected virtual bool ComputeCanResetValue() - { - return false; - } - - protected virtual object ComputeAdvancedOptionsTooltip() - { - return null; - } - - protected virtual void ResetValue() - { - var binding = BindingOperations.GetBindingExpressionBase( this, DescriptorPropertyDefinition.ValueProperty ); - if( binding != null ) - { - binding.UpdateTarget(); - } - } - - protected abstract BindingBase CreateValueBinding(); - - #endregion - - #region Internal Methods - - internal abstract ObjectContainerHelperBase CreateContainerHelper( IPropertyContainer parent ); - - internal void RaiseContainerHelperInvalidated() - { - if( this.ContainerHelperInvalidated != null ) - { - this.ContainerHelperInvalidated( this, EventArgs.Empty ); - } - } - - internal virtual ITypeEditor CreateDefaultEditor( PropertyItem propertyItem ) - { - return null; - } - - internal virtual ITypeEditor CreateAttributeEditor() - { - return null; - } - - internal void UpdateAdvanceOptionsForItem( DependencyObject dependencyObject, DependencyPropertyDescriptor dpDescriptor, out object tooltip ) - { - tooltip = StringConstants.Default; - - bool isResource = false; - bool isDynamicResource = false; - - //TODO: need to find a better way to determine if a StaticResource has been applied to any property not just a style(maybe with StaticResourceExtension) - isResource = typeof( Style ).IsAssignableFrom( this.PropertyType ); - isDynamicResource = typeof( DynamicResourceExtension ).IsAssignableFrom( this.PropertyType ); - - if( isResource || isDynamicResource ) - { - tooltip = StringConstants.Resource; - } - else - { - if( ( dependencyObject != null ) && ( dpDescriptor != null ) ) - { - if( BindingOperations.GetBindingExpressionBase( dependencyObject, dpDescriptor.DependencyProperty ) != null ) - { - tooltip = StringConstants.Databinding; - } - else - { - BaseValueSource bvs = - DependencyPropertyHelper - .GetValueSource( dependencyObject, dpDescriptor.DependencyProperty ) - .BaseValueSource; - - switch( bvs ) - { - case BaseValueSource.Inherited: - case BaseValueSource.DefaultStyle: - case BaseValueSource.ImplicitStyleReference: - tooltip = StringConstants.Inheritance; - break; - case BaseValueSource.DefaultStyleTrigger: - break; - case BaseValueSource.Style: - tooltip = StringConstants.StyleSetter; - break; - - case BaseValueSource.Local: - tooltip = StringConstants.Local; - break; - } - } - } - else - { - // When the Value is diferent from the DefaultValue, use the local icon. - if( !object.Equals( this.Value, this.DefaultValue ) ) - { - if( this.DefaultValue != null ) - { - tooltip = StringConstants.Local; - } - else - { - if( this.PropertyType.IsValueType ) - { - var defaultValue = Activator.CreateInstance( this.PropertyType ); - // When the Value is diferent from the DefaultValue, use the local icon. - if( !object.Equals( this.Value, defaultValue ) ) - { - tooltip = StringConstants.Local; - } - } - else - { - // When the Value is diferent from null, use the local icon. - if( this.Value != null ) - { - tooltip = StringConstants.Local; - } - } - } - } - } - } - } - - internal void UpdateAdvanceOptions() - { - // Only set the Tooltip. The Icon will be added in XAML based on the Tooltip. - this.AdvancedOptionsTooltip = this.ComputeAdvancedOptionsTooltip(); - } - - internal void UpdateIsExpandable() - { - this.IsExpandable = this.ComputeIsExpandable() - && ( this.ExpandableAttribute - ); - } - - internal void UpdateValueFromSource() - { - var bindingExpr = BindingOperations.GetBindingExpressionBase( this, DescriptorPropertyDefinitionBase.ValueProperty ); - if( bindingExpr != null ) - { - bindingExpr.UpdateTarget(); - } - } - - - - - - internal object ComputeDescriptionForItem( object item ) - { - PropertyDescriptor pd = item as PropertyDescriptor; - - //We do not simply rely on the "Description" property of PropertyDescriptor - //since this value is cached by PropertyDescriptor and the localized version - //(e.g., LocalizedDescriptionAttribute) value can dynamicaly change. -#if !VS2008 - var displayAttribute = PropertyGridUtilities.GetAttribute( pd ); - if( displayAttribute != null ) - { - return displayAttribute.GetDescription(); - } -#endif - - var descriptionAtt = PropertyGridUtilities.GetAttribute( pd ); - return (descriptionAtt != null) - ? descriptionAtt.Description - : pd.Description; - } - - internal object ComputeNewItemTypesForItem( object item ) - { - PropertyDescriptor pd = item as PropertyDescriptor; - var attribute = PropertyGridUtilities.GetAttribute( pd ); - - return (attribute != null) - ? attribute.Types - : null; - } - - - - - - internal object ComputeDisplayOrderForItem( object item ) - { - PropertyDescriptor pd = item as PropertyDescriptor; -#if !VS2008 - var displayAttribute = PropertyGridUtilities.GetAttribute( PropertyDescriptor ); - if( displayAttribute != null ) - { - var order = displayAttribute.GetOrder(); - if( order.HasValue ) - return displayAttribute.GetOrder(); - } -#endif - - List list = pd.Attributes.OfType().ToList(); - - if( list.Count > 0 ) - { - this.ValidatePropertyOrderAttributes( list ); - - if( this.IsPropertyGridCategorized ) - { - var attribute = list.FirstOrDefault( x => ((x.UsageContext == UsageContextEnum.Categorized) - || (x.UsageContext == UsageContextEnum.Both)) ); - if( attribute != null ) - return attribute.Order; - } - else - { - var attribute = list.FirstOrDefault( x => ((x.UsageContext == UsageContextEnum.Alphabetical) - || (x.UsageContext == UsageContextEnum.Both)) ); - if( attribute != null ) - return attribute.Order; - } - } - - // Max Value. Properties with no order will be displayed last. - return int.MaxValue; - } - - internal object ComputeExpandableAttributeForItem( object item ) - { - var pd = (PropertyDescriptor)item; - - var attribute = PropertyGridUtilities.GetAttribute( pd ); - return (attribute != null); - } - - internal int ComputeDisplayOrderInternal( bool isPropertyGridCategorized ) - { - return this.ComputeDisplayOrder( isPropertyGridCategorized ); - } - - internal object GetValueInstance( object sourceObject ) - { - ICustomTypeDescriptor customTypeDescriptor = sourceObject as ICustomTypeDescriptor; - if( customTypeDescriptor != null ) - sourceObject = customTypeDescriptor.GetPropertyOwner( PropertyDescriptor ); - - return sourceObject; - } - - internal object ComputeDefaultValueAttributeForItem( object item ) - { - var pd = ( PropertyDescriptor )item; - - var defaultValue = PropertyGridUtilities.GetAttribute( pd ); - return ( defaultValue != null ) ? defaultValue.Value : null; - } - - #endregion - - #region Private Methods - - private static void ExecuteResetValueCommand( object sender, ExecutedRoutedEventArgs e ) - { - var affectedPropertyItem = e.Parameter as PropertyItem; - if( affectedPropertyItem == null ) - { - affectedPropertyItem = sender as PropertyItem; - } - - if( ( affectedPropertyItem != null ) && ( affectedPropertyItem.DescriptorDefinition != null ) ) - { - if( affectedPropertyItem.DescriptorDefinition.ComputeCanResetValue() ) - { - affectedPropertyItem.DescriptorDefinition.ResetValue(); - } - } - } - - private static void CanExecuteResetValueCommand( object sender, CanExecuteRoutedEventArgs e ) - { - var affectedPropertyItem = e.Parameter as PropertyItem; - if( affectedPropertyItem == null ) - { - affectedPropertyItem = sender as PropertyItem; - } - - e.CanExecute = ( (affectedPropertyItem != null) && ( affectedPropertyItem.DescriptorDefinition != null) ) - ? affectedPropertyItem.DescriptorDefinition.ComputeCanResetValue() - : false; - } - - private string ComputeDisplayName() - { -#if VS2008 - var displayName = PropertyDescriptor.DisplayName; -#else - var displayAttribute = PropertyGridUtilities.GetAttribute( PropertyDescriptor ); - var displayName = (displayAttribute != null) ? displayAttribute.GetName() : PropertyDescriptor.DisplayName; -#endif - - var attribute = PropertyGridUtilities.GetAttribute( PropertyDescriptor ); - if( (attribute != null) && attribute.NeedParenthesis ) - { - displayName = "(" + displayName + ")"; - } - - return displayName; - } - - private void ValidatePropertyOrderAttributes( List list ) - { - if( list.Count > 0 ) - { - PropertyOrderAttribute both = list.FirstOrDefault( x => x.UsageContext == UsageContextEnum.Both ); - if( (both != null) && (list.Count > 1) ) - Debug.Assert( false, "A PropertyItem can't have more than 1 PropertyOrderAttribute when it has UsageContext : Both" ); - } - } - - #endregion - - #region Events - - public event EventHandler ContainerHelperInvalidated; - - #endregion - - #region AdvancedOptionsIcon (DP) - - public static readonly DependencyProperty AdvancedOptionsIconProperty = - DependencyProperty.Register( "AdvancedOptionsIcon", typeof( ImageSource ), typeof( DescriptorPropertyDefinitionBase ), new UIPropertyMetadata( null ) ); - - public ImageSource AdvancedOptionsIcon - { - get - { - return (ImageSource)GetValue( AdvancedOptionsIconProperty ); - } - set - { - SetValue( AdvancedOptionsIconProperty, value ); - } - } - - #endregion - - #region AdvancedOptionsTooltip (DP) - - public static readonly DependencyProperty AdvancedOptionsTooltipProperty = - DependencyProperty.Register( "AdvancedOptionsTooltip", typeof( object ), typeof( DescriptorPropertyDefinitionBase ), new UIPropertyMetadata( null ) ); - - public object AdvancedOptionsTooltip - { - get - { - return (object)GetValue( AdvancedOptionsTooltipProperty ); - } - set - { - SetValue( AdvancedOptionsTooltipProperty, value ); - } - } - - #endregion //AdvancedOptionsTooltip - - #region IsExpandable (DP) - - public static readonly DependencyProperty IsExpandableProperty = - DependencyProperty.Register( "IsExpandable", typeof( bool ), typeof( DescriptorPropertyDefinitionBase ), new UIPropertyMetadata( false ) ); - - public bool IsExpandable - { - get - { - return (bool)GetValue( IsExpandableProperty ); - } - set - { - SetValue( IsExpandableProperty, value ); - } - } - - #endregion //IsExpandable - - public string Category - { - get - { - return _category; - } - internal set - { - _category = value; - } - } - - public string CategoryValue - { - get - { - return _categoryValue; - } - internal set - { - _categoryValue = value; - } - } - - public IEnumerable CommandBindings - { - get - { - return _commandBindings; - } - } - - public string DisplayName - { - get - { - return _displayName; - } - internal set - { - _displayName = value; - } - } - - public object DefaultValue - { - get - { - return _defaultValue; - } - set - { - _defaultValue = value; - } - } - - - - public string Description - { - get - { - return _description; - } - internal set - { - _description = value; - } - } - - public int DisplayOrder - { - get - { - return _displayOrder; - } - internal set - { - _displayOrder = value; - } - } - - public bool IsReadOnly - { - get - { - return _isReadOnly; - } - } - - public IList NewItemTypes - { - get - { - return _newItemTypes; - } - } - - public string PropertyName - { - get - { - // A common property which is present in all selectedObjects will always have the same name. - return PropertyDescriptor.Name; - } - } - - public Type PropertyType - { - get - { - return PropertyDescriptor.PropertyType; - } - } - - internal bool ExpandableAttribute - { - get - { - return _expandableAttribute; - } - set - { - _expandableAttribute = value; - this.UpdateIsExpandable(); - } - } - - - internal bool IsPropertyGridCategorized - { - get; - set; - } - - - - #region Value Property (DP) - - public static readonly DependencyProperty ValueProperty = DependencyProperty.Register( "Value", typeof( object ), typeof( DescriptorPropertyDefinitionBase ), new UIPropertyMetadata( null, OnValueChanged ) ); - public object Value - { - get - { - return GetValue( ValueProperty ); - } - set - { - SetValue( ValueProperty, value ); - } - } - - private static void OnValueChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - ((DescriptorPropertyDefinitionBase)o).OnValueChanged( e.OldValue, e.NewValue ); - } - - internal virtual void OnValueChanged( object oldValue, object newValue ) - { - UpdateIsExpandable(); - UpdateAdvanceOptions(); - - // Reset command also affected. - CommandManager.InvalidateRequerySuggested(); - } - - #endregion //Value Property - - public virtual void InitProperties() - { - // Do "IsReadOnly" and PropertyName first since the others may need that value. - _isReadOnly = ComputeIsReadOnly(); - _category = ComputeCategory(); - _categoryValue = ComputeCategoryValue(); - _description = ComputeDescription(); - _displayName = ComputeDisplayName(); - _defaultValue = ComputeDefaultValueAttribute(); - _displayOrder = ComputeDisplayOrder( this.IsPropertyGridCategorized ); - _expandableAttribute = ComputeExpandableAttribute(); - - - _newItemTypes = ComputeNewItemTypes(); - _commandBindings = new CommandBinding[] { new CommandBinding( PropertyItemCommands.ResetValue, ExecuteResetValueCommand, CanExecuteResetValueCommand ) }; - - - BindingBase valueBinding = this.CreateValueBinding(); - BindingOperations.SetBinding( this, DescriptorPropertyDefinitionBase.ValueProperty, valueBinding ); - } - - - - - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/EditorDefinition.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/EditorDefinition.cs deleted file mode 100644 index 5a5675d9..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/EditorDefinition.cs +++ /dev/null @@ -1,100 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Windows; -using System.Collections.Generic; -using System.Linq; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - [Obsolete(@"Use EditorTemplateDefinition instead of EditorDefinition. " + EditorDefinition.UsageEx)] - public class EditorDefinition : EditorTemplateDefinition - { - private const string UsageEx = " (XAML Ex: OR )"; - - public EditorDefinition() - { - const string usageErr = "{0} is obsolete. Instead use {1}."; - System.Diagnostics.Trace.TraceWarning( string.Format( usageErr, typeof( EditorDefinition ), typeof( EditorTemplateDefinition ) ) + UsageEx ); - } - - /// - /// Gets or sets the template of the editor. - /// This Property is part of the obsolete EditorDefinition class. - /// Use EditorTemplateDefinition class and the EditingTemplate property. - /// - public DataTemplate EditorTemplate - { - get; - set; - } - - - private PropertyDefinitionCollection _properties = new PropertyDefinitionCollection(); - /// - /// List the PropertyDefinitions that identify the properties targeted by the EditorTemplate. - /// This Property is part of the obsolete EditorDefinition class. - /// Use "EditorTemplateDefinition" class and the "TargetProperties" property
- /// XAML Ex.: <t:EditorTemplateDefinition TargetProperties="FirstName,LastName" .../> - ///
- public PropertyDefinitionCollection PropertiesDefinitions - { - get - { - return _properties; - } - set - { - _properties = value; - } - } - - public Type TargetType - { - get; - set; - } - - internal override void Lock() - { - const string usageError = @"Use a EditorTemplateDefinition instead of EditorDefinition in order to use the '{0}' property."; - if( this.EditingTemplate != null ) - throw new InvalidOperationException( string.Format( usageError, "EditingTemplate" ) ); - - if( this.TargetProperties != null && this.TargetProperties.Count > 0) - throw new InvalidOperationException( string.Format( usageError, "TargetProperties" ) ); - - List properties = new List(); - if( this.PropertiesDefinitions != null ) - { - foreach( PropertyDefinition def in this.PropertiesDefinitions ) - { - if( def.TargetProperties != null ) - { - properties.AddRange( def.TargetProperties.Cast() ); - } - } - } - - this.TargetProperties = properties; - this.EditingTemplate = this.EditorTemplate; - - base.Lock(); - } - - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/CheckBoxEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/CheckBoxEditor.cs deleted file mode 100644 index bf525b84..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/CheckBoxEditor.cs +++ /dev/null @@ -1,47 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Windows; -using System.Windows.Controls; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public class CheckBoxEditor : TypeEditor - { - protected override CheckBox CreateEditor() - { - return new PropertyGridEditorCheckBox(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - Editor.Margin = new Thickness( 5, 0, 0, 0 ); - } - - protected override void SetValueDependencyProperty() - { - ValueProperty = CheckBox.IsCheckedProperty; - } - } - - public class PropertyGridEditorCheckBox : CheckBox - { - static PropertyGridEditorCheckBox() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorCheckBox ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorCheckBox ) ) ); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/CollectionEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/CollectionEditor.cs deleted file mode 100644 index 22f9ec12..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/CollectionEditor.cs +++ /dev/null @@ -1,112 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Windows; -using Xceed.Wpf.Toolkit.Core.Utilities; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public class CollectionEditor : TypeEditor - { - protected override void SetValueDependencyProperty() - { - ValueProperty = CollectionControlButton.ItemsSourceProperty; - } - - protected override CollectionControlButton CreateEditor() - { - return new PropertyGridEditorCollectionControl(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - - var propertyGrid = propertyItem.ParentElement as PropertyGrid; - if( propertyGrid != null ) - { - // Use the PropertyGrid.EditorDefinitions for the CollectionControl's propertyGrid. - this.Editor.EditorDefinitions = propertyGrid.EditorDefinitions; - } - } - - protected override void ResolveValueBinding( PropertyItem propertyItem ) - { - var type = propertyItem.PropertyType; - - Editor.ItemsSourceType = type; - - if( type.BaseType == typeof( System.Array ) ) - { - Editor.NewItemTypes = new List() { type.GetElementType() }; - } - else - { - if( (propertyItem.DescriptorDefinition != null) - && (propertyItem.DescriptorDefinition.NewItemTypes != null) - && (propertyItem.DescriptorDefinition.NewItemTypes.Count > 0) ) - { - Editor.NewItemTypes = propertyItem.DescriptorDefinition.NewItemTypes; - } - else - { - //Check if we have a Dictionary - var dictionaryTypes = ListUtilities.GetDictionaryItemsType( type ); - if( (dictionaryTypes != null) && (dictionaryTypes.Length == 2) ) - { - // A Dictionary contains KeyValuePair that can't be edited. - // We need to create EditableKeyValuePairs. - // Create a EditableKeyValuePair< TKey, TValue> type from dictionary generic arguments type - var editableKeyValuePairType = ListUtilities.CreateEditableKeyValuePairType( dictionaryTypes[ 0 ], dictionaryTypes[ 1 ] ); - Editor.NewItemTypes = new List() { editableKeyValuePairType }; - } - else - { - //Check if we have a list - var listType = ListUtilities.GetListItemType( type ); - if( listType != null ) - { - Editor.NewItemTypes = new List() { listType }; - } - else - { - //Check if we have a Collection of T - var colType = ListUtilities.GetCollectionItemType( type ); - if( colType != null ) - { - Editor.NewItemTypes = new List() { colType }; - } - } - } - } - } - - base.ResolveValueBinding( propertyItem ); - } - - } - - public class PropertyGridEditorCollectionControl : CollectionControlButton - { - static PropertyGridEditorCollectionControl() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorCollectionControl ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorCollectionControl ) ) ); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/ColorEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/ColorEditor.cs deleted file mode 100644 index ff7941f1..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/ColorEditor.cs +++ /dev/null @@ -1,45 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Windows; -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public class ColorEditor : TypeEditor - { - protected override ColorPicker CreateEditor() - { - return new PropertyGridEditorColorPicker(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - Editor.BorderThickness = new System.Windows.Thickness( 0 ); - Editor.DisplayColorAndName = true; - } - protected override void SetValueDependencyProperty() - { - ValueProperty = ColorPicker.SelectedColorProperty; - } - } - - public class PropertyGridEditorColorPicker : ColorPicker - { - static PropertyGridEditorColorPicker() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorColorPicker ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorColorPicker ) ) ); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/ComboBoxEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/ComboBoxEditor.cs deleted file mode 100644 index 4f542a43..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/ComboBoxEditor.cs +++ /dev/null @@ -1,56 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Collections.Generic; -using System.Collections; -using System.Windows; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public abstract class ComboBoxEditor : TypeEditor - { - protected override void SetValueDependencyProperty() - { - ValueProperty = System.Windows.Controls.ComboBox.SelectedItemProperty; - } - - protected override System.Windows.Controls.ComboBox CreateEditor() - { - return new PropertyGridEditorComboBox(); - } - - protected override void ResolveValueBinding( PropertyItem propertyItem ) - { - SetItemsSource( propertyItem ); - base.ResolveValueBinding( propertyItem ); - } - - protected abstract IEnumerable CreateItemsSource( PropertyItem propertyItem ); - - private void SetItemsSource( PropertyItem propertyItem ) - { - Editor.ItemsSource = CreateItemsSource( propertyItem ); - } - } - - public class PropertyGridEditorComboBox : System.Windows.Controls.ComboBox - { - static PropertyGridEditorComboBox() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorComboBox ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorComboBox ) ) ); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/EnumComboBoxEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/EnumComboBoxEditor.cs deleted file mode 100644 index b9e22a2a..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/EnumComboBoxEditor.cs +++ /dev/null @@ -1,59 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; -using System.Collections; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public class EnumComboBoxEditor : ComboBoxEditor - { - protected override IEnumerable CreateItemsSource( PropertyItem propertyItem ) - { - return GetValues( propertyItem.PropertyType ); - } - - private static object[] GetValues( Type enumType ) - { - List values = new List(); - - if( enumType != null ) - { - var fields = enumType.GetFields().Where( x => x.IsLiteral ); - foreach( FieldInfo field in fields ) - { - // Get array of BrowsableAttribute attributes - object[] attrs = field.GetCustomAttributes( typeof( BrowsableAttribute ), false ); - if( attrs.Length == 1 ) - { - // If attribute exists and its value is false continue to the next field... - BrowsableAttribute brAttr = ( BrowsableAttribute )attrs[ 0 ]; - if( brAttr.Browsable == false ) - continue; - } - - values.Add( field.GetValue( enumType ) ); - } - } - - return values.ToArray(); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/FontComboBoxEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/FontComboBoxEditor.cs deleted file mode 100644 index 5997b50d..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/FontComboBoxEditor.cs +++ /dev/null @@ -1,42 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Collections.Generic; -using System.Linq; -using System.Windows; -using System.Windows.Media; -using System.Collections; -using Xceed.Wpf.Toolkit.Core.Utilities; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public class FontComboBoxEditor : ComboBoxEditor - { - protected override IEnumerable CreateItemsSource( PropertyItem propertyItem ) - { - if( propertyItem.PropertyType == typeof( FontFamily ) ) - return FontUtilities.Families.OrderBy( x => x.Source); - else if( propertyItem.PropertyType == typeof( FontWeight ) ) - return FontUtilities.Weights; - else if( propertyItem.PropertyType == typeof( FontStyle ) ) - return FontUtilities.Styles; - else if( propertyItem.PropertyType == typeof( FontStretch ) ) - return FontUtilities.Stretches; - - return null; - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/ITypeEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/ITypeEditor.cs deleted file mode 100644 index 447eb176..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/ITypeEditor.cs +++ /dev/null @@ -1,25 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Windows; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public interface ITypeEditor - { - FrameworkElement ResolveEditor( PropertyItem propertyItem ); - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/ItemsSourceAttributeEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/ItemsSourceAttributeEditor.cs deleted file mode 100644 index 880ad78e..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/ItemsSourceAttributeEditor.cs +++ /dev/null @@ -1,68 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public class ItemsSourceAttributeEditor : TypeEditor - { - private readonly ItemsSourceAttribute _attribute; - - public ItemsSourceAttributeEditor( ItemsSourceAttribute attribute ) - { - _attribute = attribute; - } - - protected override void SetValueDependencyProperty() - { - ValueProperty = System.Windows.Controls.ComboBox.SelectedValueProperty; - } - - protected override System.Windows.Controls.ComboBox CreateEditor() - { - return new PropertyGridEditorComboBox(); - } - - protected override void ResolveValueBinding( PropertyItem propertyItem ) - { - SetItemsSource(); - base.ResolveValueBinding( propertyItem ); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - Editor.DisplayMemberPath = "DisplayName"; - Editor.SelectedValuePath = "Value"; - if( propertyItem != null ) - { - Editor.IsEnabled = !propertyItem.IsReadOnly; - } - } - - private void SetItemsSource() - { - Editor.ItemsSource = CreateItemsSource(); - } - - private System.Collections.IEnumerable CreateItemsSource() - { - var instance = Activator.CreateInstance( _attribute.Type ); - return ( instance as IItemsSource ).GetValues(); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/MaskedTextBoxEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/MaskedTextBoxEditor.cs deleted file mode 100644 index d52dafb4..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/MaskedTextBoxEditor.cs +++ /dev/null @@ -1,65 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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; -using System.Windows.Controls; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public class MaskedTextBoxEditor : TypeEditor - { - public string Mask - { - get; - set; - } - - public Type ValueDataType - { - get; - set; - } - - protected override MaskedTextBox CreateEditor() - { - return new PropertyGridEditorMaskedTextBox(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - Editor.BorderThickness = new System.Windows.Thickness( 0 ); - this.Editor.ValueDataType = this.ValueDataType; - this.Editor.Mask = this.Mask; - } - - protected override void SetValueDependencyProperty() - { - this.ValueProperty = MaskedTextBox.ValueProperty; - } - } - - public class PropertyGridEditorMaskedTextBox : MaskedTextBox - { - static PropertyGridEditorMaskedTextBox() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorMaskedTextBox ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorMaskedTextBox ) ) ); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/PrimitiveTypeCollectionEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/PrimitiveTypeCollectionEditor.cs deleted file mode 100644 index 3aca4e30..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/PrimitiveTypeCollectionEditor.cs +++ /dev/null @@ -1,68 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Windows; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public class PrimitiveTypeCollectionEditor : TypeEditor - { - protected override void SetControlProperties( PropertyItem propertyItem ) - { - Editor.BorderThickness = new System.Windows.Thickness( 0 ); - Editor.Content = "(Collection)"; - } - - protected override void SetValueDependencyProperty() - { - ValueProperty = PrimitiveTypeCollectionControl.ItemsSourceProperty; - } - - protected override PrimitiveTypeCollectionControl CreateEditor() - { - return new PropertyGridEditorPrimitiveTypeCollectionControl(); - } - - protected override void ResolveValueBinding( PropertyItem propertyItem ) - { - var type = propertyItem.PropertyType; - Editor.ItemsSourceType = type; - - if( type.BaseType == typeof( System.Array ) ) - { - Editor.ItemType = type.GetElementType(); - } - else - { - var typeArguments = type.GetGenericArguments(); - if( typeArguments.Length > 0 ) - { - Editor.ItemType = typeArguments[ 0 ]; - } - } - - base.ResolveValueBinding( propertyItem ); - } - } - - public class PropertyGridEditorPrimitiveTypeCollectionControl : PrimitiveTypeCollectionControl - { - static PropertyGridEditorPrimitiveTypeCollectionControl() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorPrimitiveTypeCollectionControl ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorPrimitiveTypeCollectionControl ) ) ); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/SourceComboBoxEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/SourceComboBoxEditor.cs deleted file mode 100644 index 7c7e87f3..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/SourceComboBoxEditor.cs +++ /dev/null @@ -1,79 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections; -using System.ComponentModel; -using System.Globalization; -using System.Windows.Data; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public class SourceComboBoxEditor : ComboBoxEditor - { - ICollection _collection; - TypeConverter _typeConverter; - - public SourceComboBoxEditor( ICollection collection, TypeConverter typeConverter ) - { - _collection = collection; - _typeConverter = typeConverter; - } - - protected override IEnumerable CreateItemsSource( PropertyItem propertyItem ) - { - return _collection; - } - - protected override IValueConverter CreateValueConverter() - { - //When using a stringConverter, we need to convert the value - if( (_typeConverter != null) && (_typeConverter is StringConverter) ) - return new SourceComboBoxEditorConverter( _typeConverter ); - return null; - } - } - - internal class SourceComboBoxEditorConverter : IValueConverter - { - private TypeConverter _typeConverter; - - internal SourceComboBoxEditorConverter( TypeConverter typeConverter ) - { - _typeConverter = typeConverter; - } - - public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) - { - if( _typeConverter != null ) - { - if( _typeConverter.CanConvertTo( typeof(string) ) ) - return _typeConverter.ConvertTo( value, typeof(string) ); - } - return value; - } - - public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) - { - if( _typeConverter != null ) - { - if( _typeConverter.CanConvertFrom( value.GetType() ) ) - return _typeConverter.ConvertFrom( value ); - } - return value; - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/TextBlockEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/TextBlockEditor.cs deleted file mode 100644 index dc2c9b90..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/TextBlockEditor.cs +++ /dev/null @@ -1,48 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Windows.Controls; -using System.Windows; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public class TextBlockEditor : TypeEditor - { - protected override TextBlock CreateEditor() - { - return new PropertyGridEditorTextBlock(); - } - - protected override void SetValueDependencyProperty() - { - ValueProperty = TextBlock.TextProperty; - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - Editor.Margin = new System.Windows.Thickness( 5, 0, 0, 0 ); - Editor.TextTrimming = TextTrimming.CharacterEllipsis; - } - } - - public class PropertyGridEditorTextBlock : TextBlock - { - static PropertyGridEditorTextBlock() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorTextBlock ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorTextBlock ) ) ); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/TextBoxEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/TextBoxEditor.cs deleted file mode 100644 index 09a3826b..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/TextBoxEditor.cs +++ /dev/null @@ -1,56 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Windows.Controls; -using System.Windows; -#if !VS2008 -using System.ComponentModel.DataAnnotations; -#endif - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public class TextBoxEditor : TypeEditor - { - protected override WatermarkTextBox CreateEditor() - { - return new PropertyGridEditorTextBox(); - } - -#if !VS2008 - protected override void SetControlProperties( PropertyItem propertyItem ) - { - var displayAttribute = PropertyGridUtilities.GetAttribute( propertyItem.PropertyDescriptor ); - if( displayAttribute != null ) - { - this.Editor.Watermark = displayAttribute.GetPrompt(); - } - } -#endif - - protected override void SetValueDependencyProperty() - { - ValueProperty = TextBox.TextProperty; - } - } - - public class PropertyGridEditorTextBox : WatermarkTextBox - { - static PropertyGridEditorTextBox() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorTextBox ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorTextBox ) ) ); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/TypeEditor.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/TypeEditor.cs deleted file mode 100644 index 01c61a4a..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/TypeEditor.cs +++ /dev/null @@ -1,84 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Windows; -using System.Windows.Data; -using Xceed.Wpf.Toolkit.Primitives; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public abstract class TypeEditor : ITypeEditor where T : FrameworkElement, new() - { - #region Properties - - protected T Editor - { - get; - set; - } - protected DependencyProperty ValueProperty - { - get; - set; - } - - #endregion //Properties - - #region ITypeEditor Members - - public virtual FrameworkElement ResolveEditor( PropertyItem propertyItem ) - { - Editor = this.CreateEditor(); - SetValueDependencyProperty(); - SetControlProperties( propertyItem ); - ResolveValueBinding( propertyItem ); - return Editor; - } - - #endregion //ITypeEditor Members - - #region Methods - - protected virtual T CreateEditor() - { - return new T(); - } - - protected virtual IValueConverter CreateValueConverter() - { - return null; - } - - protected virtual void ResolveValueBinding( PropertyItem propertyItem ) - { - var _binding = new Binding( "Value" ); - _binding.Source = propertyItem; - _binding.UpdateSourceTrigger = (Editor is InputBase) ? UpdateSourceTrigger.PropertyChanged : UpdateSourceTrigger.Default; - _binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay; - _binding.Converter = CreateValueConverter(); - BindingOperations.SetBinding( Editor, ValueProperty, _binding ); - } - - protected virtual void SetControlProperties( PropertyItem propertyItem ) - { - //TODO: implement in derived class - } - - protected abstract void SetValueDependencyProperty(); - - #endregion //Methods - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/UpDownEditors.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/UpDownEditors.cs deleted file mode 100644 index 17f4a63c..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/Editors/UpDownEditors.cs +++ /dev/null @@ -1,389 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using Xceed.Wpf.Toolkit.Primitives; -using System; -using System.Windows; -using System.Windows.Data; -#if !VS2008 -using System.ComponentModel.DataAnnotations; -#endif -using System.ComponentModel; - -namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors -{ - public class UpDownEditor : TypeEditor where TEditor : UpDownBase, new() - { - protected override void SetControlProperties( PropertyItem propertyItem ) - { - Editor.TextAlignment = System.Windows.TextAlignment.Left; - } - protected override void SetValueDependencyProperty() - { - ValueProperty = UpDownBase.ValueProperty; - } - -#if !VS2008 - internal void SetMinMaxFromRangeAttribute( PropertyDescriptor propertyDescriptor, TypeConverter converter ) - { - if( propertyDescriptor == null ) - return; - - var rangeAttribute = PropertyGridUtilities.GetAttribute( propertyDescriptor ); - if( rangeAttribute != null ) - { - Editor.Maximum = ((TType)converter.ConvertFrom( rangeAttribute.Maximum.ToString() )); - Editor.Minimum = ((TType)converter.ConvertFrom( rangeAttribute.Minimum.ToString() )); - } - } -#endif - } - - public class NumericUpDownEditor : UpDownEditor where TEditor : UpDownBase, new() - { - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); - - var binding = new Binding( "IsInvalid" ); - binding.Source = this.Editor; - binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; - binding.Mode = BindingMode.TwoWay; - BindingOperations.SetBinding( propertyItem, PropertyItem.IsInvalidProperty, binding ); - } - } - - public class ByteUpDownEditor : NumericUpDownEditor - { - protected override ByteUpDown CreateEditor() - { - return new PropertyGridEditorByteUpDown(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); -#if !VS2008 - this.SetMinMaxFromRangeAttribute( propertyItem.PropertyDescriptor, TypeDescriptor.GetConverter( typeof( byte ) ) ); -#endif - } - } - - public class DecimalUpDownEditor : NumericUpDownEditor - { - protected override DecimalUpDown CreateEditor() - { - return new PropertyGridEditorDecimalUpDown(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); -#if !VS2008 - this.SetMinMaxFromRangeAttribute( propertyItem.PropertyDescriptor, TypeDescriptor.GetConverter( typeof( decimal ) ) ); -#endif - } - } - - public class DoubleUpDownEditor : NumericUpDownEditor - { - protected override DoubleUpDown CreateEditor() - { - return new PropertyGridEditorDoubleUpDown(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); - Editor.AllowInputSpecialValues = AllowedSpecialValues.Any; - -#if !VS2008 - this.SetMinMaxFromRangeAttribute( propertyItem.PropertyDescriptor, TypeDescriptor.GetConverter( typeof( double ) ) ); -#endif - } - } - - public class IntegerUpDownEditor : NumericUpDownEditor - { - protected override IntegerUpDown CreateEditor() - { - return new PropertyGridEditorIntegerUpDown(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); -#if !VS2008 - this.SetMinMaxFromRangeAttribute( propertyItem.PropertyDescriptor, TypeDescriptor.GetConverter( typeof( int ) ) ); -#endif - } - } - - public class LongUpDownEditor : NumericUpDownEditor - { - protected override LongUpDown CreateEditor() - { - return new PropertyGridEditorLongUpDown(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); -#if !VS2008 - this.SetMinMaxFromRangeAttribute( propertyItem.PropertyDescriptor, TypeDescriptor.GetConverter( typeof( long ) ) ); -#endif - } - } - - public class ShortUpDownEditor : NumericUpDownEditor - { - protected override ShortUpDown CreateEditor() - { - return new PropertyGridEditorShortUpDown(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); -#if !VS2008 - this.SetMinMaxFromRangeAttribute( propertyItem.PropertyDescriptor, TypeDescriptor.GetConverter( typeof( short ) ) ); -#endif - } - } - - public class SingleUpDownEditor : NumericUpDownEditor - { - protected override SingleUpDown CreateEditor() - { - return new PropertyGridEditorSingleUpDown(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); - Editor.AllowInputSpecialValues = AllowedSpecialValues.Any; -#if !VS2008 - this.SetMinMaxFromRangeAttribute( propertyItem.PropertyDescriptor, TypeDescriptor.GetConverter( typeof( float ) ) ); -#endif - } - } - - public class DateTimeUpDownEditor : UpDownEditor - { - protected override DateTimeUpDown CreateEditor() - { - return new PropertyGridEditorDateTimeUpDown(); - } - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); -#if !VS2008 - this.SetMinMaxFromRangeAttribute( propertyItem.PropertyDescriptor, TypeDescriptor.GetConverter( typeof( DateTime ) ) ); -#endif - } - } - - public class TimeSpanUpDownEditor : UpDownEditor - { - protected override TimeSpanUpDown CreateEditor() - { - return new PropertyGridEditorTimeSpanUpDown(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); -#if !VS2008 - this.SetMinMaxFromRangeAttribute( propertyItem.PropertyDescriptor, TypeDescriptor.GetConverter( typeof( TimeSpan ) ) ); -#endif - } - } - - internal class SByteUpDownEditor : NumericUpDownEditor - { - protected override SByteUpDown CreateEditor() - { - return new PropertyGridEditorSByteUpDown(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); -#if !VS2008 - this.SetMinMaxFromRangeAttribute( propertyItem.PropertyDescriptor, TypeDescriptor.GetConverter( typeof( sbyte ) ) ); -#endif - } - } - - internal class UIntegerUpDownEditor : NumericUpDownEditor - { - protected override UIntegerUpDown CreateEditor() - { - return new PropertyGridEditorUIntegerUpDown(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); -#if !VS2008 - this.SetMinMaxFromRangeAttribute( propertyItem.PropertyDescriptor, TypeDescriptor.GetConverter( typeof( uint ) ) ); -#endif - } - } - - internal class ULongUpDownEditor : NumericUpDownEditor - { - protected override ULongUpDown CreateEditor() - { - return new PropertyGridEditorULongUpDown(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); -#if !VS2008 - this.SetMinMaxFromRangeAttribute( propertyItem.PropertyDescriptor, TypeDescriptor.GetConverter( typeof( ulong ) ) ); -#endif - } - } - - internal class UShortUpDownEditor : NumericUpDownEditor - { - protected override UShortUpDown CreateEditor() - { - return new PropertyGridEditorUShortUpDown(); - } - - protected override void SetControlProperties( PropertyItem propertyItem ) - { - base.SetControlProperties( propertyItem ); -#if !VS2008 - this.SetMinMaxFromRangeAttribute( propertyItem.PropertyDescriptor, TypeDescriptor.GetConverter( typeof( ushort ) ) ); -#endif - } - } - - - - public class PropertyGridEditorByteUpDown : ByteUpDown - { - static PropertyGridEditorByteUpDown() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorByteUpDown ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorByteUpDown ) ) ); - } - } - - public class PropertyGridEditorDecimalUpDown : DecimalUpDown - { - static PropertyGridEditorDecimalUpDown() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorDecimalUpDown ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorDecimalUpDown ) ) ); - } - } - - public class PropertyGridEditorDoubleUpDown : DoubleUpDown - { - static PropertyGridEditorDoubleUpDown() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorDoubleUpDown ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorDoubleUpDown ) ) ); - } - } - - public class PropertyGridEditorIntegerUpDown : IntegerUpDown - { - static PropertyGridEditorIntegerUpDown() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorIntegerUpDown ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorIntegerUpDown ) ) ); - } - } - - public class PropertyGridEditorLongUpDown : LongUpDown - { - static PropertyGridEditorLongUpDown() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorLongUpDown ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorLongUpDown ) ) ); - } - } - - public class PropertyGridEditorShortUpDown : ShortUpDown - { - static PropertyGridEditorShortUpDown() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorShortUpDown ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorShortUpDown ) ) ); - } - } - - public class PropertyGridEditorSingleUpDown : SingleUpDown - { - static PropertyGridEditorSingleUpDown() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorSingleUpDown ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorSingleUpDown ) ) ); - } - } - - public class PropertyGridEditorDateTimeUpDown : DateTimeUpDown - { - static PropertyGridEditorDateTimeUpDown() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorDateTimeUpDown ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorDateTimeUpDown ) ) ); - } - } - - public class PropertyGridEditorTimeSpanUpDown : TimeSpanUpDown - { - static PropertyGridEditorTimeSpanUpDown() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorTimeSpanUpDown ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorTimeSpanUpDown ) ) ); - } - } - - [CLSCompliantAttribute( false )] - public class PropertyGridEditorSByteUpDown : SByteUpDown - { - static PropertyGridEditorSByteUpDown() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorSByteUpDown ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorSByteUpDown ) ) ); - } - } - - [CLSCompliantAttribute( false )] - public class PropertyGridEditorUIntegerUpDown : UIntegerUpDown - { - static PropertyGridEditorUIntegerUpDown() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorUIntegerUpDown ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorUIntegerUpDown ) ) ); - } - } - - [CLSCompliantAttribute( false )] - public class PropertyGridEditorULongUpDown : ULongUpDown - { - static PropertyGridEditorULongUpDown() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorULongUpDown ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorULongUpDown ) ) ); - } - } - - [CLSCompliantAttribute( false )] - public class PropertyGridEditorUShortUpDown : UShortUpDown - { - static PropertyGridEditorUShortUpDown() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGridEditorUShortUpDown ), new FrameworkPropertyMetadata( typeof( PropertyGridEditorUShortUpDown ) ) ); - } - } - -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/FilterInfo.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/FilterInfo.cs deleted file mode 100644 index 916b2c5e..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/FilterInfo.cs +++ /dev/null @@ -1,29 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - internal struct FilterInfo - { - public string InputString; - public Predicate Predicate; - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/IPropertyContainer.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/IPropertyContainer.cs deleted file mode 100644 index 35770f0d..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/IPropertyContainer.cs +++ /dev/null @@ -1,57 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - - -using System.Collections.Generic; -using System.Windows.Controls; -using System.Collections; -using System.ComponentModel; -using System.Windows.Data; -using System; -using System.Windows; -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - internal interface IPropertyContainer - { - - - - - - - - ContainerHelperBase ContainerHelper { get; } - - Style PropertyContainerStyle { get; } - - EditorDefinitionCollection EditorDefinitions { get; } - - PropertyDefinitionCollection PropertyDefinitions { get; } - - bool IsCategorized { get; } - - bool IsSortedAlphabetically { get; } - - bool AutoGenerateProperties { get; } - - bool HideInheritedProperties { get; } - - FilterInfo FilterInfo { get; } - - bool? IsPropertyVisible( PropertyDescriptor pd ); - - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/ObjectContainerHelper.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/ObjectContainerHelper.cs deleted file mode 100644 index 2a823aef..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/ObjectContainerHelper.cs +++ /dev/null @@ -1,168 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -#if !VS2008 -using System.ComponentModel.DataAnnotations; -#endif -using System.Diagnostics; -using System.Linq; -using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - internal class ObjectContainerHelper : ObjectContainerHelperBase - { - private object _selectedObject; - - public ObjectContainerHelper( IPropertyContainer propertyContainer, object selectedObject ) - : base( propertyContainer ) - { - _selectedObject = selectedObject; - } - - private object SelectedObject - { - get - { - return _selectedObject; - } - } - - protected override string GetDefaultPropertyName() - { - object selectedObject = SelectedObject; - return ( selectedObject != null ) ? ObjectContainerHelperBase.GetDefaultPropertyName( SelectedObject ) : ( string )null; - } - - protected override void GenerateSubPropertiesCore( Action> updatePropertyItemsCallback ) - { - var propertyItems = new List(); - - if( SelectedObject != null ) - { - try - { - var descriptors = new List(); - { - descriptors = ObjectContainerHelperBase.GetPropertyDescriptors( SelectedObject, this.PropertyContainer.HideInheritedProperties ); - } - - foreach( var descriptor in descriptors ) - { - var propertyDef = this.GetPropertyDefinition( descriptor ); - bool isBrowsable = false; - - var isPropertyBrowsable = this.PropertyContainer.IsPropertyVisible( descriptor ); - if( isPropertyBrowsable.HasValue ) - { - isBrowsable = isPropertyBrowsable.Value; - } - else - { -#if !VS2008 - var displayAttribute = PropertyGridUtilities.GetAttribute( descriptor ); - if( displayAttribute != null ) - { - var autoGenerateField = displayAttribute.GetAutoGenerateField(); - isBrowsable = this.PropertyContainer.AutoGenerateProperties - && ((autoGenerateField.HasValue && autoGenerateField.Value) || !autoGenerateField.HasValue); - } - else -#endif - { - isBrowsable = descriptor.IsBrowsable && this.PropertyContainer.AutoGenerateProperties; - } - - if( propertyDef != null ) - { - isBrowsable = propertyDef.IsBrowsable.GetValueOrDefault( isBrowsable ); - } - } - - if( isBrowsable ) - { - var prop = this.CreatePropertyItem( descriptor, propertyDef ); - if( prop != null ) - { - propertyItems.Add( prop ); - } - } - } - } - catch( Exception e ) - { - //TODO: handle this some how - Debug.WriteLine( "Property creation failed." ); - Debug.WriteLine( e.StackTrace ); - } - } - - updatePropertyItemsCallback.Invoke( propertyItems ); - } - - - private PropertyItem CreatePropertyItem( PropertyDescriptor property, PropertyDefinition propertyDef ) - { - DescriptorPropertyDefinition definition = new DescriptorPropertyDefinition( property, SelectedObject, this.PropertyContainer ); - definition.InitProperties(); - - this.InitializeDescriptorDefinition( definition, propertyDef ); - PropertyItem propertyItem = new PropertyItem( definition ); - Debug.Assert( SelectedObject != null ); - propertyItem.Instance = SelectedObject; - propertyItem.CategoryOrder = this.GetCategoryOrder( definition.CategoryValue ); - - propertyItem.WillRefreshPropertyGrid = this.GetWillRefreshPropertyGrid( property ); - return propertyItem; - } - - private int GetCategoryOrder( object categoryValue ) - { - Debug.Assert( SelectedObject != null ); - - if( categoryValue == null ) - return int.MaxValue; - - int order = int.MaxValue; - object selectedObject = SelectedObject; - CategoryOrderAttribute[] orderAttributes = ( selectedObject != null ) - ? ( CategoryOrderAttribute[] )selectedObject.GetType().GetCustomAttributes( typeof( CategoryOrderAttribute ), true ) - : new CategoryOrderAttribute[ 0 ]; - - var orderAttribute = orderAttributes - .FirstOrDefault( ( a ) => object.Equals( a.CategoryValue, categoryValue ) ); - - if( orderAttribute != null ) - { - order = orderAttribute.Order; - } - - return order; - } - - - - - - - - - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/ObjectContainerHelperBase.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/ObjectContainerHelperBase.cs deleted file mode 100644 index 6542737a..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/ObjectContainerHelperBase.cs +++ /dev/null @@ -1,565 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Linq; -using System.Linq.Expressions; -using System.Windows; -using System.Windows.Data; -using System.Windows.Input; -using Xceed.Wpf.Toolkit.Core.Utilities; -using Xceed.Wpf.Toolkit.PropertyGrid.Editors; -using System.Collections; -using System.Collections.ObjectModel; -using System.Windows.Controls.Primitives; -using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; -using System.Windows.Controls; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - internal abstract class ObjectContainerHelperBase : ContainerHelperBase - { - // This is needed to work around the ItemsControl behavior. - // When ItemsControl is preparing its containers, it appears - // that calling Refresh() on the CollectionView bound to - // the ItemsSource prevents the items from being displayed. - // This patch is to avoid such a behavior. - private bool _isPreparingItemFlag = false; - private PropertyItemCollection _propertyItemCollection; - - public ObjectContainerHelperBase( IPropertyContainer propertyContainer) - : base( propertyContainer ) - { - _propertyItemCollection = new PropertyItemCollection( new ObservableCollection() ); - UpdateFilter(); - UpdateCategorization( false ); - - } - - public override IList Properties - { - get { return _propertyItemCollection; } - } - - private PropertyItem DefaultProperty - { - get - { - PropertyItem defaultProperty = null; - var defaultName = this.GetDefaultPropertyName(); - if( defaultName != null ) - { - defaultProperty = _propertyItemCollection - .FirstOrDefault( ( prop ) => object.Equals( defaultName, prop.PropertyDescriptor.Name ) ); - } - - return defaultProperty; - } - } - - - protected PropertyItemCollection PropertyItems - { - get - { - return _propertyItemCollection; - } - } - - public override PropertyItemBase ContainerFromItem( object item ) - { - if( item == null ) - return null; - // Exception case for ObjectContainerHelperBase. The "Item" may sometimes - // be identified as a string representing the property name or - // the PropertyItem itself. - Debug.Assert( item is PropertyItem || item is string ); - - var propertyItem = item as PropertyItem; - if( propertyItem != null ) - return propertyItem; - - - var propertyStr = item as string; - if( propertyStr != null ) - return PropertyItems.FirstOrDefault( ( prop ) => propertyStr == prop.PropertyDescriptor.Name ); - - return null; - } - - public override object ItemFromContainer( PropertyItemBase container ) - { - // Since this call is only used to update the PropertyGrid.SelectedProperty property, - // return the PropertyName. - var propertyItem = container as PropertyItem; - if( propertyItem == null ) - return null; - - return propertyItem.PropertyDescriptor.Name; - } - - public override void UpdateValuesFromSource() - { - foreach( PropertyItem item in PropertyItems ) - { - item.DescriptorDefinition.UpdateValueFromSource(); - item.ContainerHelper.UpdateValuesFromSource(); - } - } - - public void GenerateProperties() - { - if( (PropertyItems.Count == 0) - ) - { - this.RegenerateProperties(); - } - } - - protected override void OnFilterChanged() - { - this.UpdateFilter(); - } - - protected override void OnCategorizationChanged() - { - UpdateCategorization( true ); - } - - protected override void OnAutoGeneratePropertiesChanged() - { - this.RegenerateProperties(); - } - - protected override void OnHideInheritedPropertiesChanged() - { - this.RegenerateProperties(); - } - - protected override void OnEditorDefinitionsChanged() - { - this.RegenerateProperties(); - } - - protected override void OnPropertyDefinitionsChanged() - { - this.RegenerateProperties(); - } - - - - - - - protected internal override void SetPropertiesExpansion( bool isExpanded ) - { - if( this.Properties.Count == 0 ) - { - this.GenerateProperties(); - } - - base.SetPropertiesExpansion( isExpanded ); - } - - protected internal override void SetPropertiesExpansion( string propertyName, bool isExpanded ) - { - if( this.Properties.Count == 0 ) - { - this.GenerateProperties(); - } - - base.SetPropertiesExpansion( propertyName, isExpanded ); - } - - private void UpdateFilter() - { - FilterInfo filterInfo = this.PropertyContainer.FilterInfo; - - this.PropertyItems.FilterPredicate = filterInfo.Predicate - ?? PropertyItemCollection.CreateFilter( filterInfo.InputString, this.PropertyItems, this.PropertyContainer ); - } - - private void UpdateCategorization( bool updateSubPropertiesCategorization ) - { - _propertyItemCollection.UpdateCategorization( this.ComputeCategoryGroupDescription(), this.PropertyContainer.IsCategorized, this.PropertyContainer.IsSortedAlphabetically ); - if( updateSubPropertiesCategorization && (_propertyItemCollection.Count > 0) ) - { - foreach( PropertyItem propertyItem in _propertyItemCollection ) - { - PropertyItemCollection subPropertyItemsCollection = propertyItem.Properties as PropertyItemCollection; - if( subPropertyItemsCollection != null ) - { - subPropertyItemsCollection.UpdateCategorization( this.ComputeCategoryGroupDescription(), this.PropertyContainer.IsCategorized, this.PropertyContainer.IsSortedAlphabetically ); - } - } - } - } - - private GroupDescription ComputeCategoryGroupDescription() - { - if( !PropertyContainer.IsCategorized ) - return null; - return new PropertyGroupDescription( PropertyItemCollection.CategoryPropertyName ); - } - - private string GetCategoryGroupingPropertyName() - { - var propGroup = this.ComputeCategoryGroupDescription() as PropertyGroupDescription; - return ( propGroup != null ) ? propGroup.PropertyName : null; - } - - private void OnChildrenPropertyChanged( object sender, PropertyChangedEventArgs e ) - { - if( ObjectContainerHelperBase.IsItemOrderingProperty( e.PropertyName ) - || this.GetCategoryGroupingPropertyName() == e.PropertyName ) - { - // Refreshing the view while Containers are generated will throw an exception - if( this.ChildrenItemsControl.ItemContainerGenerator.Status != GeneratorStatus.GeneratingContainers - && !_isPreparingItemFlag ) - { - PropertyItems.RefreshView(); - } - } - } - - protected abstract string GetDefaultPropertyName(); - - protected abstract void GenerateSubPropertiesCore( Action> updatePropertyItemsCallback ); - - private void RegenerateProperties() - { - this.GenerateSubPropertiesCore( this.UpdatePropertyItemsCallback ); - } - - protected internal virtual void UpdatePropertyItemsCallback( IEnumerable subProperties ) - { - foreach( var propertyItem in subProperties ) - { - this.InitializePropertyItem( propertyItem ); - } - - //Remove the event callback from the previous children (if any) - foreach( var propertyItem in PropertyItems ) - { - propertyItem.PropertyChanged -= OnChildrenPropertyChanged; - } - - PropertyItems.UpdateItems( subProperties ); - - //Add the event callback to the new childrens - foreach( var propertyItem in PropertyItems ) - { - propertyItem.PropertyChanged += OnChildrenPropertyChanged; - } - - // Update the selected property on the property grid only. - PropertyGrid propertyGrid = PropertyContainer as PropertyGrid; - if( propertyGrid != null ) - { - propertyGrid.SelectedPropertyItem = this.DefaultProperty; - } - - if( ObjectsGenerated != null ) - { - ObjectsGenerated( this, EventArgs.Empty ); - } - } - - protected static List GetPropertyDescriptors( object instance, bool hideInheritedProperties ) - { - PropertyDescriptorCollection descriptors = null; - - TypeConverter tc = TypeDescriptor.GetConverter( instance ); - if( tc == null || !tc.GetPropertiesSupported() ) - { - if( instance is ICustomTypeDescriptor ) - { - descriptors = ((ICustomTypeDescriptor)instance).GetProperties(); - } - //ICustomTypeProvider is only available in .net 4.5 and over. Use reflection so the .net 4.0 and .net 3.5 still works. - else if( instance.GetType().GetInterface( "ICustomTypeProvider", true ) != null ) - { - var methodInfo = instance.GetType().GetMethod( "GetCustomType" ); - var result = methodInfo.Invoke( instance, null ) as Type; - descriptors = TypeDescriptor.GetProperties( result ); - } - else - { - descriptors = TypeDescriptor.GetProperties( instance.GetType() ); - } - } - else - { - try - { - descriptors = tc.GetProperties( instance ); - } - catch( Exception ) - { - } - } - - if( ( descriptors != null ) ) - { - var descriptorsProperties = descriptors.Cast(); - if( hideInheritedProperties ) - { - var properties = from p in descriptorsProperties - where p.ComponentType == instance.GetType() - select p; - return properties.ToList(); - } - else - { - return descriptorsProperties.ToList(); - } - } - - return null; - } - - - - - protected bool GetWillRefreshPropertyGrid( PropertyDescriptor propertyDescriptor ) - { - if( propertyDescriptor == null ) - return false; - - var attribute = PropertyGridUtilities.GetAttribute( propertyDescriptor ); - if( attribute != null ) - return attribute.RefreshProperties != RefreshProperties.None; - - return false; - } - - internal void InitializeDescriptorDefinition( - DescriptorPropertyDefinitionBase descriptorDef, - PropertyDefinition propertyDefinition ) - { - if( descriptorDef == null ) - throw new ArgumentNullException( "descriptorDef" ); - - if( propertyDefinition == null ) - return; - - // Values defined on PropertyDefinition have priority on the attributes - if( propertyDefinition != null ) - { - if( propertyDefinition.Category != null ) - { - descriptorDef.Category = propertyDefinition.Category; - descriptorDef.CategoryValue = propertyDefinition.Category; - } - - if( propertyDefinition.Description != null ) - { - descriptorDef.Description = propertyDefinition.Description; - } - if( propertyDefinition.DisplayName != null ) - { - descriptorDef.DisplayName = propertyDefinition.DisplayName; - } - - if( propertyDefinition.DisplayOrder != null ) - { - descriptorDef.DisplayOrder = propertyDefinition.DisplayOrder.Value; - } - - if( propertyDefinition.IsExpandable != null ) - { - descriptorDef.ExpandableAttribute = propertyDefinition.IsExpandable.Value; - } - } - } - - private void InitializePropertyItem( PropertyItem propertyItem ) - { - DescriptorPropertyDefinitionBase pd = propertyItem.DescriptorDefinition; - propertyItem.PropertyDescriptor = pd.PropertyDescriptor; - - propertyItem.IsReadOnly = pd.IsReadOnly; - propertyItem.DisplayName = pd.DisplayName; - propertyItem.Description = pd.Description; - - propertyItem.Category = pd.Category; - propertyItem.PropertyOrder = pd.DisplayOrder; - - //These properties can vary with the value. They need to be bound. - if( pd.PropertyDescriptor.Converter is ExpandableObjectConverter ) - { - propertyItem.IsExpandable = true; - } - else - { - SetupDefinitionBinding( propertyItem, PropertyItemBase.IsExpandableProperty, pd, () => pd.IsExpandable, BindingMode.OneWay ); - } - SetupDefinitionBinding( propertyItem, PropertyItemBase.AdvancedOptionsIconProperty, pd, () => pd.AdvancedOptionsIcon, BindingMode.OneWay ); - SetupDefinitionBinding( propertyItem, PropertyItemBase.AdvancedOptionsTooltipProperty, pd, () => pd.AdvancedOptionsTooltip, BindingMode.OneWay ); - SetupDefinitionBinding( propertyItem, PropertyItem.ValueProperty, pd, () => pd.Value, BindingMode.TwoWay ); - - if( pd.CommandBindings != null ) - { - foreach( CommandBinding commandBinding in pd.CommandBindings ) - { - propertyItem.CommandBindings.Add( commandBinding ); - } - } - } - - private object GetTypeDefaultValue( Type type ) - { - if( type.IsGenericType && type.GetGenericTypeDefinition() == typeof( Nullable<> ) ) - { - type = type.GetProperty( "Value" ).PropertyType; - } - - return ( type.IsValueType ? Activator.CreateInstance( type ) : null ) ; - } - - private void SetupDefinitionBinding( - PropertyItem propertyItem, - DependencyProperty itemProperty, - DescriptorPropertyDefinitionBase pd, - Expression> definitionProperty, - BindingMode bindingMode ) - { - string sourceProperty = ReflectionHelper.GetPropertyOrFieldName( definitionProperty ); - Binding binding = new Binding( sourceProperty ) - { - Source = pd, - Mode = bindingMode - }; - - propertyItem.SetBinding( itemProperty, binding ); - } - - internal FrameworkElement GenerateChildrenEditorElement( PropertyItem propertyItem ) - { - FrameworkElement editorElement = null; - DescriptorPropertyDefinitionBase pd = propertyItem.DescriptorDefinition; - object definitionKey = null; - Type definitionKeyAsType = definitionKey as Type; - ITypeEditor editor = null; - - if( editor == null ) - editor = pd.CreateAttributeEditor(); - - if( editor != null ) - editorElement = editor.ResolveEditor( propertyItem ); - - - if( (editorElement == null) && (definitionKey == null) && ( propertyItem.PropertyDescriptor != null ) ) - editorElement = this.GenerateCustomEditingElement( propertyItem.PropertyDescriptor.Name, propertyItem ); - - if( editorElement == null && definitionKeyAsType == null ) - editorElement = this.GenerateCustomEditingElement( propertyItem.PropertyType, propertyItem ); - - if( editorElement == null ) - { - if( propertyItem.IsReadOnly ) - editor = new TextBlockEditor(); - - // Fallback: Use a default type editor. - if( editor == null ) - { - editor = ( definitionKeyAsType != null ) - ? PropertyGridUtilities.CreateDefaultEditor( definitionKeyAsType, null, propertyItem ) - : pd.CreateDefaultEditor( propertyItem ); - } - - Debug.Assert( editor != null ); - - editorElement = editor.ResolveEditor( propertyItem ); - } - - return editorElement; - } - - internal PropertyDefinition GetPropertyDefinition( PropertyDescriptor descriptor ) - { - PropertyDefinition def = null; - - var propertyDefs = this.PropertyContainer.PropertyDefinitions; - if( propertyDefs != null ) - { - def = propertyDefs[ descriptor.Name ]; - if( def == null ) - { - def = propertyDefs.GetRecursiveBaseTypes( descriptor.PropertyType ); - } - } - - return def; - } - - - public override void PrepareChildrenPropertyItem( PropertyItemBase propertyItem, object item ) - { - _isPreparingItemFlag = true; - base.PrepareChildrenPropertyItem( propertyItem, item ); - - if( propertyItem.Editor == null ) - { - FrameworkElement editor = this.GenerateChildrenEditorElement( ( PropertyItem )propertyItem ); - if( editor != null ) - { - // Tag the editor as generated to know if we should clear it. - ContainerHelperBase.SetIsGenerated( editor, true ); - propertyItem.Editor = editor; - } - } - _isPreparingItemFlag = false; - } - - public override void ClearChildrenPropertyItem( PropertyItemBase propertyItem, object item ) - { - if( propertyItem.Editor != null - && ContainerHelperBase.GetIsGenerated( propertyItem.Editor ) ) - { - propertyItem.Editor = null; - } - - base.ClearChildrenPropertyItem( propertyItem, item ); - } - - public override Binding CreateChildrenDefaultBinding( PropertyItemBase propertyItem ) - { - Binding binding = new Binding( "Value" ); - binding.Mode = ( ( ( PropertyItem )propertyItem ).IsReadOnly ) ? BindingMode.OneWay : BindingMode.TwoWay; - return binding; - } - - protected static string GetDefaultPropertyName( object instance ) - { - AttributeCollection attributes = TypeDescriptor.GetAttributes( instance ); - DefaultPropertyAttribute defaultPropertyAttribute = ( DefaultPropertyAttribute )attributes[ typeof( DefaultPropertyAttribute ) ]; - return defaultPropertyAttribute != null ? defaultPropertyAttribute.Name : null; - } - - private static bool IsItemOrderingProperty( string propertyName ) - { - return string.Equals( propertyName, PropertyItemCollection.DisplayNamePropertyName ) - || string.Equals( propertyName, PropertyItemCollection.CategoryOrderPropertyName ) - || string.Equals( propertyName, PropertyItemCollection.PropertyOrderPropertyName ); - } - - internal event EventHandler ObjectsGenerated; - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyDefinition.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyDefinition.cs deleted file mode 100644 index 6bdef100..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyDefinition.cs +++ /dev/null @@ -1,122 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - public class PropertyDefinition : PropertyDefinitionBase - { - private string _name; - private bool? _isBrowsable = true; - private bool? _isExpandable = null; - private string _displayName = null; - private string _description = null; - private string _category = null; - private int? _displayOrder = null; - - [Obsolete(@"Use 'TargetProperties' instead of 'Name'")] - public string Name - { - get { return _name; } - set - { - const string usageError = "{0}: \'Name\' property is obsolete. Instead use \'TargetProperties\'. (XAML example: )"; - System.Diagnostics.Trace.TraceWarning( usageError, typeof( PropertyDefinition ) ); - _name = value; - } - } - - public string Category - { - get { return _category; } - set - { - this.ThrowIfLocked( () => this.Category ); - _category = value; - } - } - - public string DisplayName - { - get { return _displayName; } - set - { - this.ThrowIfLocked( () => this.DisplayName ); - _displayName = value; - } - } - - public string Description - { - get { return _description; } - set - { - this.ThrowIfLocked( () => this.Description ); - _description = value; - } - } - - public int? DisplayOrder - { - get { return _displayOrder; } - set - { - this.ThrowIfLocked( () => this.DisplayOrder ); - _displayOrder = value; - } - } - - public bool? IsBrowsable - { - get { return _isBrowsable; } - set - { - this.ThrowIfLocked( () => this.IsBrowsable ); - _isBrowsable = value; - } - } - - public bool? IsExpandable - { - get { return _isExpandable; } - set - { - this.ThrowIfLocked( () => this.IsExpandable ); - _isExpandable = value; - } - } - - internal override void Lock() - { - if( _name != null - && this.TargetProperties != null - && this.TargetProperties.Count > 0 ) - { - throw new InvalidOperationException( - string.Format( - @"{0}: When using 'TargetProperties' property, do not use 'Name' property.", - typeof( PropertyDefinition ) ) ); - } - - if( _name != null ) - { - this.TargetProperties = new List() { _name }; - } - base.Lock(); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyDefinitionBaseCollection.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyDefinitionBaseCollection.cs deleted file mode 100644 index 69bf3bde..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyDefinitionBaseCollection.cs +++ /dev/null @@ -1,124 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Windows.Documents; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - public class PropertyDefinitionCollection : PropertyDefinitionBaseCollection - { - } - public class EditorDefinitionCollection : PropertyDefinitionBaseCollection - { - } - - - public abstract class PropertyDefinitionBaseCollection : DefinitionCollectionBase where T : PropertyDefinitionBase - { - protected PropertyDefinitionBaseCollection() - { - } - - public virtual T this[ object propertyId ] - { - get - { - foreach( var item in Items ) - { - if( item.TargetProperties.Contains( propertyId ) ) - return item; - - // Using the special character "*" in a string of TargetProperties will - // return all the items containing the string (before or after) the "*". - // ex : Prop* will return properties named Prop1, Prop2, Prop3... - List stringTargetProperties = item.TargetProperties.OfType().ToList(); - if( ( stringTargetProperties != null ) && ( stringTargetProperties.Count > 0 ) ) - { - if( propertyId is string ) - { - string stringPropertyID = ( string )propertyId; - foreach( var targetPropertyString in stringTargetProperties ) - { - if( targetPropertyString.Contains( "*" ) ) - { - string searchString = targetPropertyString.Replace( "*", "" ); - if( stringPropertyID.StartsWith( searchString ) || stringPropertyID.EndsWith( searchString ) ) - return item; - } - } - } - } - else - { - //Manage Interfaces - var type = propertyId as Type; - if( type != null ) - { - foreach( Type targetProperty in item.TargetProperties ) - { - if( targetProperty.IsAssignableFrom( type ) ) - return item; - } - } - } - } - - return null; - } - } - - internal T GetRecursiveBaseTypes( Type type ) - { - // If no definition for the current type, fall back on base type editor recursively. - T ret = null; - while( ret == null && type != null ) - { - ret = this[ type ]; - type = type.BaseType; - } - return ret; - } - } - - public abstract class DefinitionCollectionBase : ObservableCollection where T : DefinitionBase - { - internal DefinitionCollectionBase() - { - } - - protected override void InsertItem( int index, T item ) - { - if( item == null ) - throw new InvalidOperationException( @"Cannot insert null items in the collection." ); - - item.Lock(); - base.InsertItem( index, item ); - } - - protected override void SetItem( int index, T item ) - { - if( item == null ) - throw new InvalidOperationException( @"Cannot insert null items in the collection." ); - - item.Lock(); - base.SetItem( index, item ); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyGrid.Icon.bmp b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyGrid.Icon.bmp deleted file mode 100644 index 76f9520f..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyGrid.Icon.bmp and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyGrid.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyGrid.cs deleted file mode 100644 index de577b5f..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyGrid.cs +++ /dev/null @@ -1,1681 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Controls.Primitives; -using System.Windows.Data; -using System.Windows.Input; -using Xceed.Wpf.Toolkit.PropertyGrid.Commands; -using System.Collections.Specialized; -using System.Windows.Media; -using System.Collections.ObjectModel; -using System.Collections; -using Xceed.Wpf.Toolkit.Core.Utilities; -using System.Linq.Expressions; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - [TemplatePart( Name = PART_DragThumb, Type = typeof( Thumb ) )] - [TemplatePart( Name = PART_PropertyItemsControl, Type = typeof( PropertyItemsControl ) )] - [StyleTypedProperty( Property = "PropertyContainerStyle", StyleTargetType = typeof( PropertyItemBase ) )] - public class PropertyGrid : Control, ISupportInitialize, IPropertyContainer, INotifyPropertyChanged - { - private const string PART_DragThumb = "PART_DragThumb"; - internal const string PART_PropertyItemsControl = "PART_PropertyItemsControl"; - private static readonly ComponentResourceKey SelectedObjectAdvancedOptionsMenuKey = new ComponentResourceKey( typeof( PropertyGrid ), "SelectedObjectAdvancedOptionsMenu" ); - - #region Members - - private Thumb _dragThumb; - private bool _hasPendingSelectedObjectChanged; - private int _initializationCount; - private ContainerHelperBase _containerHelper; - private WeakEventListener _propertyDefinitionsListener; - private WeakEventListener _editorDefinitionsListener; - - #endregion //Members - - #region Properties - - #region AdvancedOptionsMenu - - public static readonly DependencyProperty AdvancedOptionsMenuProperty = DependencyProperty.Register( "AdvancedOptionsMenu", typeof( ContextMenu ), typeof( PropertyGrid ), new UIPropertyMetadata( null ) ); - public ContextMenu AdvancedOptionsMenu - { - get - { - return ( ContextMenu )GetValue( AdvancedOptionsMenuProperty ); - } - set - { - SetValue( AdvancedOptionsMenuProperty, value ); - } - } - - #endregion //AdvancedOptionsMenu - - #region AutoGenerateProperties - - public static readonly DependencyProperty AutoGeneratePropertiesProperty = DependencyProperty.Register( "AutoGenerateProperties", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( true ) ); - public bool AutoGenerateProperties - { - get - { - return ( bool )GetValue( AutoGeneratePropertiesProperty ); - } - set - { - SetValue( AutoGeneratePropertiesProperty, value ); - } - } - - #endregion //AutoGenerateProperties - - #region CategoryGroupHeaderTemplate - - public static readonly DependencyProperty CategoryGroupHeaderTemplateProperty = DependencyProperty.Register( "CategoryGroupHeaderTemplate", typeof( DataTemplate ), typeof( PropertyGrid ) ); - public DataTemplate CategoryGroupHeaderTemplate - { - get - { - return (DataTemplate)GetValue( CategoryGroupHeaderTemplateProperty ); - } - set - { - SetValue( CategoryGroupHeaderTemplateProperty, value ); - } - } - - #endregion //CategoryGroupHeaderTemplate - - #region ShowDescriptionByTooltip - - public static readonly DependencyProperty ShowDescriptionByTooltipProperty = DependencyProperty.Register( "ShowDescriptionByTooltip", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( false ) ); - public bool ShowDescriptionByTooltip - { - get - { - return ( bool )GetValue( ShowDescriptionByTooltipProperty ); - } - set - { - SetValue( ShowDescriptionByTooltipProperty, value ); - } - } - - #endregion //ShowDescriptionByTooltip - - #region ShowSummary - - public static readonly DependencyProperty ShowSummaryProperty = DependencyProperty.Register( "ShowSummary", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( true ) ); - public bool ShowSummary - { - get - { - return ( bool )GetValue( ShowSummaryProperty ); - } - set - { - SetValue( ShowSummaryProperty, value ); - } - } - - #endregion //ShowSummary - - #region EditorDefinitions - - public static readonly DependencyProperty EditorDefinitionsProperty = DependencyProperty.Register( "EditorDefinitions", typeof( EditorDefinitionCollection ), typeof( PropertyGrid ) - , new UIPropertyMetadata( null, OnEditorDefinitionsChanged ) ); - public EditorDefinitionCollection EditorDefinitions - { - get - { - return ( EditorDefinitionCollection )GetValue( EditorDefinitionsProperty ); - } - set - { - SetValue( EditorDefinitionsProperty, value ); - } - } - - private static void OnEditorDefinitionsChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PropertyGrid propertyGrid = o as PropertyGrid; - if( propertyGrid != null ) - propertyGrid.OnEditorDefinitionsChanged( ( EditorDefinitionCollection )e.OldValue, ( EditorDefinitionCollection )e.NewValue ); - } - - protected virtual void OnEditorDefinitionsChanged( EditorDefinitionCollection oldValue, EditorDefinitionCollection newValue ) - { - if( oldValue != null ) - CollectionChangedEventManager.RemoveListener( oldValue, _editorDefinitionsListener ); - - if( newValue != null ) - CollectionChangedEventManager.AddListener( newValue, _editorDefinitionsListener ); - - this.Notify( this.PropertyChanged, () => this.EditorDefinitions ); - } - - private void OnEditorDefinitionsCollectionChanged( object sender, NotifyCollectionChangedEventArgs e ) - { - if( _containerHelper != null ) - { - _containerHelper.NotifyEditorDefinitionsCollectionChanged(); - } - } - - #endregion //EditorDefinitions - - #region Filter - - public static readonly DependencyProperty FilterProperty = DependencyProperty.Register( "Filter", typeof( string ), typeof( PropertyGrid ), new UIPropertyMetadata( null, OnFilterChanged ) ); - public string Filter - { - get - { - return ( string )GetValue( FilterProperty ); - } - set - { - SetValue( FilterProperty, value ); - } - } - - private static void OnFilterChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PropertyGrid propertyGrid = o as PropertyGrid; - if( propertyGrid != null ) - propertyGrid.OnFilterChanged( ( string )e.OldValue, ( string )e.NewValue ); - } - - protected virtual void OnFilterChanged( string oldValue, string newValue ) - { - // The Filter property affects the resulting FilterInfo of IPropertyContainer. Raise an event corresponding - // to this property. - this.Notify( this.PropertyChanged, () => ( ( IPropertyContainer )this ).FilterInfo ); - } - - #endregion //Filter - - #region FilterWatermark - - public static readonly DependencyProperty FilterWatermarkProperty = DependencyProperty.Register( "FilterWatermark", typeof( string ), typeof( PropertyGrid ), new UIPropertyMetadata( "Search" ) ); - public string FilterWatermark - { - get - { - return ( string )GetValue( FilterWatermarkProperty ); - } - set - { - SetValue( FilterWatermarkProperty, value ); - } - } - - #endregion //FilterWatermark - - #region HideInheritedProperties - - public static readonly DependencyProperty HideInheritedPropertiesProperty = DependencyProperty.Register( "HideInheritedProperties", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( false ) ); - public bool HideInheritedProperties - { - get - { - return ( bool )GetValue( HideInheritedPropertiesProperty ); - } - set - { - SetValue( HideInheritedPropertiesProperty, value ); - } - } - - #endregion //HideInheritedProperties - - #region IsCategorized - - public static readonly DependencyProperty IsCategorizedProperty = DependencyProperty.Register( "IsCategorized", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( true, OnIsCategorizedChanged ) ); - public bool IsCategorized - { - get - { - return ( bool )GetValue( IsCategorizedProperty ); - } - set - { - SetValue( IsCategorizedProperty, value ); - } - } - - private static void OnIsCategorizedChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PropertyGrid propertyGrid = o as PropertyGrid; - if( propertyGrid != null ) - propertyGrid.OnIsCategorizedChanged( ( bool )e.OldValue, ( bool )e.NewValue ); - } - - protected virtual void OnIsCategorizedChanged( bool oldValue, bool newValue ) - { - this.UpdateThumb(); - } - - #endregion //IsCategorized - - #region IsMiscCategoryLabelHidden - - public static readonly DependencyProperty IsMiscCategoryLabelHiddenProperty = DependencyProperty.Register( "IsMiscCategoryLabelHidden", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( false ) ); - public bool IsMiscCategoryLabelHidden - { - get - { - return ( bool )GetValue( IsMiscCategoryLabelHiddenProperty ); - } - set - { - SetValue( IsMiscCategoryLabelHiddenProperty, value ); - } - } - - #endregion //IsMiscCategoryLabelHidden - - #region IsScrollingToTopAfterRefresh - - public static readonly DependencyProperty IsScrollingToTopAfterRefreshProperty = DependencyProperty.Register( "IsScrollingToTopAfterRefresh", typeof( bool ), typeof( PropertyGrid ) - , new UIPropertyMetadata( true ) ); - public bool IsScrollingToTopAfterRefresh - { - get - { - return ( bool )GetValue( IsScrollingToTopAfterRefreshProperty ); - } - set - { - SetValue( IsScrollingToTopAfterRefreshProperty, value ); - } - } - - #endregion //IsScrollingToTopAfterRefresh - - #region IsVirtualizing - - public static readonly DependencyProperty IsVirtualizingProperty = DependencyProperty.Register( "IsVirtualizing", typeof( bool ), typeof( PropertyGrid ) - , new UIPropertyMetadata( false, OnIsVirtualizingChanged ) ); - public bool IsVirtualizing - { - get - { - return ( bool )GetValue( IsVirtualizingProperty ); - } - set - { - SetValue( IsVirtualizingProperty, value ); - } - } - - private static void OnIsVirtualizingChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - var propertyGrid = o as PropertyGrid; - if( propertyGrid != null ) - propertyGrid.OnIsVirtualizingChanged( ( bool )e.OldValue, ( bool )e.NewValue ); - } - - protected virtual void OnIsVirtualizingChanged( bool oldValue, bool newValue ) - { - this.UpdateContainerHelper(); - } - - #endregion //IsVirtualizing - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #region NameColumnWidth - - public static readonly DependencyProperty NameColumnWidthProperty = DependencyProperty.Register( "NameColumnWidth", typeof( double ), typeof( PropertyGrid ), new UIPropertyMetadata( 150.0, OnNameColumnWidthChanged ) ); - public double NameColumnWidth - { - get - { - return ( double )GetValue( NameColumnWidthProperty ); - } - set - { - SetValue( NameColumnWidthProperty, value ); - } - } - - private static void OnNameColumnWidthChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PropertyGrid propertyGrid = o as PropertyGrid; - if( propertyGrid != null ) - propertyGrid.OnNameColumnWidthChanged( ( double )e.OldValue, ( double )e.NewValue ); - } - - protected virtual void OnNameColumnWidthChanged( double oldValue, double newValue ) - { - if( _dragThumb != null ) - ( ( TranslateTransform )_dragThumb.RenderTransform ).X = newValue; - } - - #endregion //NameColumnWidth - - #region PropertyNameLeftPadding - - public static readonly DependencyProperty PropertyNameLeftPaddingProperty = DependencyProperty.Register( "PropertyNameLeftPadding", typeof( double ), typeof( PropertyGrid ), new UIPropertyMetadata( 15.0 ) ); - public double PropertyNameLeftPadding - { - get - { - return (double)GetValue( PropertyNameLeftPaddingProperty ); - } - set - { - SetValue( PropertyNameLeftPaddingProperty, value ); - } - } - - #endregion //PropertyNameLeftPadding - - #region Properties - - public IList Properties - { - get - { - return (_containerHelper != null) ? _containerHelper.Properties : null; - } - } - - #endregion //Properties - - - - - - - - - #region PropertyContainerStyle - - /// - /// Identifies the PropertyContainerStyle dependency property - /// - public static readonly DependencyProperty PropertyContainerStyleProperty = - DependencyProperty.Register( "PropertyContainerStyle", typeof( Style ), typeof( PropertyGrid ), new UIPropertyMetadata( null, OnPropertyContainerStyleChanged ) ); - - /// - /// Gets or sets the style that will be applied to all PropertyItemBase instances displayed in the property grid. - /// - public Style PropertyContainerStyle - { - get { return ( Style )GetValue( PropertyContainerStyleProperty ); } - set { SetValue( PropertyContainerStyleProperty, value ); } - } - - private static void OnPropertyContainerStyleChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - var owner = o as PropertyGrid; - if( owner != null ) - owner.OnPropertyContainerStyleChanged( ( Style )e.OldValue, ( Style )e.NewValue ); - } - - protected virtual void OnPropertyContainerStyleChanged( Style oldValue, Style newValue ) - { - } - - #endregion //PropertyContainerStyle - - #region PropertyDefinitions - - public static readonly DependencyProperty PropertyDefinitionsProperty = - DependencyProperty.Register( "PropertyDefinitions", typeof( PropertyDefinitionCollection ), typeof( PropertyGrid ), new UIPropertyMetadata( null, OnPropertyDefinitionsChanged ) ); - - public PropertyDefinitionCollection PropertyDefinitions - { - get - { - return (PropertyDefinitionCollection)GetValue( PropertyDefinitionsProperty ); - } - set - { - SetValue( PropertyDefinitionsProperty, value ); - } - } - - private static void OnPropertyDefinitionsChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - var owner = o as PropertyGrid; - if( owner != null ) - owner.OnPropertyDefinitionsChanged( (PropertyDefinitionCollection)e.OldValue, (PropertyDefinitionCollection)e.NewValue ); - } - - protected virtual void OnPropertyDefinitionsChanged( PropertyDefinitionCollection oldValue, PropertyDefinitionCollection newValue ) - { - if( oldValue != null ) - { - CollectionChangedEventManager.RemoveListener( oldValue, _propertyDefinitionsListener ); - } - - if( newValue != null ) - { - CollectionChangedEventManager.AddListener( newValue, _propertyDefinitionsListener ); - } - - this.Notify( this.PropertyChanged, () => this.PropertyDefinitions ); - } - - private void OnPropertyDefinitionsCollectionChanged( object sender, NotifyCollectionChangedEventArgs e ) - { - if( _containerHelper != null ) - { - _containerHelper.NotifyPropertyDefinitionsCollectionChanged(); - } - if( this.IsLoaded ) - { - this.UpdateContainerHelper(); - } - } - - #endregion //PropertyDefinitions - - #region IsReadOnly - - public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register( "IsReadOnly", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( false, OnIsReadOnlyChanged ) ); - public bool IsReadOnly - { - get - { - return ( bool )GetValue( IsReadOnlyProperty ); - } - set - { - SetValue( IsReadOnlyProperty, value ); - } - } - - private static void OnIsReadOnlyChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - var propertyGrid = o as PropertyGrid; - if( propertyGrid != null ) - propertyGrid.OnIsReadOnlyChanged( (bool)e.OldValue, (bool)e.NewValue ); - } - - protected virtual void OnIsReadOnlyChanged( bool oldValue, bool newValue ) - { - this.UpdateContainerHelper(); - } - - #endregion //ReadOnly - - #region SelectedObject - - public static readonly DependencyProperty SelectedObjectProperty = DependencyProperty.Register( "SelectedObject", typeof( object ), typeof( PropertyGrid ), new UIPropertyMetadata( null, OnSelectedObjectChanged ) ); - public object SelectedObject - { - get - { - return ( object )GetValue( SelectedObjectProperty ); - } - set - { - SetValue( SelectedObjectProperty, value ); - } - } - - private static void OnSelectedObjectChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PropertyGrid propertyInspector = o as PropertyGrid; - if( propertyInspector != null ) - propertyInspector.OnSelectedObjectChanged( ( object )e.OldValue, ( object )e.NewValue ); - } - - protected virtual void OnSelectedObjectChanged( object oldValue, object newValue ) - { - // We do not want to process the change now if the grid is initializing (ie. BeginInit/EndInit). - if( _initializationCount != 0 ) - { - _hasPendingSelectedObjectChanged = true; - return; - } - - this.UpdateContainerHelper(); - - RaiseEvent( new RoutedPropertyChangedEventArgs( oldValue, newValue, PropertyGrid.SelectedObjectChangedEvent ) ); - } - - #endregion //SelectedObject - - #region SelectedObjectType - - public static readonly DependencyProperty SelectedObjectTypeProperty = DependencyProperty.Register( "SelectedObjectType", typeof( Type ), typeof( PropertyGrid ), new UIPropertyMetadata( null, OnSelectedObjectTypeChanged ) ); - public Type SelectedObjectType - { - get - { - return ( Type )GetValue( SelectedObjectTypeProperty ); - } - set - { - SetValue( SelectedObjectTypeProperty, value ); - } - } - - private static void OnSelectedObjectTypeChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PropertyGrid propertyGrid = o as PropertyGrid; - if( propertyGrid != null ) - propertyGrid.OnSelectedObjectTypeChanged( ( Type )e.OldValue, ( Type )e.NewValue ); - } - - protected virtual void OnSelectedObjectTypeChanged( Type oldValue, Type newValue ) - { - } - - #endregion //SelectedObjectType - - #region SelectedObjectTypeName - - public static readonly DependencyProperty SelectedObjectTypeNameProperty = DependencyProperty.Register( "SelectedObjectTypeName", typeof( string ), typeof( PropertyGrid ), new UIPropertyMetadata( string.Empty ) ); - public string SelectedObjectTypeName - { - get - { - return ( string )GetValue( SelectedObjectTypeNameProperty ); - } - set - { - SetValue( SelectedObjectTypeNameProperty, value ); - } - } - - #endregion //SelectedObjectTypeName - - #region SelectedObjectName - - public static readonly DependencyProperty SelectedObjectNameProperty = DependencyProperty.Register( "SelectedObjectName", typeof( string ), typeof( PropertyGrid ), new UIPropertyMetadata( string.Empty, OnSelectedObjectNameChanged, OnCoerceSelectedObjectName ) ); - public string SelectedObjectName - { - get - { - return ( string )GetValue( SelectedObjectNameProperty ); - } - set - { - SetValue( SelectedObjectNameProperty, value ); - } - } - - private static object OnCoerceSelectedObjectName( DependencyObject o, object baseValue ) - { - PropertyGrid propertyGrid = o as PropertyGrid; - if( propertyGrid != null ) - { - if( (propertyGrid.SelectedObject is FrameworkElement) && ( String.IsNullOrEmpty( ( String )baseValue ) )) - return ""; - } - - return baseValue; - } - - private static void OnSelectedObjectNameChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PropertyGrid propertyGrid = o as PropertyGrid; - if( propertyGrid != null ) - propertyGrid.SelectedObjectNameChanged( ( string )e.OldValue, ( string )e.NewValue ); - } - - protected virtual void SelectedObjectNameChanged( string oldValue, string newValue ) - { - } - - #endregion //SelectedObjectName - - - - - - - - - - - - - - #region SelectedPropertyItem - - private static readonly DependencyPropertyKey SelectedPropertyItemPropertyKey = DependencyProperty.RegisterReadOnly( "SelectedPropertyItem", typeof( PropertyItemBase ), typeof( PropertyGrid ), new UIPropertyMetadata( null, OnSelectedPropertyItemChanged ) ); - public static readonly DependencyProperty SelectedPropertyItemProperty = SelectedPropertyItemPropertyKey.DependencyProperty; - public PropertyItemBase SelectedPropertyItem - { - get - { - return ( PropertyItemBase )GetValue( SelectedPropertyItemProperty ); - } - internal set - { - SetValue( SelectedPropertyItemPropertyKey, value ); - } - } - - private static void OnSelectedPropertyItemChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PropertyGrid propertyGrid = o as PropertyGrid; - if( propertyGrid != null ) - propertyGrid.OnSelectedPropertyItemChanged( ( PropertyItemBase )e.OldValue, ( PropertyItemBase )e.NewValue ); - } - - protected virtual void OnSelectedPropertyItemChanged( PropertyItemBase oldValue, PropertyItemBase newValue ) - { - if( oldValue != null ) - oldValue.IsSelected = false; - - if( newValue != null ) - newValue.IsSelected = true; - - this.SelectedProperty = ( (newValue != null) && (_containerHelper != null) ) ? _containerHelper.ItemFromContainer( newValue ) : null; - - RaiseEvent( new RoutedPropertyChangedEventArgs( oldValue, newValue, PropertyGrid.SelectedPropertyItemChangedEvent ) ); - } - - #endregion //SelectedPropertyItem - - #region SelectedProperty - - /// - /// Identifies the SelectedProperty dependency property - /// - public static readonly DependencyProperty SelectedPropertyProperty = - DependencyProperty.Register( "SelectedProperty", typeof( object ), typeof( PropertyGrid ), new UIPropertyMetadata( null, OnSelectedPropertyChanged ) ); - - /// - /// Gets or sets the selected property or returns null if the selection is empty. - /// - public object SelectedProperty - { - get { return ( object )GetValue( SelectedPropertyProperty ); } - set { SetValue( SelectedPropertyProperty, value ); } - } - - private static void OnSelectedPropertyChanged( DependencyObject sender, DependencyPropertyChangedEventArgs args ) - { - PropertyGrid propertyGrid = sender as PropertyGrid; - if( propertyGrid != null ) - { - propertyGrid.OnSelectedPropertyChanged( ( object )args.OldValue, ( object )args.NewValue ); - } - } - - private void OnSelectedPropertyChanged( object oldValue, object newValue ) - { - // Do not update the SelectedPropertyItem if the Current SelectedPropertyItem - // item is the same as the new SelectedProperty. There may be - // duplicate items and the result could be to change the selection to the wrong item. - if( _containerHelper != null ) - { - object currentSelectedProperty = _containerHelper.ItemFromContainer( this.SelectedPropertyItem ); - if( !object.Equals( currentSelectedProperty, newValue ) ) - { - this.SelectedPropertyItem = _containerHelper.ContainerFromItem( newValue ); - } - } - } - - #endregion //SelectedProperty - - #region ShowAdvancedOptions - - public static readonly DependencyProperty ShowAdvancedOptionsProperty = DependencyProperty.Register( "ShowAdvancedOptions", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( false ) ); - public bool ShowAdvancedOptions - { - get - { - return ( bool )GetValue( ShowAdvancedOptionsProperty ); - } - set - { - SetValue( ShowAdvancedOptionsProperty, value ); - } - } - - #endregion //ShowAdvancedOptions - - #region ShowHorizontalScrollBar - - public static readonly DependencyProperty ShowHorizontalScrollBarProperty = DependencyProperty.Register( "ShowHorizontalScrollBar", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( false ) ); - public bool ShowHorizontalScrollBar - { - get - { - return ( bool )GetValue( ShowHorizontalScrollBarProperty ); - } - set - { - SetValue( ShowHorizontalScrollBarProperty, value ); - } - } - - #endregion //ShowHorizontalScrollBar - - #region ShowPreview - - public static readonly DependencyProperty ShowPreviewProperty = DependencyProperty.Register( "ShowPreview", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( false ) ); - public bool ShowPreview - { - get - { - return ( bool )GetValue( ShowPreviewProperty ); - } - set - { - SetValue( ShowPreviewProperty, value ); - } - } - - #endregion //ShowPreview - - #region ShowSearchBox - - public static readonly DependencyProperty ShowSearchBoxProperty = DependencyProperty.Register( "ShowSearchBox", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( true ) ); - public bool ShowSearchBox - { - get - { - return ( bool )GetValue( ShowSearchBoxProperty ); - } - set - { - SetValue( ShowSearchBoxProperty, value ); - } - } - - #endregion //ShowSearchBox - - #region ShowSortOptions - - public static readonly DependencyProperty ShowSortOptionsProperty = DependencyProperty.Register( "ShowSortOptions", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( true ) ); - public bool ShowSortOptions - { - get - { - return ( bool )GetValue( ShowSortOptionsProperty ); - } - set - { - SetValue( ShowSortOptionsProperty, value ); - } - } - - #endregion //ShowSortOptions - - #region ShowTitle - - public static readonly DependencyProperty ShowTitleProperty = DependencyProperty.Register( "ShowTitle", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( true ) ); - public bool ShowTitle - { - get - { - return ( bool )GetValue( ShowTitleProperty ); - } - set - { - SetValue( ShowTitleProperty, value ); - } - } - - #endregion //ShowTitle - - #region UpdateTextBoxSourceOnEnterKey - - public static readonly DependencyProperty UpdateTextBoxSourceOnEnterKeyProperty = DependencyProperty.Register( "UpdateTextBoxSourceOnEnterKey", typeof( bool ), typeof( PropertyGrid ), new UIPropertyMetadata( true ) ); - public bool UpdateTextBoxSourceOnEnterKey - { - get - { - return ( bool )GetValue( UpdateTextBoxSourceOnEnterKeyProperty ); - } - set - { - SetValue( UpdateTextBoxSourceOnEnterKeyProperty, value ); - } - } - - #endregion //UpdateTextBoxSourceOnEnterKey - - #endregion //Properties - - #region Constructors - - static PropertyGrid() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyGrid ), new FrameworkPropertyMetadata( typeof( PropertyGrid ) ) ); - } - - public PropertyGrid() - { - _propertyDefinitionsListener = new WeakEventListener( this.OnPropertyDefinitionsCollectionChanged ); - _editorDefinitionsListener = new WeakEventListener( this.OnEditorDefinitionsCollectionChanged); - UpdateContainerHelper(); -#if VS2008 - EditorDefinitions = new EditorDefinitionCollection(); -#else - this.SetCurrentValue( PropertyGrid.EditorDefinitionsProperty, new EditorDefinitionCollection() ); -#endif - - PropertyDefinitions = new PropertyDefinitionCollection(); - this.PropertyValueChanged += this.PropertyGrid_PropertyValueChanged; - - AddHandler( PropertyItemBase.ItemSelectionChangedEvent, new RoutedEventHandler( OnItemSelectionChanged ) ); - AddHandler( PropertyItemsControl.PreparePropertyItemEvent, new PropertyItemEventHandler( OnPreparePropertyItemInternal ) ); - AddHandler( PropertyItemsControl.ClearPropertyItemEvent, new PropertyItemEventHandler( OnClearPropertyItemInternal ) ); - CommandBindings.Add( new CommandBinding( PropertyGridCommands.ClearFilter, ClearFilter, CanClearFilter ) ); - } - - #endregion //Constructors - - #region Base Class Overrides - - public override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - if( _dragThumb != null ) - _dragThumb.DragDelta -= DragThumb_DragDelta; - _dragThumb = GetTemplateChild( PART_DragThumb ) as Thumb; - if( _dragThumb != null ) - _dragThumb.DragDelta += DragThumb_DragDelta; - - if( _containerHelper != null ) - { - _containerHelper.ChildrenItemsControl = GetTemplateChild( PART_PropertyItemsControl ) as PropertyItemsControl; - } - - //Update TranslateTransform in code-behind instead of XAML to remove the - //output window error. - //When we use FindAncesstor in custom control template for binding internal elements property - //into its ancestor element, Visual Studio displays data warning messages in output window when - //binding engine meets unmatched target type during visual tree traversal though it does the proper - //binding when it receives expected target type during visual tree traversal - //ref : http://www.codeproject.com/Tips/124556/How-to-suppress-the-System-Windows-Data-Error-warn - TranslateTransform _moveTransform = new TranslateTransform(); - _moveTransform.X = NameColumnWidth; - if( _dragThumb != null ) - { - _dragThumb.RenderTransform = _moveTransform; - } - - this.UpdateThumb(); - } - - protected override void OnPreviewKeyDown( KeyEventArgs e ) - { - var textBox = e.OriginalSource as TextBox; - - //hitting enter on textbox will update value of underlying source if UpdateTextBoxSourceOnEnterKey is true - if( (this.SelectedPropertyItem != null) - && (e.Key == Key.Enter) - && this.UpdateTextBoxSourceOnEnterKey - && (textBox != null) - && !textBox.AcceptsReturn ) - { - BindingExpression be = textBox.GetBindingExpression( TextBox.TextProperty ); - if( be != null ) - be.UpdateSource(); - } - } - - protected override void OnPropertyChanged( DependencyPropertyChangedEventArgs e ) - { - base.OnPropertyChanged( e ); - - // First check that the raised property is actually a real CLR property. - // This could be something else like a Attached DP. - if( ReflectionHelper.IsPublicInstanceProperty( GetType(), e.Property.Name ) ) - { - this.Notify( this.PropertyChanged, e.Property.Name ); - } - } - - -#endregion //Base Class Overrides - - #region Event Handlers - - private void OnItemSelectionChanged( object sender, RoutedEventArgs args ) - { - PropertyItemBase item = ( PropertyItemBase )args.OriginalSource; - if( item.IsSelected ) - { - SelectedPropertyItem = item; - } - else - { - if( object.ReferenceEquals( item, SelectedPropertyItem ) ) - { - SelectedPropertyItem = null; - } - } - } - - private void OnPreparePropertyItemInternal( object sender, PropertyItemEventArgs args ) - { - if( _containerHelper != null ) - { - _containerHelper.PrepareChildrenPropertyItem( args.PropertyItem, args.Item ); - } - args.Handled = true; - } - - private void OnClearPropertyItemInternal( object sender, PropertyItemEventArgs args ) - { - if( _containerHelper != null ) - { - _containerHelper.ClearChildrenPropertyItem( args.PropertyItem, args.Item ); - } - args.Handled = true; - } - - private void DragThumb_DragDelta( object sender, DragDeltaEventArgs e ) - { - NameColumnWidth = Math.Min( Math.Max( this.ActualWidth * 0.1, NameColumnWidth + e.HorizontalChange ), this.ActualWidth * 0.9 ); - } - - - private void PropertyGrid_PropertyValueChanged( object sender, PropertyValueChangedEventArgs e ) - { - var modifiedPropertyItem = e.OriginalSource as PropertyItem; - if( modifiedPropertyItem != null ) - { - // Need to refresh the PropertyGrid Properties. - if( modifiedPropertyItem.WillRefreshPropertyGrid ) - { - // Refresh the PropertyGrid...this will set the initial Categories states. - this.UpdateContainerHelper(); - } - - var parentPropertyItem = modifiedPropertyItem.ParentNode as PropertyItem; - if( ( parentPropertyItem != null ) && parentPropertyItem.IsExpandable ) - { - //Rebuild Editor for parent propertyItem if one of its sub-propertyItem have changed. - this.RebuildPropertyItemEditor( parentPropertyItem ); - } - } - } - - - #endregion //Event Handlers - - #region Commands - - private void ClearFilter( object sender, ExecutedRoutedEventArgs e ) - { - Filter = String.Empty; - } - - private void CanClearFilter( object sender, CanExecuteRoutedEventArgs e ) - { - e.CanExecute = !String.IsNullOrEmpty( Filter ); - } - - #endregion //Commands - - #region Methods - - - - - - - - - - - - - - - - - - - - - - - - - - public double GetScrollPosition() - { - var scrollViewer = this.GetScrollViewer(); - if( scrollViewer != null ) - { - return scrollViewer.VerticalOffset; - } - return 0d; - } - - public void ScrollToPosition( double position ) - { - var scrollViewer = this.GetScrollViewer(); - if( scrollViewer != null ) - { - scrollViewer.ScrollToVerticalOffset( position ); - } - } - - public void ScrollToTop() - { - var scrollViewer = this.GetScrollViewer(); - if( scrollViewer != null ) - { - scrollViewer.ScrollToTop(); - } - } - - public void ScrollToBottom() - { - var scrollViewer = this.GetScrollViewer(); - if( scrollViewer != null ) - { - scrollViewer.ScrollToBottom(); - } - } - - public void CollapseAllProperties() - { - if( _containerHelper != null ) - { - _containerHelper.SetPropertiesExpansion( false ); - } - } - - public void ExpandAllProperties() - { - if( _containerHelper != null ) - { - _containerHelper.SetPropertiesExpansion( true ); - } - } - - public void ExpandProperty( string propertyName ) - { - if( _containerHelper != null ) - { - _containerHelper.SetPropertiesExpansion( propertyName, true ); - } - } - - public void CollapseProperty( string propertyName ) - { - if( _containerHelper != null ) - { - _containerHelper.SetPropertiesExpansion( propertyName, false ); - } - } - - private ScrollViewer GetScrollViewer() - { - if( (_containerHelper != null) && (_containerHelper.ChildrenItemsControl != null) ) - { - return TreeHelper.FindChild( _containerHelper.ChildrenItemsControl ); - } - return null; - } - - private void RebuildPropertyItemEditor( PropertyItem propertyItem ) - { - if( propertyItem != null ) - { - propertyItem.RebuildEditor(); - } - } - - private void UpdateContainerHelper() - { - // Keep a backup of the template element and initialize the - // new helper with it. - ItemsControl childrenItemsControl = ( _containerHelper != null ) ? _containerHelper.ChildrenItemsControl : null; - ObjectContainerHelperBase objectContainerHelper = null; - - - objectContainerHelper = new ObjectContainerHelper( this, SelectedObject ); - objectContainerHelper.ObjectsGenerated += this.ObjectContainerHelper_ObjectsGenerated; - objectContainerHelper.GenerateProperties(); - } - - private void SetContainerHelper( ContainerHelperBase containerHelper ) - { - if( _containerHelper != null ) - { - _containerHelper.ClearHelper(); - } - _containerHelper = containerHelper; - } - - private void FinalizeUpdateContainerHelper( ItemsControl childrenItemsControl ) - { - - if( _containerHelper != null ) - { - _containerHelper.ChildrenItemsControl = childrenItemsControl; - } - - if( this.IsScrollingToTopAfterRefresh ) - { - this.ScrollToTop(); - } - - // Since the template will bind on this property and this property - // will be different when the property parent is updated. - this.Notify( this.PropertyChanged, () => this.Properties ); - } - - - - - - - - - - - - - - - private void UpdateThumb() - { - if( _dragThumb != null ) - { - if( IsCategorized ) - _dragThumb.Margin = new Thickness( 6, 0, 0, 0 ); - else - _dragThumb.Margin = new Thickness( -1, 0, 0, 0 ); - } - } - - /// - /// Override this call to control the filter applied based on the - /// text input. - /// - /// - /// - protected virtual Predicate CreateFilter( string filter ) - { - return null; - } - - /// - /// Updates all property values in the PropertyGrid with the data from the SelectedObject - /// - public void Update() - { - if( _containerHelper != null ) - { - _containerHelper.UpdateValuesFromSource(); - } - } - - - - - #endregion //Methods - - #region Event Handlers - - private void ObjectContainerHelper_ObjectsGenerated( object sender, EventArgs e ) - { - var objectContainerHelper = sender as ObjectContainerHelperBase; - if( objectContainerHelper != null ) - { - objectContainerHelper.ObjectsGenerated -= this.ObjectContainerHelper_ObjectsGenerated; - this.SetContainerHelper( objectContainerHelper ); - this.FinalizeUpdateContainerHelper( objectContainerHelper.ChildrenItemsControl ); - - RaiseEvent( new RoutedEventArgs( PropertyGrid.PropertiesGeneratedEvent, this ) ); - } - } - - #endregion - - #region Events - - #region PropertyChanged Event - - public event PropertyChangedEventHandler PropertyChanged; - - #endregion - - #region PropertyValueChangedEvent Routed Event - public static readonly RoutedEvent PropertyValueChangedEvent = EventManager.RegisterRoutedEvent( "PropertyValueChanged", RoutingStrategy.Bubble, typeof( PropertyValueChangedEventHandler ), typeof( PropertyGrid ) ); - public event PropertyValueChangedEventHandler PropertyValueChanged - { - add - { - AddHandler( PropertyValueChangedEvent, value ); - } - remove - { - RemoveHandler( PropertyValueChangedEvent, value ); - } - } - #endregion - - #region SelectedPropertyItemChangedEvent Routed Event - - public static readonly RoutedEvent SelectedPropertyItemChangedEvent = EventManager.RegisterRoutedEvent( "SelectedPropertyItemChanged", RoutingStrategy.Bubble, typeof( RoutedPropertyChangedEventHandler ), typeof( PropertyGrid ) ); - public event RoutedPropertyChangedEventHandler SelectedPropertyItemChanged - { - add - { - AddHandler( SelectedPropertyItemChangedEvent, value ); - } - remove - { - RemoveHandler( SelectedPropertyItemChangedEvent, value ); - } - } - #endregion - - #region SelectedObjectChangedEventRouted Routed Event - - public static readonly RoutedEvent SelectedObjectChangedEvent = EventManager.RegisterRoutedEvent( "SelectedObjectChanged", RoutingStrategy.Bubble, typeof( RoutedPropertyChangedEventHandler ), typeof( PropertyGrid ) ); - public event RoutedPropertyChangedEventHandler SelectedObjectChanged - { - add - { - AddHandler( SelectedObjectChangedEvent, value ); - } - remove - { - RemoveHandler( SelectedObjectChangedEvent, value ); - } - } - - #endregion - - #region IsPropertyBrowsable Event - - public event IsPropertyBrowsableHandler IsPropertyBrowsable; - - #endregion - - - - - - - - #region PreparePropertyItemEvent Attached Routed Event - - /// - /// Identifies the PreparePropertyItem event. - /// This attached routed event may be raised by the PropertyGrid itself or by a - /// PropertyItemBase containing sub-items. - /// - public static readonly RoutedEvent PreparePropertyItemEvent = EventManager.RegisterRoutedEvent( "PreparePropertyItem", RoutingStrategy.Bubble, typeof( PropertyItemEventHandler ), typeof( PropertyGrid ) ); - - /// - /// This event is raised when a property item is about to be displayed in the PropertyGrid. - /// This allow the user to customize the property item just before it is displayed. - /// - public event PropertyItemEventHandler PreparePropertyItem - { - add - { - AddHandler( PropertyGrid.PreparePropertyItemEvent, value ); - } - remove - { - RemoveHandler( PropertyGrid.PreparePropertyItemEvent, value ); - } - } - - /// - /// Adds a handler for the PreparePropertyItem attached event - /// - /// the element to attach the handler - /// the handler for the event - public static void AddPreparePropertyItemHandler( UIElement element, PropertyItemEventHandler handler ) - { - element.AddHandler( PropertyGrid.PreparePropertyItemEvent, handler ); - } - - /// - /// Removes a handler for the PreparePropertyItem attached event - /// - /// the element to attach the handler - /// the handler for the event - public static void RemovePreparePropertyItemHandler( UIElement element, PropertyItemEventHandler handler ) - { - element.RemoveHandler( PropertyGrid.PreparePropertyItemEvent, handler ); - } - - internal static void RaisePreparePropertyItemEvent( UIElement source, PropertyItemBase propertyItem, object item ) - { - source.RaiseEvent( new PropertyItemEventArgs( PropertyGrid.PreparePropertyItemEvent, source, propertyItem, item ) ); - } - - #endregion - - #region ClearPropertyItemEvent Attached Routed Event - - /// - /// Identifies the ClearPropertyItem event. - /// This attached routed event may be raised by the PropertyGrid itself or by a - /// PropertyItemBase containing sub items. - /// - public static readonly RoutedEvent ClearPropertyItemEvent = EventManager.RegisterRoutedEvent( "ClearPropertyItem", RoutingStrategy.Bubble, typeof( PropertyItemEventHandler ), typeof( PropertyGrid ) ); - /// - /// This event is raised when an property item is about to be remove from the display in the PropertyGrid - /// This allow the user to remove any attached handler in the PreparePropertyItem event. - /// - public event PropertyItemEventHandler ClearPropertyItem - { - add - { - AddHandler( PropertyGrid.ClearPropertyItemEvent, value ); - } - remove - { - RemoveHandler( PropertyGrid.ClearPropertyItemEvent, value ); - } - } - - #region PropertiesGenerated Event - - public static readonly RoutedEvent PropertiesGeneratedEvent = EventManager.RegisterRoutedEvent( "PropertiesGenerated", RoutingStrategy.Bubble, typeof( EventHandler ), typeof( PropertyGrid ) ); - public event RoutedEventHandler PropertiesGenerated - { - add - { - AddHandler( PropertiesGeneratedEvent, value ); - } - remove - { - RemoveHandler( PropertiesGeneratedEvent, value ); - } - } - - #endregion //PropertiesGenerated Event - - /// - /// Adds a handler for the ClearPropertyItem attached event - /// - /// the element to attach the handler - /// the handler for the event - public static void AddClearPropertyItemHandler( UIElement element, PropertyItemEventHandler handler ) - { - element.AddHandler( PropertyGrid.ClearPropertyItemEvent, handler ); - } - - /// - /// Removes a handler for the ClearPropertyItem attached event - /// - /// the element to attach the handler - /// the handler for the event - public static void RemoveClearPropertyItemHandler( UIElement element, PropertyItemEventHandler handler ) - { - element.RemoveHandler( PropertyGrid.ClearPropertyItemEvent, handler ); - } - - internal static void RaiseClearPropertyItemEvent( UIElement source, PropertyItemBase propertyItem, object item ) - { - source.RaiseEvent( new PropertyItemEventArgs( PropertyGrid.ClearPropertyItemEvent, source, propertyItem, item ) ); - } - - #endregion - - #endregion //Events - - #region Interfaces - - #region ISupportInitialize Members - - public override void BeginInit() - { - base.BeginInit(); - _initializationCount++; - } - - public override void EndInit() - { - base.EndInit(); - if( --_initializationCount == 0 ) - { - if( _hasPendingSelectedObjectChanged ) - { - //This will update SelectedObject, Type, Name based on the actual config. - this.UpdateContainerHelper(); - _hasPendingSelectedObjectChanged = false; - } - if( _containerHelper != null ) - { - _containerHelper.OnEndInit(); - } - } - } - - #endregion - - #region IPropertyContainer Members - - FilterInfo IPropertyContainer.FilterInfo - { - get - { - return new FilterInfo() - { - Predicate = this.CreateFilter(this.Filter), - InputString = this.Filter - }; - } - } - - ContainerHelperBase IPropertyContainer.ContainerHelper - { - get - { - return _containerHelper; - } - } - - bool IPropertyContainer.IsSortedAlphabetically - { - get - { - return true; - } - } - - - bool? IPropertyContainer.IsPropertyVisible( PropertyDescriptor pd ) - { - var handler = this.IsPropertyBrowsable; - //If anyone is registered to PropertyGrid.IsPropertyBrowsable event - if( handler != null ) - { - var isBrowsableArgs = new IsPropertyBrowsableArgs( pd ); - handler( this, isBrowsableArgs ); - - return isBrowsableArgs.IsBrowsable; - } - - return null; - } - - - - - #endregion - - - #endregion - - } - - #region PropertyValueChangedEvent Handler/Args - public delegate void PropertyValueChangedEventHandler( object sender, PropertyValueChangedEventArgs e ); - public class PropertyValueChangedEventArgs : RoutedEventArgs - { - public object NewValue - { - get; - set; - } - public object OldValue - { - get; - set; - } - - public PropertyValueChangedEventArgs( RoutedEvent routedEvent, object source, object oldValue, object newValue ) - : base( routedEvent, source ) - { - NewValue = newValue; - OldValue = oldValue; - } - } - #endregion - - #region PropertyItemCreatedEvent Handler/Args - public delegate void PropertyItemEventHandler( object sender, PropertyItemEventArgs e ); - public class PropertyItemEventArgs : RoutedEventArgs - { - public PropertyItemBase PropertyItem - { - get; - private set; - } - - public object Item - { - get; - private set; - } - - public PropertyItemEventArgs( RoutedEvent routedEvent, object source, PropertyItemBase propertyItem, object item ) - : base( routedEvent, source ) - { - this.PropertyItem = propertyItem; - this.Item = item; - } - } - #endregion - - #region IsPropertyArgs class - - public class PropertyArgs : RoutedEventArgs - { - #region Constructors - - public PropertyArgs( PropertyDescriptor pd ) - { - this.PropertyDescriptor = pd; - } - - #endregion - - #region Properties - - #region PropertyDescriptor Property - - public PropertyDescriptor PropertyDescriptor - { - get; - private set; - } - - #endregion - - #endregion - } - - #endregion - - #region isPropertyBrowsableEvent Handler/Args - - public delegate void IsPropertyBrowsableHandler( object sender, IsPropertyBrowsableArgs e ); - - public class IsPropertyBrowsableArgs : PropertyArgs - { - #region Constructors - - public IsPropertyBrowsableArgs( PropertyDescriptor pd ) - : base( pd ) - { - } - - #endregion - - #region Properties - - #region IsBrowsable Property - - public bool? IsBrowsable - { - get; - set; - } - - #endregion - - #endregion - } - - #endregion - - - - - - - - - - - - -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyGridUtilities.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyGridUtilities.cs deleted file mode 100644 index 6b09500f..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyGridUtilities.cs +++ /dev/null @@ -1,211 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Windows; -using System.Windows.Data; -using System.Windows.Media; -using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; -using Xceed.Wpf.Toolkit.PropertyGrid.Editors; -using System.Linq.Expressions; -using System.Windows.Input; -using Xceed.Wpf.Toolkit.Core.Utilities; -using System.Windows.Controls; -using System.Reflection; -using System.Windows.Controls.Primitives; -using Xceed.Wpf.Toolkit.PropertyGrid.Converters; -using Xceed.Wpf.Toolkit.Primitives; -using System.IO; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - internal class PropertyGridUtilities - { - internal static T GetAttribute( PropertyDescriptor property ) where T : Attribute - { - return property.Attributes.OfType().FirstOrDefault(); - } - - - - - internal static ITypeEditor CreateDefaultEditor( Type propertyType, TypeConverter typeConverter, PropertyItem propertyItem ) - { - ITypeEditor editor = null; - - var context = new EditorTypeDescriptorContext( null, propertyItem.Instance, propertyItem.PropertyDescriptor ); - if( (typeConverter != null) - && typeConverter.GetStandardValuesSupported( context ) - && typeConverter.GetStandardValuesExclusive( context ) - && !( typeConverter is ReferenceConverter ) - && (propertyType != typeof( bool )) && (propertyType != typeof( bool? )) ) //Bool type always have a BooleanConverter with standardValues : True/False. - { - var items = typeConverter.GetStandardValues( context ); - editor = new SourceComboBoxEditor( items, typeConverter ); - } - else if( propertyType == typeof( string ) ) - editor = new TextBoxEditor(); - else if( propertyType == typeof( bool ) || propertyType == typeof( bool? ) ) - editor = new CheckBoxEditor(); - else if( propertyType == typeof( decimal ) || propertyType == typeof( decimal? ) ) - editor = new DecimalUpDownEditor(); - else if( propertyType == typeof( double ) || propertyType == typeof( double? ) ) - editor = new DoubleUpDownEditor(); - else if( propertyType == typeof( int ) || propertyType == typeof( int? ) ) - editor = new IntegerUpDownEditor(); - else if( propertyType == typeof( short ) || propertyType == typeof( short? ) ) - editor = new ShortUpDownEditor(); - else if( propertyType == typeof( long ) || propertyType == typeof( long? ) ) - editor = new LongUpDownEditor(); - else if( propertyType == typeof( float ) || propertyType == typeof( float? ) ) - editor = new SingleUpDownEditor(); - else if( propertyType == typeof( byte ) || propertyType == typeof( byte? ) ) - editor = new ByteUpDownEditor(); - else if( propertyType == typeof( sbyte ) || propertyType == typeof( sbyte? ) ) - editor = new SByteUpDownEditor(); - else if( propertyType == typeof( uint ) || propertyType == typeof( uint? ) ) - editor = new UIntegerUpDownEditor(); - else if( propertyType == typeof( ulong ) || propertyType == typeof( ulong? ) ) - editor = new ULongUpDownEditor(); - else if( propertyType == typeof( ushort ) || propertyType == typeof( ushort? ) ) - editor = new UShortUpDownEditor(); - else if( propertyType == typeof( DateTime ) || propertyType == typeof( DateTime? ) ) - editor = new DateTimeUpDownEditor(); - else if( ( propertyType == typeof( Color ) ) || ( propertyType == typeof( Color? ) ) ) - editor = new ColorEditor(); - else if( propertyType.IsEnum ) - editor = new EnumComboBoxEditor(); - else if( propertyType == typeof( TimeSpan ) || propertyType == typeof( TimeSpan? ) ) - editor = new TimeSpanUpDownEditor(); - else if( propertyType == typeof( FontFamily ) || propertyType == typeof( FontWeight ) || propertyType == typeof( FontStyle ) || propertyType == typeof( FontStretch ) ) - editor = new FontComboBoxEditor(); - else if (propertyType == typeof(Guid) || propertyType == typeof(Guid?)) - editor = new MaskedTextBoxEditor() { ValueDataType = propertyType, Mask = "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA" }; - else if (propertyType == typeof(char) || propertyType == typeof(char?)) - editor = new MaskedTextBoxEditor() { ValueDataType = propertyType, Mask = "&" }; - else if( propertyType == typeof( object ) ) - // If any type of object is possible in the property, default to the TextBoxEditor. - // Useful in some case (e.g., Button.Content). - // Can be reconsidered but was the legacy behavior on the PropertyGrid. - editor = new TextBoxEditor(); - else - { - var listType = ListUtilities.GetListItemType( propertyType ); - - // A List of T - if( listType != null ) - { - if( !listType.IsPrimitive && !listType.Equals( typeof( String ) ) && !listType.IsEnum ) - editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.CollectionEditor(); - else - editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.PrimitiveTypeCollectionEditor(); - } - else - { - var dictionaryType = ListUtilities.GetDictionaryItemsType( propertyType ); - var collectionType = ListUtilities.GetCollectionItemType( propertyType ); - // A dictionary of T or a Collection of T or an ICollection - if( (dictionaryType != null) || (collectionType != null) || typeof( ICollection ).IsAssignableFrom( propertyType ) ) - { - editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.CollectionEditor(); - } - else - { - // If the type is not supported, check if there is a converter that supports - // string conversion to the object type. Use TextBox in theses cases. - // Otherwise, return a TextBlock editor since no valid editor exists. - editor = (typeConverter != null && typeConverter.CanConvertFrom( typeof( string ) )) - ? (ITypeEditor)new TextBoxEditor() - : (ITypeEditor)new TextBlockEditor(); - } - } - } - - return editor; - } - - - - - - - - - - - - - - - #region Private class - - private class EditorTypeDescriptorContext : ITypeDescriptorContext - { - IContainer _container; - object _instance; - PropertyDescriptor _propertyDescriptor; - - internal EditorTypeDescriptorContext( IContainer container, object instance, PropertyDescriptor pd ) - { - _container = container; - _instance = instance; - _propertyDescriptor = pd; - } - - IContainer ITypeDescriptorContext.Container - { - get - { - return _container; - } - } - object ITypeDescriptorContext.Instance - { - get - { - return _instance; - } - } - PropertyDescriptor ITypeDescriptorContext.PropertyDescriptor - { - get - { - return _propertyDescriptor; - } - } - - void ITypeDescriptorContext.OnComponentChanged() - { - } - - bool ITypeDescriptorContext.OnComponentChanging() - { - return false; - } - - object IServiceProvider.GetService( Type serviceType ) - { - return null; - } - } - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyItem.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyItem.cs deleted file mode 100644 index 3b47a5fe..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyItem.cs +++ /dev/null @@ -1,335 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Data; -using System.Collections; -using Xceed.Wpf.Toolkit.Core.Utilities; -using System.Linq.Expressions; -using System.Diagnostics; -using System.Globalization; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - [TemplatePart( Name = "content", Type = typeof( ContentControl ) )] - public class PropertyItem : CustomPropertyItem - { - #region Properties - - #region IsReadOnly - - /// - /// Identifies the IsReadOnly dependency property - /// - public static readonly DependencyProperty IsReadOnlyProperty = - DependencyProperty.Register( "IsReadOnly", typeof( bool ), typeof( PropertyItem ), new UIPropertyMetadata( false, OnIsReadOnlyChanged ) ); - - public bool IsReadOnly - { - get { return ( bool )GetValue( IsReadOnlyProperty ); } - set { SetValue( IsReadOnlyProperty, value ); } - } - - private static void OnIsReadOnlyChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - var propertyItem = o as PropertyItem; - if( propertyItem != null ) - propertyItem.OnIsReadOnlyChanged( (bool)e.OldValue, (bool)e.NewValue ); - } - - protected virtual void OnIsReadOnlyChanged( bool oldValue, bool newValue ) - { - if( this.IsLoaded ) - { - this.RebuildEditor(); - } - } - - - #endregion //IsReadOnly - - #region IsInValid - - /// - /// Identifies the IsInvalid dependency property - /// - public static readonly DependencyProperty IsInvalidProperty = - DependencyProperty.Register( "IsInvalid", typeof( bool ), typeof( PropertyItem ), new UIPropertyMetadata( false, OnIsInvalidChanged ) ); - - public bool IsInvalid - { - get - { - return ( bool )GetValue( IsInvalidProperty ); - } - internal set - { - SetValue( IsInvalidProperty, value ); - } - } - - private static void OnIsInvalidChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - var propertyItem = o as PropertyItem; - if( propertyItem != null ) - propertyItem.OnIsInvalidChanged( ( bool )e.OldValue, ( bool )e.NewValue ); - } - - protected virtual void OnIsInvalidChanged( bool oldValue, bool newValue ) - { - var be = this.GetBindingExpression( PropertyItem.ValueProperty ); - - if( newValue ) - { - var validationError = new ValidationError( new InvalidValueValidationRule(), be ); - validationError.ErrorContent = "Value could not be converted."; - Validation.MarkInvalid( be, validationError ); - } - else - { - Validation.ClearInvalid( be ); - } - } - - - #endregion // IsInvalid - - #region PropertyDescriptor - - public PropertyDescriptor PropertyDescriptor - { - get; - internal set; - } - - #endregion //PropertyDescriptor - - #region PropertyName - - public string PropertyName - { - get - { - return (this.DescriptorDefinition != null) ? this.DescriptorDefinition.PropertyName : null; - } - } - - #endregion - - #region PropertyType - - public Type PropertyType - { - get - { - return ( PropertyDescriptor != null ) - ? PropertyDescriptor.PropertyType - : null; - } - } - - #endregion //PropertyType - - #region DescriptorDefinition - - internal DescriptorPropertyDefinitionBase DescriptorDefinition - { - get; - private set; - } - - #endregion DescriptorDefinition - - #region Instance - - public object Instance - { - get; - internal set; - } - - #endregion //Instance - - #endregion //Properties - - #region Overrides - - protected override string GetPropertyItemName() - { - return this.PropertyName; - } - - protected override Type GetPropertyItemType() - { - return this.PropertyType; - } - - protected override void OnIsExpandedChanged( bool oldValue, bool newValue ) - { - if( newValue && this.IsLoaded ) - { - this.GenerateExpandedPropertyItems(); - } - } - - protected override object OnCoerceValueChanged( object baseValue ) - { - // Propagate error from DescriptorPropertyDefinitionBase to PropertyItem.Value - // to see the red error rectangle in the propertyGrid. - BindingExpression be = this.GetBindingExpression( PropertyItem.ValueProperty ); - this.SetRedInvalidBorder( be ); - return baseValue; - } - - protected override void OnValueChanged( object oldValue, object newValue ) - { - base.OnValueChanged( oldValue, newValue ); - - // A Default Value is defined and newValue is null => set the Default Value - if( ( newValue == null ) && ( this.DescriptorDefinition != null ) && ( this.DescriptorDefinition.DefaultValue != null ) ) - { -#if VS2008 - this.Value = this.DescriptorDefinition.DefaultValue; -#else - this.SetCurrentValue( PropertyItem.ValueProperty, this.DescriptorDefinition.DefaultValue ); -#endif - } - } - - #endregion - - #region Internal Methods - - internal void SetRedInvalidBorder( BindingExpression be ) - { - if( (be != null) && be.DataItem is DescriptorPropertyDefinitionBase ) - { - DescriptorPropertyDefinitionBase descriptor = be.DataItem as DescriptorPropertyDefinitionBase; - if( Validation.GetHasError( descriptor ) ) - { - ReadOnlyObservableCollection errors = Validation.GetErrors( descriptor ); - Validation.MarkInvalid( be, errors[ 0 ] ); - } - } - } - - internal void RebuildEditor() - { - var objectContainerHelperBase = this.ContainerHelper as ObjectContainerHelperBase; - //Re-build the editor to update this propertyItem - var editor = objectContainerHelperBase.GenerateChildrenEditorElement( this ); - if( editor != null ) - { - // Tag the editor as generated to know if we should clear it. - ContainerHelperBase.SetIsGenerated( editor, true ); - this.Editor = editor; - - //Update Source of binding and Validation of PropertyItem to update - var be = this.GetBindingExpression( PropertyItem.ValueProperty ); - if( be != null ) - { - be.UpdateSource(); - this.SetRedInvalidBorder( be ); - } - } - } - - #endregion - - #region Private Methods - - private void OnDefinitionContainerHelperInvalidated( object sender, EventArgs e ) - { - if( this.ContainerHelper != null ) - { - this.ContainerHelper.ClearHelper(); - } - var helper = this.DescriptorDefinition.CreateContainerHelper( this ); - this.ContainerHelper = helper; - if( this.IsExpanded ) - { - helper.GenerateProperties(); - } - } - - private void Init( DescriptorPropertyDefinitionBase definition ) - { - if( definition == null ) - throw new ArgumentNullException( "definition" ); - - if( this.ContainerHelper != null ) - { - this.ContainerHelper.ClearHelper(); - } - this.DescriptorDefinition = definition; - this.ContainerHelper = definition.CreateContainerHelper( this ); - definition.ContainerHelperInvalidated += new EventHandler( OnDefinitionContainerHelperInvalidated ); - this.Loaded += this.PropertyItem_Loaded; - } - - private void GenerateExpandedPropertyItems() - { - if( this.IsExpanded ) - { - // This withholds the generation of all PropertyItem instances (recursively) - // until the PropertyItem is expanded. - var objectContainerHelper = ContainerHelper as ObjectContainerHelperBase; - if( objectContainerHelper != null ) - { - objectContainerHelper.GenerateProperties(); - } - } - } - - #endregion - - #region Event Handlers - - private void PropertyItem_Loaded( object sender, RoutedEventArgs e ) - { - this.GenerateExpandedPropertyItems(); - } - - #endregion - - #region Constructors - - internal PropertyItem( DescriptorPropertyDefinitionBase definition ) - : base( definition.IsPropertyGridCategorized, !definition.PropertyType.IsArray ) - { - this.Init( definition ); - } - - #endregion //Constructors - - private class InvalidValueValidationRule : ValidationRule - { - public override ValidationResult Validate( object value, CultureInfo cultureInfo ) - { - // Will always return an error. - return new ValidationResult( false, null ); - } - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyItemBase.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyItemBase.cs deleted file mode 100644 index 79eb3898..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyItemBase.cs +++ /dev/null @@ -1,602 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Data; -using System.Collections; -using Xceed.Wpf.Toolkit.Core.Utilities; -using System.Linq.Expressions; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - [TemplatePart( Name = PropertyGrid.PART_PropertyItemsControl, Type = typeof( PropertyItemsControl ) )] - [TemplatePart( Name = PropertyItemBase.PART_ValueContainer, Type = typeof( ContentControl ) )] - public abstract class PropertyItemBase : Control, IPropertyContainer, INotifyPropertyChanged - { - internal const string PART_ValueContainer = "PART_ValueContainer"; - - private ContentControl _valueContainer; - private ContainerHelperBase _containerHelper; - private IPropertyContainer _parentNode; - internal bool _isPropertyGridCategorized; - internal bool _isSortedAlphabetically = true; - - #region Properties - - #region AdvancedOptionsIcon - - public static readonly DependencyProperty AdvancedOptionsIconProperty = - DependencyProperty.Register( "AdvancedOptionsIcon", typeof( ImageSource ), typeof( PropertyItemBase ), new UIPropertyMetadata( null ) ); - - public ImageSource AdvancedOptionsIcon - { - get { return ( ImageSource )GetValue( AdvancedOptionsIconProperty ); } - set { SetValue( AdvancedOptionsIconProperty, value ); } - } - - #endregion //AdvancedOptionsIcon - - #region AdvancedOptionsTooltip - - public static readonly DependencyProperty AdvancedOptionsTooltipProperty = - DependencyProperty.Register( "AdvancedOptionsTooltip", typeof( object ), typeof( PropertyItemBase ), new UIPropertyMetadata( null ) ); - - public object AdvancedOptionsTooltip - { - get { return ( object )GetValue( AdvancedOptionsTooltipProperty ); } - set { SetValue( AdvancedOptionsTooltipProperty, value ); } - } - - #endregion //AdvancedOptionsTooltip - - - - - - - #region Description - - public static readonly DependencyProperty DescriptionProperty = - DependencyProperty.Register( "Description", typeof( string ), typeof( PropertyItemBase ), new UIPropertyMetadata( null ) ); - - public string Description - { - get { return ( string )GetValue( DescriptionProperty ); } - set { SetValue( DescriptionProperty, value ); } - } - - #endregion //Description - - #region DisplayName - - public static readonly DependencyProperty DisplayNameProperty = - DependencyProperty.Register( "DisplayName", typeof( string ), typeof( PropertyItemBase ), new UIPropertyMetadata( null ) ); - - public string DisplayName - { - get { return ( string )GetValue( DisplayNameProperty ); } - set { SetValue( DisplayNameProperty, value ); } - } - - #endregion //DisplayName - - #region Editor - - public static readonly DependencyProperty EditorProperty = DependencyProperty.Register( "Editor", typeof( FrameworkElement ), typeof( PropertyItemBase ), new UIPropertyMetadata( null, OnEditorChanged ) ); - public FrameworkElement Editor - { - get - { - return ( FrameworkElement )GetValue( EditorProperty ); - } - set - { - SetValue( EditorProperty, value ); - } - } - - private static void OnEditorChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PropertyItemBase propertyItem = o as PropertyItemBase; - if( propertyItem != null ) - propertyItem.OnEditorChanged( ( FrameworkElement )e.OldValue, ( FrameworkElement )e.NewValue ); - } - - protected virtual void OnEditorChanged( FrameworkElement oldValue, FrameworkElement newValue ) - { - } - - #endregion //Editor - - #region HighlightedText - - public static readonly DependencyProperty HighlightedTextProperty = DependencyProperty.Register( "HighlightedText", typeof( string ), typeof( PropertyItemBase ), new UIPropertyMetadata( null ) ); - - public string HighlightedText - { - get - { - return ( string )GetValue( HighlightedTextProperty ); - } - set - { - SetValue( HighlightedTextProperty, value ); - } - } - - #endregion //HighlightedText - - #region IsExpanded - - public static readonly DependencyProperty IsExpandedProperty = DependencyProperty.Register( "IsExpanded", typeof( bool ), typeof( PropertyItemBase ), new UIPropertyMetadata( false, OnIsExpandedChanged ) ); - public bool IsExpanded - { - get - { - return ( bool )GetValue( IsExpandedProperty ); - } - set - { - SetValue( IsExpandedProperty, value ); - } - } - - private static void OnIsExpandedChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PropertyItemBase propertyItem = o as PropertyItemBase; - if( propertyItem != null ) - propertyItem.OnIsExpandedChanged( ( bool )e.OldValue, ( bool )e.NewValue ); - } - - protected virtual void OnIsExpandedChanged( bool oldValue, bool newValue ) - { - } - - #endregion IsExpanded - - #region IsExpandable - - public static readonly DependencyProperty IsExpandableProperty = - DependencyProperty.Register( "IsExpandable", typeof( bool ), typeof( PropertyItemBase ), new UIPropertyMetadata( false ) ); - - public bool IsExpandable - { - get { return ( bool )GetValue( IsExpandableProperty ); } - set { SetValue( IsExpandableProperty, value ); } - } - - #endregion //IsExpandable - - #region IsSelected - - public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register( "IsSelected", typeof( bool ), typeof( PropertyItemBase ), new UIPropertyMetadata( false, OnIsSelectedChanged ) ); - public bool IsSelected - { - get - { - return ( bool )GetValue( IsSelectedProperty ); - } - set - { - SetValue( IsSelectedProperty, value ); - } - } - - private static void OnIsSelectedChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - PropertyItemBase propertyItem = o as PropertyItemBase; - if( propertyItem != null ) - propertyItem.OnIsSelectedChanged( ( bool )e.OldValue, ( bool )e.NewValue ); - } - - protected virtual void OnIsSelectedChanged( bool oldValue, bool newValue ) - { - this.RaiseItemSelectionChangedEvent(); - } - - #endregion //IsSelected - - #region ParentElement - /// - /// Gets the parent property grid element of this property. - /// A PropertyItemBase instance if this is a sub-element, - /// or the PropertyGrid itself if this is a first-level property. - /// - public FrameworkElement ParentElement - { - get { return this.ParentNode as FrameworkElement; } - } - #endregion - - #region ParentNode - - internal IPropertyContainer ParentNode - { - get - { - return _parentNode; - } - set - { - _parentNode = value; - } - } - #endregion - - #region ValueContainer - - internal ContentControl ValueContainer - { - get - { - return _valueContainer; - } - } - - #endregion - - #region Level - - public int Level - { - get; - internal set; - } - - #endregion //Level - - #region Properties - - public IList Properties - { - get - { - if( _containerHelper == null ) - { - _containerHelper = new ObjectContainerHelper( this, null ); - } - return _containerHelper.Properties; - } - } - - #endregion //Properties - - #region PropertyContainerStyle - /// - /// Get the PropertyContainerStyle for sub items of this property. - /// It return the value defined on PropertyGrid.PropertyContainerStyle. - /// - public Style PropertyContainerStyle - { - get - { - return ( ParentNode != null ) - ? ParentNode.PropertyContainerStyle - : null; - } - } - #endregion - - #region ContainerHelper - - internal ContainerHelperBase ContainerHelper - { - get - { - return _containerHelper; - } - set - { - if( value == null ) - throw new ArgumentNullException( "value" ); - - _containerHelper = value; - // Properties property relies on the "Properties" property of the helper - // class. Raise a property-changed event. - this.RaisePropertyChanged( () => this.Properties ); - } - } - - #endregion - - #region WillRefreshPropertyGrid - - public static readonly DependencyProperty WillRefreshPropertyGridProperty = - DependencyProperty.Register( "WillRefreshPropertyGrid", typeof( bool ), typeof( PropertyItemBase ), new UIPropertyMetadata( false ) ); - - public bool WillRefreshPropertyGrid - { - get - { - return ( bool )GetValue( WillRefreshPropertyGridProperty ); - } - set - { - SetValue( WillRefreshPropertyGridProperty, value ); - } - } - - #endregion //WillRefreshPropertyGrid - - #endregion //Properties - - #region Events - - #region ItemSelectionChanged - - internal static readonly RoutedEvent ItemSelectionChangedEvent = EventManager.RegisterRoutedEvent( - "ItemSelectionChangedEvent", RoutingStrategy.Bubble, typeof( RoutedEventHandler ), typeof( PropertyItemBase ) ); - - private void RaiseItemSelectionChangedEvent() - { - RaiseEvent( new RoutedEventArgs( PropertyItemBase.ItemSelectionChangedEvent ) ); - } - - #endregion - - #region PropertyChanged event - - public event PropertyChangedEventHandler PropertyChanged; - - internal void RaisePropertyChanged( Expression> propertyExpression ) - { - this.Notify( this.PropertyChanged, propertyExpression ); - } - internal void RaisePropertyChanged( string name ) - { - this.Notify( this.PropertyChanged, name ); - } - #endregion - - #endregion //Events - - #region Constructors - - static PropertyItemBase() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( PropertyItemBase ), new FrameworkPropertyMetadata( typeof( PropertyItemBase ) ) ); - } - - internal PropertyItemBase() - { - this.GotFocus += new RoutedEventHandler( PropertyItemBase_GotFocus ); - this.RequestBringIntoView += this.PropertyItemBase_RequestBringIntoView; - AddHandler( PropertyItemsControl.PreparePropertyItemEvent, new PropertyItemEventHandler( OnPreparePropertyItemInternal ) ); - AddHandler( PropertyItemsControl.ClearPropertyItemEvent, new PropertyItemEventHandler( OnClearPropertyItemInternal ) ); - } - - #endregion //Constructors - - #region Event Handlers - - private void OnPreparePropertyItemInternal( object sender, PropertyItemEventArgs args ) - { - // This is the callback of the PreparePropertyItem comming from the template PropertyItemControl. - args.PropertyItem.Level = this.Level + 1; - _containerHelper.PrepareChildrenPropertyItem( args.PropertyItem, args.Item ); - - args.Handled = true; - } - - private void OnClearPropertyItemInternal( object sender, PropertyItemEventArgs args ) - { - _containerHelper.ClearChildrenPropertyItem( args.PropertyItem, args.Item ); - // This is the callback of the PreparePropertyItem comming from the template PropertyItemControl. - args.PropertyItem.Level = 0; - - args.Handled = true; - } - - private void PropertyItemBase_RequestBringIntoView( object sender, RequestBringIntoViewEventArgs e ) - { - e.Handled = true; - } - - #endregion //Event Handlers - - #region Methods - - protected virtual Type GetPropertyItemType() - { - return null; - } - - protected virtual string GetPropertyItemName() - { - return this.DisplayName; - } - - public override void OnApplyTemplate() - { - base.OnApplyTemplate(); - _containerHelper.ChildrenItemsControl = GetTemplateChild( PropertyGrid.PART_PropertyItemsControl ) as PropertyItemsControl; - _valueContainer = GetTemplateChild( PropertyItemBase.PART_ValueContainer ) as ContentControl; - } - - protected override void OnMouseDown( MouseButtonEventArgs e ) - { - IsSelected = true; - if( !this.IsKeyboardFocusWithin ) - { - this.Focus(); - } - // Handle the event; otherwise, the possible - // parent property item will select itself too. - e.Handled = true; - } - - - private void PropertyItemBase_GotFocus( object sender, RoutedEventArgs e ) - { - IsSelected = true; - // Handle the event; otherwise, the possible - // parent property item will select itself too. - e.Handled = true; - } - - protected override void OnPropertyChanged( DependencyPropertyChangedEventArgs e ) - { - base.OnPropertyChanged( e ); - - // First check that the raised property is actually a real CLR property. - // This could be something else like an Attached DP. - if( ReflectionHelper.IsPublicInstanceProperty( GetType(), e.Property.Name ) - && this.IsLoaded - && (_parentNode != null) - && !_parentNode.ContainerHelper.IsCleaning) - { - this.RaisePropertyChanged( e.Property.Name ); - } - } - - private PropertyDefinitionCollection GetPropertItemPropertyDefinitions() - { - if( (this.ParentNode != null) && (this.ParentNode.PropertyDefinitions != null) ) - { - var name = this.GetPropertyItemName(); - foreach( var pd in this.ParentNode.PropertyDefinitions ) - { - if( pd.TargetProperties.Contains( name ) ) - { - // PropertyDefinitions contains a PropertyDefinition for this PropertyItem Name => return its PropertyDefinitions. - return pd.PropertyDefinitions; - } - else - { - var type = this.GetPropertyItemType(); - if( type != null ) - { - foreach( var targetProperty in pd.TargetProperties ) - { - var targetPropertyType = targetProperty as Type; - // PropertyDefinitions contains a PropertyDefinition for this PropertyItem Type => return its PropertyDefinitions. - if( (targetPropertyType != null) && targetPropertyType.IsAssignableFrom( type ) ) - return pd.PropertyDefinitions; - } - } - } - } - } - return null; - } - - #endregion //Methods - - #region IPropertyContainer Members - - - - - - - Style IPropertyContainer.PropertyContainerStyle - { - get { return this.PropertyContainerStyle; } - } - - EditorDefinitionCollection IPropertyContainer.EditorDefinitions - { - get - { - return (this.ParentNode != null) ? this.ParentNode.EditorDefinitions : null; - } - } - - PropertyDefinitionCollection IPropertyContainer.PropertyDefinitions - { - get - { - return this.GetPropertItemPropertyDefinitions(); - } - } - - ContainerHelperBase IPropertyContainer.ContainerHelper - { - get - { - return this.ContainerHelper; - } - } - - bool IPropertyContainer.IsCategorized - { - get - { - return _isPropertyGridCategorized; - } - } - - bool IPropertyContainer.IsSortedAlphabetically - { - get - { - return _isSortedAlphabetically; - } - } - - bool IPropertyContainer.AutoGenerateProperties - { - get - { - if( this.ParentNode != null ) - { - var propertyItemPropertyDefinitions = this.GetPropertItemPropertyDefinitions(); - // No PropertyDefinitions specified : show all properties of this PropertyItem. - if( (propertyItemPropertyDefinitions == null) || (propertyItemPropertyDefinitions.Count == 0) ) - return true; - - // A PropertyDefinitions is specified : show only the properties of the PropertyDefinitions from this PropertyItem. - return this.ParentNode.AutoGenerateProperties; - } - return true; - } - } - - bool IPropertyContainer.HideInheritedProperties - { - get - { - return false; - } - } - - FilterInfo IPropertyContainer.FilterInfo - { - get { return new FilterInfo(); } - } - - bool? IPropertyContainer.IsPropertyVisible( PropertyDescriptor pd ) - { - if( _parentNode != null ) - { - return _parentNode.IsPropertyVisible( pd ); - } - - return null; - } - - - -#endregion - - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyItemCollection.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyItemCollection.cs deleted file mode 100644 index c4b6a01c..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyItemCollection.cs +++ /dev/null @@ -1,227 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Windows.Data; -using System; -using System.Collections.Specialized; -using System.Diagnostics; -using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; -using System.Linq; -using System.Collections; -using Xceed.Wpf.Toolkit.Core.Utilities; -using System.Reflection; -#if !VS2008 -using System.ComponentModel.DataAnnotations; -#endif - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - public class PropertyItemCollection : ReadOnlyObservableCollection - { - internal static readonly string CategoryPropertyName; - internal static readonly string CategoryOrderPropertyName; - internal static readonly string PropertyOrderPropertyName; - internal static readonly string DisplayNamePropertyName; - - private bool _preventNotification; - - static PropertyItemCollection() - { - PropertyItem p = null; - CategoryPropertyName = ReflectionHelper.GetPropertyOrFieldName( () => p.Category ); - CategoryOrderPropertyName = ReflectionHelper.GetPropertyOrFieldName( () => p.CategoryOrder ); - PropertyOrderPropertyName = ReflectionHelper.GetPropertyOrFieldName( () => p.PropertyOrder ); - DisplayNamePropertyName = ReflectionHelper.GetPropertyOrFieldName( () => p.DisplayName ); - } - - public PropertyItemCollection(ObservableCollection editableCollection) - :base(editableCollection) - { - EditableCollection = editableCollection; - } - - internal Predicate FilterPredicate - { - get { return GetDefaultView().Filter; } - set { GetDefaultView().Filter = value; } - } - - public ObservableCollection EditableCollection { get; private set; } - - private ICollectionView GetDefaultView() - { - return CollectionViewSource.GetDefaultView( this ); - } - - public void GroupBy( string name ) - { - GetDefaultView().GroupDescriptions.Add( new PropertyGroupDescription( name ) ); - } - - public void SortBy( string name, ListSortDirection sortDirection ) - { - GetDefaultView().SortDescriptions.Add( new SortDescription( name, sortDirection ) ); - } - - public void Filter( string text ) - { - Predicate filter = PropertyItemCollection.CreateFilter( text, this.Items, null ); - GetDefaultView().Filter = filter; - } - - protected override void OnCollectionChanged( NotifyCollectionChangedEventArgs args ) - { - if( _preventNotification ) - return; - - base.OnCollectionChanged( args ); - } - - internal void UpdateItems( IEnumerable newItems ) - { - if( newItems == null ) - throw new ArgumentNullException( "newItems" ); - - _preventNotification = true; - using( GetDefaultView().DeferRefresh() ) - { - EditableCollection.Clear(); - foreach( var item in newItems ) - { - this.EditableCollection.Add( item ); - } - } - _preventNotification = false; - OnCollectionChanged( new NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction.Reset ) ); - } - - internal void UpdateCategorization( GroupDescription groupDescription, bool isPropertyGridCategorized, bool sortAlphabetically ) - { - // Compute Display Order relative to PropertyOrderAttributes on PropertyItem - // which could be different in Alphabetical or Categorized mode. - foreach( PropertyItem item in this.Items ) - { - item.DescriptorDefinition.DisplayOrder = item.DescriptorDefinition.ComputeDisplayOrderInternal( isPropertyGridCategorized ); - item.PropertyOrder = item.DescriptorDefinition.DisplayOrder; - } - - // Clear view values - ICollectionView view = this.GetDefaultView(); - using( view.DeferRefresh() ) - { - view.GroupDescriptions.Clear(); - view.SortDescriptions.Clear(); - - // Update view values - if( groupDescription != null ) - { - view.GroupDescriptions.Add( groupDescription ); - if( sortAlphabetically ) - { - SortBy( CategoryOrderPropertyName, ListSortDirection.Ascending ); - SortBy( CategoryPropertyName, ListSortDirection.Ascending ); - } - } - - if( sortAlphabetically ) - { - SortBy( PropertyOrderPropertyName, ListSortDirection.Ascending ); - SortBy( DisplayNamePropertyName, ListSortDirection.Ascending ); - } - } - } - - internal void RefreshView() - { - GetDefaultView().Refresh(); - } - - internal static Predicate CreateFilter( string text, IList PropertyItems, IPropertyContainer propertyContainer ) - { - Predicate filter = null; - - if( !string.IsNullOrEmpty( text ) ) - { - filter = ( item ) => - { - var property = item as PropertyItem; - if( property.DisplayName != null ) - { -#if !VS2008 - var displayAttribute = PropertyGridUtilities.GetAttribute( property.PropertyDescriptor ); - if( displayAttribute != null ) - { - var canBeFiltered = displayAttribute.GetAutoGenerateFilter(); - if( canBeFiltered.HasValue && !canBeFiltered.Value ) - return false; - } -#endif - property.HighlightedText = property.DisplayName.ToLower().Contains( text.ToLower() ) ? text : null; - return (property.HighlightedText != null); - } - - return false; - }; - } - else - { - ClearFilterSubItems( PropertyItems.ToList() ); - } - - return filter; - } - - - - - - - - - - - - - - - - - - - - - - - - - private static void ClearFilterSubItems( IList items ) - { - foreach( var item in items ) - { - var propertyItem = item as PropertyItemBase; - if( propertyItem != null ) - { - propertyItem.HighlightedText = null; - - - } - } - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyItemsControl.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyItemsControl.cs deleted file mode 100644 index caca0687..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/PropertyItemsControl.cs +++ /dev/null @@ -1,109 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Windows.Controls; -using System.Windows; -using System.ComponentModel; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - /// - /// This Control is intended to be used in the template of the - /// PropertyItemBase and PropertyGrid classes to contain the - /// sub-children properties. - /// - public class PropertyItemsControl : ItemsControl - { - public PropertyItemsControl() - { - var propertyItemsControlProperties = TypeDescriptor.GetProperties( this, new Attribute[] { new PropertyFilterAttribute( PropertyFilterOptions.All ) } ); - var prop1 = propertyItemsControlProperties.Find( "VirtualizingPanel.IsVirtualizingWhenGrouping", false ); - if( prop1 != null ) - { - prop1.SetValue( this, true ); - } - var prop2 = propertyItemsControlProperties.Find( "VirtualizingPanel.CacheLengthUnit", false ); - if( prop2 != null ) - { - prop2.SetValue( this, Enum.ToObject( prop2.PropertyType, 1 ) ); - } - } - - #region PreparePropertyItemEvent Attached Routed Event - - internal static readonly RoutedEvent PreparePropertyItemEvent = EventManager.RegisterRoutedEvent( "PreparePropertyItem", RoutingStrategy.Bubble, typeof( PropertyItemEventHandler ), typeof( PropertyItemsControl ) ); - internal event PropertyItemEventHandler PreparePropertyItem - { - add - { - AddHandler( PropertyItemsControl.PreparePropertyItemEvent, value ); - } - remove - { - RemoveHandler( PropertyItemsControl.PreparePropertyItemEvent, value ); - } - } - - private void RaisePreparePropertyItemEvent( PropertyItemBase propertyItem, object item ) - { - this.RaiseEvent( new PropertyItemEventArgs( PropertyItemsControl.PreparePropertyItemEvent, this, propertyItem, item ) ); - } - - #endregion - - #region ClearPropertyItemEvent Attached Routed Event - - internal static readonly RoutedEvent ClearPropertyItemEvent = EventManager.RegisterRoutedEvent( "ClearPropertyItem", RoutingStrategy.Bubble, typeof( PropertyItemEventHandler ), typeof( PropertyItemsControl ) ); - internal event PropertyItemEventHandler ClearPropertyItem - { - add - { - AddHandler( PropertyItemsControl.ClearPropertyItemEvent, value ); - } - remove - { - RemoveHandler( PropertyItemsControl.ClearPropertyItemEvent, value ); - } - } - - private void RaiseClearPropertyItemEvent( PropertyItemBase propertyItem, object item ) - { - this.RaiseEvent( new PropertyItemEventArgs( PropertyItemsControl.ClearPropertyItemEvent, this, propertyItem, item ) ); - } - - #endregion - - protected override bool IsItemItsOwnContainerOverride( object item ) - { - return ( item is PropertyItemBase ); - } - - - protected override void PrepareContainerForItemOverride( DependencyObject element, object item ) - { - base.PrepareContainerForItemOverride( element, item ); - this.RaisePreparePropertyItemEvent( ( PropertyItemBase )element, item ); - } - - protected override void ClearContainerForItemOverride( DependencyObject element, object item ) - { - this.RaiseClearPropertyItemEvent( ( PropertyItemBase )element, item ); - base.ClearContainerForItemOverride( element, item ); - } - - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/StringConstants.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/StringConstants.cs deleted file mode 100644 index dda2f153..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/StringConstants.cs +++ /dev/null @@ -1,56 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - public static class StringConstants - { - public static string Local - { - get { return "Local"; } - } - - public static string Resource - { - get { return "Resource"; } - } - - public static string Databinding - { - get { return "Databinding"; } - } - - public static string Inheritance - { - get { return "Inheritance"; } - } - - public static string StyleSetter - { - get { return "Style Setter"; } - } - - public static string Default - { - get { return "Default"; } - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/TargetPropertyType.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/TargetPropertyType.cs deleted file mode 100644 index 734ba65d..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/TargetPropertyType.cs +++ /dev/null @@ -1,59 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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 Xceed.Wpf.Toolkit.Core.Utilities; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - /// - /// This class is intended to provide the "Type" target - /// for property definitions or editor definitions when - /// using Property Element Syntax. - /// - public sealed class TargetPropertyType - { - private Type _type; - private bool _sealed; - - public Type Type - { - get { return _type; } - set - { - if( _sealed ) - throw new InvalidOperationException( - string.Format( - "{0}.Type property cannot be modified once the instance is used", - typeof( TargetPropertyType ) ) ); - - _type = value; - } - } - - internal void Seal() - { - if( _type == null ) - throw new InvalidOperationException( - string.Format( "{0}.Type property must be initialized", typeof( TargetPropertyType ) ) ); - - _sealed = true; - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/TrimmedTextBlock.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/TrimmedTextBlock.cs deleted file mode 100644 index ec077065..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Implementation/TrimmedTextBlock.cs +++ /dev/null @@ -1,186 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - 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; -using System.Windows.Controls; -using System.Windows.Documents; -using System.Windows.Media; - -namespace Xceed.Wpf.Toolkit.PropertyGrid -{ - public class TrimmedTextBlock : TextBlock - { - #region Constructor - - public TrimmedTextBlock() - { - this.SizeChanged += this.TrimmedTextBlock_SizeChanged; - } - - #endregion - - #region IsTextTrimmed Property - - public static readonly DependencyProperty IsTextTrimmedProperty = DependencyProperty.Register( "IsTextTrimmed", typeof( bool ), typeof( TrimmedTextBlock ), new PropertyMetadata( false, OnIsTextTrimmedChanged ) ); - public bool IsTextTrimmed - { - get - { - return ( bool )GetValue( IsTextTrimmedProperty ); - } - private set - { - SetValue( IsTextTrimmedProperty, value ); - } - } - - private static void OnIsTextTrimmedChanged( DependencyObject d, DependencyPropertyChangedEventArgs e ) - { - var textBlock = d as TrimmedTextBlock; - if( textBlock != null ) - { - textBlock.OnIsTextTrimmedChanged( ( bool )e.OldValue, ( bool )e.NewValue ); - } - } - - private void OnIsTextTrimmedChanged( bool oldValue, bool newValue ) - { - this.ToolTip = ( newValue ) ? this.Text : null; - } - - #endregion - - #region HighlightedBrush - - public static readonly DependencyProperty HighlightedBrushProperty = DependencyProperty.Register( "HighlightedBrush", typeof( Brush ), typeof( TrimmedTextBlock ), new FrameworkPropertyMetadata( Brushes.Yellow ) ); - - public Brush HighlightedBrush - { - get - { - return ( Brush )GetValue( HighlightedBrushProperty ); - } - set - { - SetValue( HighlightedBrushProperty, value ); - } - } - - #endregion - - #region HighlightedText - - public static readonly DependencyProperty HighlightedTextProperty = DependencyProperty.Register( "HighlightedText", typeof( string ), typeof( TrimmedTextBlock ), new FrameworkPropertyMetadata( null, HighlightedTextChanged ) ); - - public string HighlightedText - { - get - { - return ( string )GetValue( HighlightedTextProperty ); - } - set - { - SetValue( HighlightedTextProperty, value ); - } - } - - private static void HighlightedTextChanged( DependencyObject sender, DependencyPropertyChangedEventArgs e ) - { - var trimmedTextBlock = sender as TrimmedTextBlock; - if( trimmedTextBlock != null ) - { - trimmedTextBlock.HighlightedTextChanged( ( string )e.OldValue, ( string )e.NewValue ); - } - } - - protected virtual void HighlightedTextChanged( string oldValue, string newValue ) - { - if( this.Text.Length == 0 ) - return; - - // Set original text without highlight. - if( newValue == null ) - { - var newrRun = new Run( this.Text ); - this.Inlines.Clear(); - this.Inlines.Add( newrRun ); - - return; - } - - var startHighlightedIndex = this.Text.IndexOf( newValue, StringComparison.InvariantCultureIgnoreCase ); - var endHighlightedIndex = startHighlightedIndex + newValue.Length; - - var startUnHighlightedText = this.Text.Substring( 0, startHighlightedIndex ); - var highlightedText = this.Text.Substring( startHighlightedIndex, newValue.Length ); - var endUnHighlightedText = this.Text.Substring( endHighlightedIndex, this.Text.Length - endHighlightedIndex ); - - this.Inlines.Clear(); - - // Start Un-Highlighted text - var run = new Run( startUnHighlightedText ); - this.Inlines.Add( run ); - - // Highlighted text - run = new Run( highlightedText ); - run.Background = this.HighlightedBrush; - this.Inlines.Add( run ); - - // End Un-Highlighted text - run = new Run( endUnHighlightedText ); - this.Inlines.Add( run ); - } - - #endregion - - #region Event Handler - - private void TrimmedTextBlock_SizeChanged(object sender, SizeChangedEventArgs e) - { - var textBlock = sender as TextBlock; - if( textBlock != null ) - { - this.IsTextTrimmed = this.GetIsTextTrimmed( textBlock ); - } - } - - #endregion - - #region Private Methods - - private bool GetIsTextTrimmed( TextBlock textBlock ) - { - if( textBlock == null ) - return false; - if( textBlock.TextTrimming == TextTrimming.None ) - return false; - if( textBlock.TextWrapping != TextWrapping.NoWrap ) - return false; - - var textBlockActualWidth = textBlock.ActualWidth; - textBlock.Measure( new Size( double.MaxValue, double.MaxValue ) ); - var textBlockDesiredWidth = textBlock.DesiredSize.Width; - - return ( textBlockActualWidth < textBlockDesiredWidth ); - } - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Themes/Aero2.NormalColor.xaml b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Themes/Aero2.NormalColor.xaml deleted file mode 100644 index 56c66699..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Themes/Aero2.NormalColor.xaml +++ /dev/null @@ -1,1312 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Themes/Generic.xaml b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Themes/Generic.xaml deleted file mode 100644 index 9463a5a9..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/PropertyGrid/Themes/Generic.xaml +++ /dev/null @@ -1,1432 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/TimePicker/Implementation/TimePicker.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/TimePicker/Implementation/TimePicker.cs index 7f3959da..c27501be 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/TimePicker/Implementation/TimePicker.cs +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/TimePicker/Implementation/TimePicker.cs @@ -16,535 +16,528 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using Xceed.Wpf.Toolkit.Core.Utilities; -using System.Collections.Generic; using Xceed.Wpf.Toolkit.Primitives; namespace Xceed.Wpf.Toolkit { - [TemplatePart( Name = PART_TimeListItems, Type = typeof( ListBox ) )] - public class TimePicker : DateTimePickerBase - { - private const string PART_TimeListItems = "PART_TimeListItems"; - - #region Members - - private ListBox _timeListBox; - private bool _isListBoxInvalid = true; - internal static readonly TimeSpan EndTimeDefaultValue = new TimeSpan( 23, 59, 0 ); - internal static readonly TimeSpan StartTimeDefaultValue = new TimeSpan( 0, 0, 0 ); - internal static readonly TimeSpan TimeIntervalDefaultValue = new TimeSpan( 1, 0, 0 ); - - #endregion //Members - - #region Properties - - #region EndTime - - public static readonly DependencyProperty EndTimeProperty = DependencyProperty.Register( "EndTime", typeof( TimeSpan ), typeof( TimePicker ), new UIPropertyMetadata( EndTimeDefaultValue, new PropertyChangedCallback( OnEndTimeChanged ), new CoerceValueCallback( OnCoerceEndTime ) ) ); - - private static object OnCoerceEndTime( DependencyObject o, object value ) - { - TimePicker timePicker = o as TimePicker; - if( timePicker != null ) - return timePicker.OnCoerceEndTime( ( TimeSpan )value ); - else - return value; - } - - private static void OnEndTimeChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - TimePicker timePicker = o as TimePicker; - if( timePicker != null ) - timePicker.OnEndTimeChanged( ( TimeSpan )e.OldValue, ( TimeSpan )e.NewValue ); - } - - protected virtual TimeSpan OnCoerceEndTime( TimeSpan value ) - { - ValidateTime( value ); - return value; - } - - protected virtual void OnEndTimeChanged( TimeSpan oldValue, TimeSpan newValue ) + [TemplatePart(Name = PART_TimeListItems, Type = typeof(ListBox))] + public class TimePicker : DateTimePickerBase { - InvalidateListBoxItems(); - } + private const string PART_TimeListItems = "PART_TimeListItems"; - public TimeSpan EndTime - { - get - { - return ( TimeSpan )GetValue( EndTimeProperty ); - } - set - { - SetValue( EndTimeProperty, value ); - } - } + #region Members - #endregion //EndTime + private ListBox _timeListBox; + private bool _isListBoxInvalid = true; + internal static readonly TimeSpan EndTimeDefaultValue = new TimeSpan(23, 59, 0); + internal static readonly TimeSpan StartTimeDefaultValue = new TimeSpan(0, 0, 0); + internal static readonly TimeSpan TimeIntervalDefaultValue = new TimeSpan(1, 0, 0); - #region Format + #endregion //Members - protected override void OnFormatChanged( DateTimeFormat oldValue, DateTimeFormat newValue ) - { - base.OnFormatChanged( oldValue, newValue ); - InvalidateListBoxItems(); - } + #region Properties - #endregion //Format + #region EndTime - #region MaxDropDownHeight + public static readonly DependencyProperty EndTimeProperty = DependencyProperty.Register("EndTime", typeof(TimeSpan), typeof(TimePicker), new UIPropertyMetadata(EndTimeDefaultValue, new PropertyChangedCallback(OnEndTimeChanged), new CoerceValueCallback(OnCoerceEndTime))); - public static readonly DependencyProperty MaxDropDownHeightProperty = DependencyProperty.Register( "MaxDropDownHeight", typeof( double ), typeof( TimePicker ), new UIPropertyMetadata( 130d, OnMaxDropDownHeightChanged ) ); - public double MaxDropDownHeight - { - get - { - return ( double )GetValue( MaxDropDownHeightProperty ); - } - set - { - SetValue( MaxDropDownHeightProperty, value ); - } - } - - private static void OnMaxDropDownHeightChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - TimePicker timePicker = o as TimePicker; - if( timePicker != null ) - timePicker.OnMaxDropDownHeightChanged( ( double )e.OldValue, ( double )e.NewValue ); - } + private static object OnCoerceEndTime(DependencyObject o, object value) + { + TimePicker timePicker = o as TimePicker; + if (timePicker != null) + return timePicker.OnCoerceEndTime((TimeSpan)value); + else + return value; + } - protected virtual void OnMaxDropDownHeightChanged( double oldValue, double newValue ) - { - // TODO: Add your property changed side-effects. Descendants can override as well. - } + private static void OnEndTimeChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) + { + TimePicker timePicker = o as TimePicker; + if (timePicker != null) + timePicker.OnEndTimeChanged((TimeSpan)e.OldValue, (TimeSpan)e.NewValue); + } - #endregion + protected virtual TimeSpan OnCoerceEndTime(TimeSpan value) + { + ValidateTime(value); + return value; + } - #region StartTime + protected virtual void OnEndTimeChanged(TimeSpan oldValue, TimeSpan newValue) + { + InvalidateListBoxItems(); + } - public static readonly DependencyProperty StartTimeProperty = DependencyProperty.Register( "StartTime", typeof( TimeSpan ), typeof( TimePicker ), new UIPropertyMetadata( StartTimeDefaultValue, new PropertyChangedCallback( OnStartTimeChanged ), new CoerceValueCallback( OnCoerceStartTime ) ) ); + public TimeSpan? EndTime + { + get + { + return (TimeSpan?)GetValue(EndTimeProperty); + } + set + { + SetValue(EndTimeProperty, value); + } + } - private static object OnCoerceStartTime( DependencyObject o, object value ) - { - TimePicker timePicker = o as TimePicker; - if( timePicker != null ) - return timePicker.OnCoerceStartTime( ( TimeSpan )value ); - else - return value; - } + #endregion //EndTime - private static void OnStartTimeChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - TimePicker timePicker = o as TimePicker; - if( timePicker != null ) - timePicker.OnStartTimeChanged( ( TimeSpan )e.OldValue, ( TimeSpan )e.NewValue ); - } + #region Format - protected virtual TimeSpan OnCoerceStartTime( TimeSpan value ) - { - ValidateTime( value ); - return value; - } + protected override void OnFormatChanged(DateTimeFormat oldValue, DateTimeFormat newValue) + { + base.OnFormatChanged(oldValue, newValue); + InvalidateListBoxItems(); + } - protected virtual void OnStartTimeChanged( TimeSpan oldValue, TimeSpan newValue ) - { - InvalidateListBoxItems(); - } + #endregion //Format - public TimeSpan StartTime - { - get - { - return ( TimeSpan )GetValue( StartTimeProperty ); - } - set - { - SetValue( StartTimeProperty, value ); - } - } + #region MaxDropDownHeight + public static readonly DependencyProperty MaxDropDownHeightProperty = DependencyProperty.Register("MaxDropDownHeight", typeof(double), typeof(TimePicker), new UIPropertyMetadata(130d, OnMaxDropDownHeightChanged)); + public double MaxDropDownHeight + { + get + { + return (double)GetValue(MaxDropDownHeightProperty); + } + set + { + SetValue(MaxDropDownHeightProperty, value); + } + } - #endregion //StartTime + private static void OnMaxDropDownHeightChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) + { + TimePicker timePicker = o as TimePicker; + if (timePicker != null) + timePicker.OnMaxDropDownHeightChanged((double)e.OldValue, (double)e.NewValue); + } - #region TimeInterval + protected virtual void OnMaxDropDownHeightChanged(double oldValue, double newValue) + { + // TODO: Add your property changed side-effects. Descendants can override as well. + } - public static readonly DependencyProperty TimeIntervalProperty = DependencyProperty.Register( "TimeInterval", typeof( TimeSpan ), typeof( TimePicker ), new UIPropertyMetadata( TimeIntervalDefaultValue, OnTimeIntervalChanged ) ); - public TimeSpan TimeInterval - { - get - { - return ( TimeSpan )GetValue( TimeIntervalProperty ); - } - set - { - SetValue( TimeIntervalProperty, value ); - } - } + #endregion - private static object OnCoerceTimeInterval( DependencyObject o, object value ) - { - TimePicker timePicker = o as TimePicker; - if( timePicker != null ) - return timePicker.OnCoerceTimeInterval( ( TimeSpan )value ); - else - return value; - } + #region StartTime - private static void OnTimeIntervalChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - TimePicker timePicker = o as TimePicker; - if( timePicker != null ) - timePicker.OnTimeIntervalChanged( ( TimeSpan )e.OldValue, ( TimeSpan )e.NewValue ); - } + public static readonly DependencyProperty StartTimeProperty = DependencyProperty.Register("StartTime", typeof(TimeSpan), typeof(TimePicker), new UIPropertyMetadata(StartTimeDefaultValue, new PropertyChangedCallback(OnStartTimeChanged), new CoerceValueCallback(OnCoerceStartTime))); - protected virtual TimeSpan OnCoerceTimeInterval( TimeSpan value ) - { - ValidateTime( value ); + private static object OnCoerceStartTime(DependencyObject o, object value) + { + TimePicker timePicker = o as TimePicker; + if (timePicker != null) + return timePicker.OnCoerceStartTime((TimeSpan)value); + else + return value; + } - if( value.Ticks == 0L ) - throw new ArgumentException( "TimeInterval must be greater than zero" ); + private static void OnStartTimeChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) + { + TimePicker timePicker = o as TimePicker; + if (timePicker != null) + timePicker.OnStartTimeChanged((TimeSpan)e.OldValue, (TimeSpan)e.NewValue); + } - return value; - } + protected virtual TimeSpan OnCoerceStartTime(TimeSpan value) + { + ValidateTime(value); + return value; + } + protected virtual void OnStartTimeChanged(TimeSpan oldValue, TimeSpan newValue) + { + InvalidateListBoxItems(); + } - protected virtual void OnTimeIntervalChanged( TimeSpan oldValue, TimeSpan newValue ) - { - InvalidateListBoxItems(); - } + public TimeSpan? StartTime + { + get + { + return (TimeSpan)GetValue(StartTimeProperty); + } + set + { + SetValue(StartTimeProperty, value); + } + } - #endregion //TimeInterval - #endregion //Properties + #endregion //StartTime - #region Constructors + #region TimeInterval - static TimePicker() - { - DefaultStyleKeyProperty.OverrideMetadata( typeof( TimePicker ), new FrameworkPropertyMetadata( typeof( TimePicker ) ) ); - FormatProperty.OverrideMetadata( typeof( TimePicker ), new UIPropertyMetadata( DateTimeFormat.ShortTime ) ); - UpdateValueOnEnterKeyProperty.OverrideMetadata( typeof( TimePicker ), new FrameworkPropertyMetadata( true ) ); - } + public static readonly DependencyProperty TimeIntervalProperty = DependencyProperty.Register("TimeInterval", typeof(TimeSpan), typeof(TimePicker), new UIPropertyMetadata(TimeIntervalDefaultValue, OnTimeIntervalChanged)); + public TimeSpan? TimeInterval + { + get + { + return (TimeSpan?)GetValue(TimeIntervalProperty); + } + set + { + SetValue(TimeIntervalProperty, value); + } + } - #endregion //Constructors + private static void OnTimeIntervalChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) + { + TimePicker timePicker = o as TimePicker; + if (timePicker != null) + timePicker.OnTimeIntervalChanged((TimeSpan)e.OldValue, (TimeSpan)e.NewValue); + } - #region Base Class Overrides + protected virtual TimeSpan OnCoerceTimeInterval(TimeSpan value) + { + ValidateTime(value); - protected override void OnFormatStringChanged( string oldValue, string newValue ) - { - if( this.Format == DateTimeFormat.Custom ) - { - InvalidateListBoxItems(); - } - base.OnFormatStringChanged( oldValue, newValue ); - } + if (value.Ticks == 0L) + throw new ArgumentException("TimeInterval must be greater than zero"); - protected override void OnMaximumChanged( DateTime? oldValue, DateTime? newValue ) - { - base.OnMaximumChanged( oldValue, newValue ); - this.InvalidateListBoxItems(); - } + return value; + } - protected override void OnMinimumChanged( DateTime? oldValue, DateTime? newValue ) - { - base.OnMinimumChanged( oldValue, newValue ); - this.InvalidateListBoxItems(); - } + protected virtual void OnTimeIntervalChanged(TimeSpan oldValue, TimeSpan newValue) + { + InvalidateListBoxItems(); + } - protected override void OnValueChanged( DateTime? oldValue, DateTime? newValue ) - { - base.OnValueChanged( oldValue, newValue ); - - // ListBox content may be affected if value's date changed and the date was - // or is equal to Minimum or Maximum value. - bool invalidate = false; - - if( DateTimeUtilities.IsSameDate( this.Minimum, oldValue ) - != DateTimeUtilities.IsSameDate( this.Minimum, newValue ) ) - { - invalidate = true; - } - - if( DateTimeUtilities.IsSameDate( this.Maximum, oldValue ) - != DateTimeUtilities.IsSameDate( this.Maximum, newValue ) ) - { - invalidate = true; - } - - // A value change can affect the display of the listbox items - // if the Date part of the value has changed. This is the case when - // the display text of the items contains part of the Date values. - if( oldValue.GetValueOrDefault().Date != newValue.GetValueOrDefault().Date ) - { - invalidate = true; - } - - if( invalidate ) - { - //Invalidate the entire listbox content - this.InvalidateListBoxItems(); - } - else - { - //Just update the selected item - this.UpdateListBoxSelectedItem(); - } - } + #endregion //TimeInterval - protected override void Popup_Opened( object sender, EventArgs e ) - { - base.Popup_Opened( sender, e ); + #endregion //Properties - if( _timeListBox != null ) - { - this.UpdateListBoxItems(); + #region Constructors - var time = (this.Value != null) ? this.Value.Value.TimeOfDay : TimePicker.StartTimeDefaultValue; - var nearestItem = this.GetNearestTimeItem( time ); - if( nearestItem != null ) + static TimePicker() { - _timeListBox.ScrollIntoView( nearestItem ); - this.UpdateListBoxSelectedItem(); + DefaultStyleKeyProperty.OverrideMetadata(typeof(TimePicker), new FrameworkPropertyMetadata(typeof(TimePicker))); + FormatProperty.OverrideMetadata(typeof(TimePicker), new UIPropertyMetadata(DateTimeFormat.ShortTime)); + UpdateValueOnEnterKeyProperty.OverrideMetadata(typeof(TimePicker), new FrameworkPropertyMetadata(true)); } - _timeListBox.Focus(); - } - } - public override void OnApplyTemplate() - { - if( this.TextBox != null ) - { - this.TextBox.GotKeyboardFocus -= this.TextBoxSpinner_GotKeyboardFocus; - } - if( this.Spinner != null ) - { - this.Spinner.GotKeyboardFocus -= this.TextBoxSpinner_GotKeyboardFocus; - } - - base.OnApplyTemplate(); - - if( this.TextBox != null ) - { - this.TextBox.GotKeyboardFocus += this.TextBoxSpinner_GotKeyboardFocus; - } - if( this.Spinner != null ) - { - this.Spinner.GotKeyboardFocus += this.TextBoxSpinner_GotKeyboardFocus; - } - - if( _timeListBox != null ) - { - _timeListBox.SelectionChanged -= this.TimeListBox_SelectionChanged; - _timeListBox.MouseUp -= this.TimeListBox_MouseUp; - } - - _timeListBox = this.GetTemplateChild( PART_TimeListItems ) as ListBox; - - if( _timeListBox != null ) - { - _timeListBox.SelectionChanged += this.TimeListBox_SelectionChanged; - _timeListBox.MouseUp += this.TimeListBox_MouseUp; - - this.InvalidateListBoxItems(); - } - } - - #endregion //Base Class Overrides + #endregion //Constructors - #region Internal Methods + #region Base Class Overrides - internal void UpdateTempValue( DateTime? newDate ) - { - var date = newDate ?? this.ContextNow; - // Set TimePicker TextBox (not Value) to DatetimePicker TextBox. - if( this.TextBox != null ) - { - this.TextBox.Text = date.ToString( this.GetFormatString( this.Format ), this.CultureInfo ); - } - // Set TimePicker TempValue to the same value. - // It will be used when selecting a new date in Calendar (to keep the set time) and - // and when incrementing the TimePicker inside a DateTimePicker (to get the current time when Value is not up to date). - this.TempValue = date; - } + protected override void OnFormatStringChanged(string oldValue, string newValue) + { + if (this.Format == DateTimeFormat.Custom) + { + InvalidateListBoxItems(); + } + base.OnFormatStringChanged(oldValue, newValue); + } - #endregion + protected override void OnMaximumChanged(DateTime? oldValue, DateTime? newValue) + { + base.OnMaximumChanged(oldValue, newValue); + this.InvalidateListBoxItems(); + } - #region Event Handlers - private void TimeListBox_SelectionChanged( object sender, SelectionChangedEventArgs e ) - { - if( e.AddedItems.Count > 0 ) - { - TimeItem selectedTimeListItem = ( TimeItem )e.AddedItems[ 0 ]; - var time = selectedTimeListItem.Time; - - //if( this.UpdateValueOnEnterKey ) - //{ - // var currentValue = this.ConvertTextToValue( this.TextBox.Text ); - // var date = currentValue ?? this.ContextNow; - // var newValue = new DateTime( date.Year, date.Month, date.Day, time.Hours, time.Minutes, time.Seconds, time.Milliseconds, date.Kind ); - // this.TextBox.Text = newValue.ToString( this.GetFormatString( this.Format ), this.CultureInfo ); - //} - //else - //{ - var date = this.Value ?? this.ContextNow; - this.Value = new DateTime( date.Year, date.Month, date.Day, time.Hours, time.Minutes, time.Seconds, time.Milliseconds, date.Kind ); - //} - } - } + protected override void OnMinimumChanged(DateTime? oldValue, DateTime? newValue) + { + base.OnMinimumChanged(oldValue, newValue); + this.InvalidateListBoxItems(); + } - private void TextBoxSpinner_GotKeyboardFocus( object sender, KeyboardFocusChangedEventArgs e ) - { - this.ClosePopup( true ); - } + protected override void OnValueChanged(DateTime? oldValue, DateTime? newValue) + { + base.OnValueChanged(oldValue, newValue); + + // ListBox content may be affected if value's date changed and the date was + // or is equal to Minimum or Maximum value. + bool invalidate = false; + + if (DateTimeUtilities.IsSameDate(this.Minimum, oldValue) + != DateTimeUtilities.IsSameDate(this.Minimum, newValue)) + { + invalidate = true; + } + + if (DateTimeUtilities.IsSameDate(this.Maximum, oldValue) + != DateTimeUtilities.IsSameDate(this.Maximum, newValue)) + { + invalidate = true; + } + + // A value change can affect the display of the listbox items + // if the Date part of the value has changed. This is the case when + // the display text of the items contains part of the Date values. + if (oldValue.GetValueOrDefault().Date != newValue.GetValueOrDefault().Date) + { + invalidate = true; + } + + if (invalidate) + { + //Invalidate the entire listbox content + this.InvalidateListBoxItems(); + } + else + { + //Just update the selected item + this.UpdateListBoxSelectedItem(); + } + } - private void TimeListBox_MouseUp( object sender, MouseButtonEventArgs e ) - { - this.ClosePopup( true ); - } + protected override void Popup_Opened(object sender, EventArgs e) + { + base.Popup_Opened(sender, e); + + if (_timeListBox != null) + { + this.UpdateListBoxItems(); + + var time = (this.Value != null) ? this.Value.Value.TimeOfDay : TimePicker.StartTimeDefaultValue; + var nearestItem = this.GetNearestTimeItem(time); + if (nearestItem != null) + { + _timeListBox.ScrollIntoView(nearestItem); + this.UpdateListBoxSelectedItem(); + } + _timeListBox.Focus(); + } + } - #endregion //Event Handlers + public override void OnApplyTemplate() + { + if (this.TextBox != null) + { + this.TextBox.GotKeyboardFocus -= this.TextBoxSpinner_GotKeyboardFocus; + } + if (this.Spinner != null) + { + this.Spinner.GotKeyboardFocus -= this.TextBoxSpinner_GotKeyboardFocus; + } + + base.OnApplyTemplate(); + + if (this.TextBox != null) + { + this.TextBox.GotKeyboardFocus += this.TextBoxSpinner_GotKeyboardFocus; + } + if (this.Spinner != null) + { + this.Spinner.GotKeyboardFocus += this.TextBoxSpinner_GotKeyboardFocus; + } + + if (_timeListBox != null) + { + _timeListBox.SelectionChanged -= this.TimeListBox_SelectionChanged; + _timeListBox.MouseUp -= this.TimeListBox_MouseUp; + } + + _timeListBox = this.GetTemplateChild(PART_TimeListItems) as ListBox; + + if (_timeListBox != null) + { + _timeListBox.SelectionChanged += this.TimeListBox_SelectionChanged; + _timeListBox.MouseUp += this.TimeListBox_MouseUp; + + this.InvalidateListBoxItems(); + } + } - #region Methods + #endregion //Base Class Overrides - private void ValidateTime( TimeSpan time ) - { - if( time.TotalHours >= 24d ) - throw new ArgumentException( "Time value cannot be greater than or equal to 24 hours." ); - } + #region Internal Methods - public IEnumerable GenerateTimeListItemsSource() - { - TimeSpan time = StartTime; - TimeSpan endTime = EndTime; + internal void UpdateTempValue(DateTime? newDate) + { + var date = newDate ?? this.ContextNow; + // Set TimePicker TextBox (not Value) to DatetimePicker TextBox. + if (this.TextBox != null) + { + this.TextBox.Text = date.ToString(this.GetFormatString(this.Format), this.CultureInfo); + } + // Set TimePicker TempValue to the same value. + // It will be used when selecting a new date in Calendar (to keep the set time) and + // and when incrementing the TimePicker inside a DateTimePicker (to get the current time when Value is not up to date). + this.TempValue = date; + } - if( endTime <= time ) - { - endTime = EndTimeDefaultValue; - time = StartTimeDefaultValue; - } + #endregion - // Limit the content of the list to the Minimum or Maximum - // if the date is set to the Minimum or Maximum. - if( this.Value.HasValue ) - { - DateTime date = this.Value.Value; - DateTime minDate = this.Minimum.GetValueOrDefault( System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.Calendar.MinSupportedDateTime ); - DateTime maxDate = this.Maximum.GetValueOrDefault( System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.Calendar.MaxSupportedDateTime ); - TimeSpan minTime = minDate.TimeOfDay; - TimeSpan maxTime = maxDate.TimeOfDay; + #region Event Handlers - if( date.Date == minDate.Date && time.Ticks < minTime.Ticks ) + private void TimeListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { - time = minTime; + if (e.AddedItems.Count > 0) + { + TimeItem selectedTimeListItem = (TimeItem)e.AddedItems[0]; + var time = selectedTimeListItem.Time; + + //if( this.UpdateValueOnEnterKey ) + //{ + // var currentValue = this.ConvertTextToValue( this.TextBox.Text ); + // var date = currentValue ?? this.ContextNow; + // var newValue = new DateTime( date.Year, date.Month, date.Day, time.Hours, time.Minutes, time.Seconds, time.Milliseconds, date.Kind ); + // this.TextBox.Text = newValue.ToString( this.GetFormatString( this.Format ), this.CultureInfo ); + //} + //else + //{ + var date = this.Value ?? this.ContextNow; + this.Value = new DateTime(date.Year, date.Month, date.Day, time.Hours, time.Minutes, time.Seconds, time.Milliseconds, date.Kind); + //} + } } - if( date.Date == maxDate.Date && endTime.Ticks > maxTime.Ticks ) + private void TextBoxSpinner_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { - endTime = maxTime; + this.ClosePopup(true); } - if( endTime < time ) + private void TimeListBox_MouseUp(object sender, MouseButtonEventArgs e) { - time = endTime; + this.ClosePopup(true); } - } + #endregion //Event Handlers - TimeSpan timeInterval = TimeInterval; - List timeItemList = new List(); + #region Methods - if( time != null && endTime != null && timeInterval != null && timeInterval.Ticks > 0 ) - { - while( time <= endTime ) + private static void ValidateTime(TimeSpan time) { - timeItemList.Add( this.CreateTimeItem( time ) ); - time = time.Add( timeInterval ); + if (time.TotalHours >= 24d) + throw new ArgumentException("Time value cannot be greater than or equal to 24 hours."); } - } - return timeItemList; - } - - protected virtual TimeItem CreateTimeItem( TimeSpan time ) - { - var date = Value ?? this.ContextNow; - string formatString = this.GetFormatString( (DateTimeFormat)this.Format ); - return new TimeItem( date.Date.Add( time ).ToString( formatString, CultureInfo ), time ); - } - private void UpdateListBoxSelectedItem() - { - if( _timeListBox != null ) - { - TimeItem time = null; - if( Value != null ) + public IEnumerable GenerateTimeListItemsSource() { - time = this.CreateTimeItem( Value.Value.TimeOfDay ); - if( !_timeListBox.Items.Contains( time ) ) - { - time = null; - } + var time = StartTime; + var endTime = EndTime; + + if (endTime <= time) + { + endTime = EndTimeDefaultValue; + time = StartTimeDefaultValue; + } + + // Limit the content of the list to the Minimum or Maximum + // if the date is set to the Minimum or Maximum. + if (this.Value.HasValue) + { + DateTime date = this.Value.Value; + DateTime minDate = this.Minimum.GetValueOrDefault(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.Calendar.MinSupportedDateTime); + DateTime maxDate = this.Maximum.GetValueOrDefault(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.Calendar.MaxSupportedDateTime); + TimeSpan minTime = minDate.TimeOfDay; + TimeSpan maxTime = maxDate.TimeOfDay; + + if (date.Date == minDate.Date && time.Value.Ticks < minTime.Ticks) + { + time = minTime; + } + + if (date.Date == maxDate.Date && endTime.Value.Ticks > maxTime.Ticks) + { + endTime = maxTime; + } + + if (endTime < time) + { + time = endTime; + } + } + + + var timeInterval = TimeInterval; + List timeItemList = new List(); + + if (time != null && endTime != null && timeInterval != null && timeInterval.Value.Ticks > 0) + { + while (time <= endTime) + { + timeItemList.Add(this.CreateTimeItem(time.Value)); + time = time.Value.Add(timeInterval.Value); + } + } + return timeItemList; } - _timeListBox.SelectedItem = time; - } - } + protected virtual TimeItem CreateTimeItem(TimeSpan time) + { + var date = Value ?? this.ContextNow; + string formatString = this.GetFormatString(Format); + return new TimeItem(date.Date.Add(time).ToString(formatString, CultureInfo), time); + } - private void InvalidateListBoxItems() - { - _isListBoxInvalid = true; - if( IsOpen ) - { - UpdateListBoxItems(); - } - } + private void UpdateListBoxSelectedItem() + { + if (_timeListBox != null) + { + TimeItem time = null; + if (Value != null) + { + time = this.CreateTimeItem(Value.Value.TimeOfDay); + if (!_timeListBox.Items.Contains(time)) + { + time = null; + } + } + + _timeListBox.SelectedItem = time; + } + } - private void UpdateListBoxItems() - { - if( _timeListBox != null ) - { - if( _isListBoxInvalid ) + private void InvalidateListBoxItems() { - _timeListBox.ItemsSource = GenerateTimeListItemsSource(); - UpdateListBoxSelectedItem(); - _isListBoxInvalid = false; + _isListBoxInvalid = true; + if (IsOpen) + { + UpdateListBoxItems(); + } } - } - } - private TimeItem GetNearestTimeItem( TimeSpan time ) - { - if( _timeListBox != null ) - { - int itemCount = _timeListBox.Items.Count; - for( int i = 0; i < itemCount; i++ ) + private void UpdateListBoxItems() { - TimeItem timeItem = _timeListBox.Items[ i ] as TimeItem; - if( timeItem != null ) - { - if( timeItem.Time >= time ) - return timeItem; - } + if (_timeListBox != null) + { + if (_isListBoxInvalid) + { + _timeListBox.ItemsSource = GenerateTimeListItemsSource(); + UpdateListBoxSelectedItem(); + _isListBoxInvalid = false; + } + } } - //They are all less than the searched time. - //Return the last one. (Should also be the greater one.) - if( itemCount > 0 ) + private TimeItem GetNearestTimeItem(TimeSpan time) { - return _timeListBox.Items[ itemCount - 1 ] as TimeItem; + if (_timeListBox != null) + { + int itemCount = _timeListBox.Items.Count; + for (int i = 0; i < itemCount; i++) + { + TimeItem timeItem = _timeListBox.Items[i] as TimeItem; + if (timeItem != null) + { + if (timeItem.Time >= time) + { + return timeItem; + } + } + } + + //They are all less than the searched time. + //Return the last one. (Should also be the greater one.) + if (itemCount > 0) + { + return _timeListBox.Items[itemCount - 1] as TimeItem; + } + } + + return null; } - } - return null; + #endregion //Methods } - - #endregion //Methods - } } diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Xceed.Wpf.Toolkit.csproj b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Xceed.Wpf.Toolkit.csproj index 937f8edf..c094e86c 100644 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Xceed.Wpf.Toolkit.csproj +++ b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Xceed.Wpf.Toolkit.csproj @@ -1,6 +1,6 @@  - net472 + net472;net8.0-windows Library false true @@ -12,12 +12,6 @@ - - - - - - @@ -49,39 +43,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -113,9 +77,6 @@ - - - @@ -140,15 +101,6 @@ - - - - - - - - - @@ -170,12 +122,6 @@ - - - - - - @@ -230,9 +176,6 @@ - - - @@ -269,10 +212,7 @@ - - - - + diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Resources/Zoom.cur b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Resources/Zoom.cur deleted file mode 100644 index f5001727..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Resources/Zoom.cur and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Resources/ZoomRelative.cur b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Resources/ZoomRelative.cur deleted file mode 100644 index 7df27fd6..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Resources/ZoomRelative.cur and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Themes/Aero2.NormalColor.xaml b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Themes/Aero2.NormalColor.xaml deleted file mode 100644 index 3df93a00..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Themes/Aero2.NormalColor.xaml +++ /dev/null @@ -1,833 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Themes/Generic.xaml b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Themes/Generic.xaml deleted file mode 100644 index 08a2092a..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Themes/Generic.xaml +++ /dev/null @@ -1,833 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Zoombox.Icon.bmp b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Zoombox.Icon.bmp deleted file mode 100644 index 76f9520f..00000000 Binary files a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Zoombox.Icon.bmp and /dev/null differ diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Zoombox.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Zoombox.cs deleted file mode 100644 index 75c9dc16..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/Zoombox.cs +++ /dev/null @@ -1,4058 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections; -using System.Collections.Specialized; -using System.ComponentModel; -using System.Globalization; -using System.Security; -using System.Security.Permissions; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Controls.Primitives; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Animation; -using Xceed.Wpf.Toolkit.Core.Input; -using Xceed.Wpf.Toolkit.Core; -using Xceed.Wpf.Toolkit.Core.Utilities; - -namespace Xceed.Wpf.Toolkit.Zoombox -{ - [TemplatePart( Name = PART_VerticalScrollBar, Type = typeof( ScrollBar ) )] - [TemplatePart( Name = PART_HorizontalScrollBar, Type = typeof( ScrollBar ) )] - public sealed class Zoombox : ContentControl - { - private const string PART_VerticalScrollBar = "PART_VerticalScrollBar"; - private const string PART_HorizontalScrollBar = "PART_HorizontalScrollBar"; - private bool _isUpdatingVisualTree = false; - - #region Constructors - - static Zoombox() - { - Zoombox.DefaultStyleKeyProperty.OverrideMetadata( typeof( Zoombox ), new FrameworkPropertyMetadata( typeof( Zoombox ) ) ); - Zoombox.ClipToBoundsProperty.OverrideMetadata( typeof( Zoombox ), new FrameworkPropertyMetadata( true ) ); - Zoombox.FocusableProperty.OverrideMetadata( typeof( Zoombox ), new FrameworkPropertyMetadata( true ) ); - Zoombox.HorizontalContentAlignmentProperty.OverrideMetadata( typeof( Zoombox ), new FrameworkPropertyMetadata( HorizontalAlignment.Center, new PropertyChangedCallback( Zoombox.RefocusView ) ) ); - Zoombox.VerticalContentAlignmentProperty.OverrideMetadata( typeof( Zoombox ), new FrameworkPropertyMetadata( VerticalAlignment.Center, new PropertyChangedCallback( Zoombox.RefocusView ) ) ); - Zoombox.ContentProperty.OverrideMetadata( typeof( Zoombox ), new FrameworkPropertyMetadata( ( PropertyChangedCallback )null, new CoerceValueCallback( Zoombox.CoerceContentValue ) ) ); - } - - public Zoombox() - : base() - { - try - { - new UIPermission( PermissionState.Unrestricted ).Demand(); - _cacheBits[ ( int )CacheBits.HasUIPermission ] = true; - } - catch( SecurityException ) - { - } - - this.InitCommands(); - - // use the LayoutUpdated event to keep the Viewport in sync - this.LayoutUpdated += new EventHandler( this.OnLayoutUpdated ); - this.AddHandler( FrameworkElement.SizeChangedEvent, new SizeChangedEventHandler( this.OnSizeChanged ), true ); - - this.CoerceValue( Zoombox.ViewStackModeProperty ); - - this.Loaded += this.Zoombox_Loaded; - } - - #endregion - - #region AnimationAccelerationRatio Property - - public static readonly DependencyProperty AnimationAccelerationRatioProperty = - DependencyProperty.Register( "AnimationAccelerationRatio", typeof( double ), typeof( Zoombox ), - new FrameworkPropertyMetadata( 0d ), - new ValidateValueCallback( Zoombox.ValidateAccelerationRatio ) ); - - public double AnimationAccelerationRatio - { - get - { - return ( double )this.GetValue( Zoombox.AnimationAccelerationRatioProperty ); - } - set - { - this.SetValue( Zoombox.AnimationAccelerationRatioProperty, value ); - } - } - - private static bool ValidateAccelerationRatio( object value ) - { - double newValue = ( double )value; - if( newValue < 0 || newValue > 1 || DoubleHelper.IsNaN( newValue ) ) - throw new ArgumentException( ErrorMessages.GetMessage( "AnimationAccelerationRatioOOR" ) ); - - return true; - } - - #endregion - - #region AnimationDecelerationRatio Property - - public static readonly DependencyProperty AnimationDecelerationRatioProperty = - DependencyProperty.Register( "AnimationDecelerationRatio", typeof( double ), typeof( Zoombox ), - new FrameworkPropertyMetadata( 0d ), - new ValidateValueCallback( Zoombox.ValidateDecelerationRatio ) ); - - public double AnimationDecelerationRatio - { - get - { - return ( double )this.GetValue( Zoombox.AnimationDecelerationRatioProperty ); - } - set - { - this.SetValue( Zoombox.AnimationDecelerationRatioProperty, value ); - } - } - - private static bool ValidateDecelerationRatio( object value ) - { - double newValue = ( double )value; - if( newValue < 0 || newValue > 1 || DoubleHelper.IsNaN( newValue ) ) - throw new ArgumentException( ErrorMessages.GetMessage( "AnimationDecelerationRatioOOR" ) ); - - return true; - } - - #endregion - - #region AnimationDuration Property - - public static readonly DependencyProperty AnimationDurationProperty = - DependencyProperty.Register( "AnimationDuration", typeof( Duration ), typeof( Zoombox ), - new FrameworkPropertyMetadata( new Duration( TimeSpan.FromMilliseconds( 300 ) ) ) ); - - public Duration AnimationDuration - { - get - { - return ( Duration )this.GetValue( Zoombox.AnimationDurationProperty ); - } - set - { - this.SetValue( Zoombox.AnimationDurationProperty, value ); - } - } - - #endregion - - #region AreDragModifiersActive Property - - private static readonly DependencyPropertyKey AreDragModifiersActivePropertyKey = - DependencyProperty.RegisterReadOnly( "AreDragModifiersActive", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( false ) ); - - public static readonly DependencyProperty AreDragModifiersActiveProperty = Zoombox.AreDragModifiersActivePropertyKey.DependencyProperty; - - public bool AreDragModifiersActive - { - get - { - return ( bool )this.GetValue( Zoombox.AreDragModifiersActiveProperty ); - } - } - - private void SetAreDragModifiersActive( bool value ) - { - this.SetValue( Zoombox.AreDragModifiersActivePropertyKey, value ); - } - - #endregion - - #region AreRelativeZoomModifiersActive Property - - private static readonly DependencyPropertyKey AreRelativeZoomModifiersActivePropertyKey = - DependencyProperty.RegisterReadOnly( "AreRelativeZoomModifiersActive", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( false ) ); - - public static readonly DependencyProperty AreRelativeZoomModifiersActiveProperty = Zoombox.AreRelativeZoomModifiersActivePropertyKey.DependencyProperty; - - public bool AreRelativeZoomModifiersActive - { - get - { - return ( bool )this.GetValue( Zoombox.AreRelativeZoomModifiersActiveProperty ); - } - } - - private void SetAreRelativeZoomModifiersActive( bool value ) - { - this.SetValue( Zoombox.AreRelativeZoomModifiersActivePropertyKey, value ); - } - - #endregion - - #region AreZoomModifiersActive Property - - private static readonly DependencyPropertyKey AreZoomModifiersActivePropertyKey = - DependencyProperty.RegisterReadOnly( "AreZoomModifiersActive", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( false ) ); - - public static readonly DependencyProperty AreZoomModifiersActiveProperty = Zoombox.AreZoomModifiersActivePropertyKey.DependencyProperty; - - public bool AreZoomModifiersActive - { - get - { - return ( bool )this.GetValue( Zoombox.AreZoomModifiersActiveProperty ); - } - } - - private void SetAreZoomModifiersActive( bool value ) - { - this.SetValue( Zoombox.AreZoomModifiersActivePropertyKey, value ); - } - - #endregion - - #region AreZoomToSelectionModifiersActive Property - - private static readonly DependencyPropertyKey AreZoomToSelectionModifiersActivePropertyKey = - DependencyProperty.RegisterReadOnly( "AreZoomToSelectionModifiersActive", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( false ) ); - - public static readonly DependencyProperty AreZoomToSelectionModifiersActiveProperty = Zoombox.AreZoomToSelectionModifiersActivePropertyKey.DependencyProperty; - - public bool AreZoomToSelectionModifiersActive - { - get - { - return ( bool )this.GetValue( Zoombox.AreZoomToSelectionModifiersActiveProperty ); - } - } - - private void SetAreZoomToSelectionModifiersActive( bool value ) - { - this.SetValue( Zoombox.AreZoomToSelectionModifiersActivePropertyKey, value ); - } - - #endregion - - #region AutoWrapContentWithViewbox Property - - public static readonly DependencyProperty AutoWrapContentWithViewboxProperty = - DependencyProperty.Register( "AutoWrapContentWithViewbox", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( true, - new PropertyChangedCallback( Zoombox.OnAutoWrapContentWithViewboxChanged ) ) ); - - public bool AutoWrapContentWithViewbox - { - get - { - return ( bool )this.GetValue( Zoombox.AutoWrapContentWithViewboxProperty ); - } - set - { - this.SetValue( Zoombox.AutoWrapContentWithViewboxProperty, value ); - } - } - - private static void OnAutoWrapContentWithViewboxChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - o.CoerceValue( Zoombox.ContentProperty ); - } - - private static object CoerceContentValue( DependencyObject d, object value ) - { - return ( ( Zoombox )d ).CoerceContentValue( value ); - } - - private object CoerceContentValue( object value ) - { - if( value != null && !( value is UIElement ) && !( ( bool )this.GetValue( DesignerProperties.IsInDesignModeProperty ) ) ) - throw new InvalidContentException( ErrorMessages.GetMessage( "ZoomboxContentMustBeUIElement" ) ); - - object oldContent = _content; - if( value != _trueContent || ( this.IsContentWrapped != this.AutoWrapContentWithViewbox ) ) - { - // check whether the content is currently wrapped and needs to be unwrapped - if( this.IsContentWrapped && _content is Viewbox && _content != _trueContent ) - { - Viewbox viewbox = ( Viewbox )_content; - - BindingOperations.ClearAllBindings( viewbox ); - if( viewbox.Child is FrameworkElement ) - { - ( viewbox.Child as FrameworkElement ).RemoveHandler( FrameworkElement.SizeChangedEvent, new SizeChangedEventHandler( this.OnContentSizeChanged ) ); - } - ( viewbox as Viewbox ).Child = null; - - this.RemoveLogicalChild( viewbox ); - } - - // make sure the view finder's visual brush is null - if( _viewFinderDisplay != null && _viewFinderDisplay.VisualBrush != null ) - { - _viewFinderDisplay.VisualBrush.Visual = null; - _viewFinderDisplay.VisualBrush = null; - } - - // update the cached content and true content values - _content = value as UIElement; - _trueContent = value as UIElement; - - // if necessary, unparent the existing content - if( _contentPresenter != null && _contentPresenter.Content != null ) - { - _contentPresenter.Content = null; - } - - // if necessary, wrap the content - this.IsContentWrapped = false; - if( this.AutoWrapContentWithViewbox ) - { - // create a viewbox and make it the logical child of the Zoombox - Viewbox viewbox = new Viewbox(); - this.AddLogicalChild( viewbox ); - - // now set the new parent to be the viewbox - viewbox.Child = value as UIElement; - _content = viewbox; - viewbox.HorizontalAlignment = HorizontalAlignment.Left; - viewbox.VerticalAlignment = VerticalAlignment.Top; - this.IsContentWrapped = true; - } - - if( ( _content is Viewbox ) && ( this.IsContentWrapped ) && ( _trueContent is FrameworkElement ) ) - { - ( _trueContent as FrameworkElement ).AddHandler( FrameworkElement.SizeChangedEvent, new SizeChangedEventHandler( this.OnContentSizeChanged ), true ); - } - - if( _contentPresenter != null ) - { - _contentPresenter.Content = _content; - } - - if( _viewFinderDisplay != null ) - { - this.CreateVisualBrushForViewFinder( _content ); - } - this.UpdateViewFinderDisplayContentBounds(); - } - - // if the content changes, we need to reset the flags used to first render and arrange the content - if( oldContent != _content - && this.HasArrangedContentPresenter - && this.HasRenderedFirstView ) - { - this.HasArrangedContentPresenter = false; - this.HasRenderedFirstView = false; - this.RefocusViewOnFirstRender = true; - _contentPresenter.LayoutUpdated += new EventHandler( this.ContentPresenterFirstArranged ); - } - return _content; - } - - private UIElement _trueContent; //null - - #endregion - - #region CurrentView Property - - private static readonly DependencyPropertyKey CurrentViewPropertyKey = - DependencyProperty.RegisterReadOnly( "CurrentView", typeof( ZoomboxView ), typeof( Zoombox ), - new FrameworkPropertyMetadata( ZoomboxView.Empty, - new PropertyChangedCallback( Zoombox.OnCurrentViewChanged ) ) ); - - public static readonly DependencyProperty CurrentViewProperty = Zoombox.CurrentViewPropertyKey.DependencyProperty; - - public ZoomboxView CurrentView - { - get - { - return ( ZoomboxView )this.GetValue( Zoombox.CurrentViewProperty ); - } - } - - private void SetCurrentView( ZoomboxView value ) - { - this.SetValue( Zoombox.CurrentViewPropertyKey, value ); - } - - private static void OnCurrentViewChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - Zoombox zoombox = ( Zoombox )o; - if( !zoombox.IsUpdatingView ) - { - zoombox.ZoomTo( zoombox.CurrentView ); - } - zoombox.RaiseEvent( new ZoomboxViewChangedEventArgs( e.OldValue as ZoomboxView, e.NewValue as ZoomboxView, zoombox._lastViewIndex, zoombox.CurrentViewIndex ) ); - } - - #endregion - - #region CurrentViewIndex Property - - private static readonly DependencyPropertyKey CurrentViewIndexPropertyKey = - DependencyProperty.RegisterReadOnly( "CurrentViewIndex", typeof( int ), typeof( Zoombox ), - new FrameworkPropertyMetadata( -1 ) ); - - public static readonly DependencyProperty CurrentViewIndexProperty = Zoombox.CurrentViewIndexPropertyKey.DependencyProperty; - - public int CurrentViewIndex - { - get - { - return ( int )this.GetValue( Zoombox.CurrentViewIndexProperty ); - } - } - - internal void SetCurrentViewIndex( int value ) - { - this.SetValue( Zoombox.CurrentViewIndexPropertyKey, value ); - } - - #endregion - - #region DragModifiers Property - - public static readonly DependencyProperty DragModifiersProperty = - DependencyProperty.Register( "DragModifiers", typeof( KeyModifierCollection ), typeof( Zoombox ), - new FrameworkPropertyMetadata( Zoombox.GetDefaultDragModifiers() ) ); - - [TypeConverter( typeof( KeyModifierCollectionConverter ) )] - public KeyModifierCollection DragModifiers - { - get - { - return ( KeyModifierCollection )this.GetValue( Zoombox.DragModifiersProperty ); - } - set - { - this.SetValue( Zoombox.DragModifiersProperty, value ); - } - } - - private static KeyModifierCollection GetDefaultDragModifiers() - { - KeyModifierCollection result = new KeyModifierCollection(); - result.Add( KeyModifier.Ctrl ); - result.Add( KeyModifier.Exact ); - return result; - } - - #endregion - - #region DragOnPreview Property - - public static readonly DependencyProperty DragOnPreviewProperty = - DependencyProperty.Register( "DragOnPreview", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( false ) ); - - public bool DragOnPreview - { - get - { - return ( bool )this.GetValue( Zoombox.DragOnPreviewProperty ); - } - set - { - this.SetValue( Zoombox.DragOnPreviewProperty, value ); - } - } - - #endregion - - #region EffectiveViewStackMode Property - - private static readonly DependencyPropertyKey EffectiveViewStackModePropertyKey = - DependencyProperty.RegisterReadOnly( "EffectiveViewStackMode", typeof( ZoomboxViewStackMode ), typeof( Zoombox ), - new FrameworkPropertyMetadata( ZoomboxViewStackMode.Auto ) ); - - public static readonly DependencyProperty EffectiveViewStackModeProperty = Zoombox.EffectiveViewStackModePropertyKey.DependencyProperty; - - public ZoomboxViewStackMode EffectiveViewStackMode - { - get - { - return ( ZoomboxViewStackMode )this.GetValue( Zoombox.EffectiveViewStackModeProperty ); - } - } - - private void SetEffectiveViewStackMode( ZoomboxViewStackMode value ) - { - this.SetValue( Zoombox.EffectiveViewStackModePropertyKey, value ); - } - - #endregion - - #region HasBackStack Property - - private static readonly DependencyPropertyKey HasBackStackPropertyKey = - DependencyProperty.RegisterReadOnly( "HasBackStack", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( false ) ); - - public static readonly DependencyProperty HasBackStackProperty = Zoombox.HasBackStackPropertyKey.DependencyProperty; - - public bool HasBackStack - { - get - { - return ( bool )this.GetValue( Zoombox.HasBackStackProperty ); - } - } - - #endregion - - #region HasForwardStack Property - - private static readonly DependencyPropertyKey HasForwardStackPropertyKey = - DependencyProperty.RegisterReadOnly( "HasForwardStack", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( false ) ); - - public static readonly DependencyProperty HasForwardStackProperty = Zoombox.HasForwardStackPropertyKey.DependencyProperty; - - public bool HasForwardStack - { - get - { - return ( bool )this.GetValue( Zoombox.HasForwardStackProperty ); - } - } - - #endregion - - #region IsAnimated Property - - public static readonly DependencyProperty IsAnimatedProperty = - DependencyProperty.Register( "IsAnimated", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( true, - ( PropertyChangedCallback )null, new CoerceValueCallback( Zoombox.CoerceIsAnimatedValue ) ) ); - - public bool IsAnimated - { - get - { - return ( bool )this.GetValue( Zoombox.IsAnimatedProperty ); - } - set - { - this.SetValue( Zoombox.IsAnimatedProperty, value ); - } - } - - private static object CoerceIsAnimatedValue( DependencyObject d, object value ) - { - Zoombox zoombox = ( Zoombox )d; - bool result = ( bool )value; - if( !zoombox.IsInitialized ) - { - result = false; - } - return result; - } - - #endregion - - #region IsDraggingContent Property - - private static readonly DependencyPropertyKey IsDraggingContentPropertyKey = - DependencyProperty.RegisterReadOnly( "IsDraggingContent", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( false ) ); - - public static readonly DependencyProperty IsDraggingContentProperty = Zoombox.IsDraggingContentPropertyKey.DependencyProperty; - - public bool IsDraggingContent - { - get - { - return ( bool )this.GetValue( Zoombox.IsDraggingContentProperty ); - } - } - - private void SetIsDraggingContent( bool value ) - { - this.SetValue( Zoombox.IsDraggingContentPropertyKey, value ); - } - - #endregion - - #region IsSelectingRegion Property - - private static readonly DependencyPropertyKey IsSelectingRegionPropertyKey = - DependencyProperty.RegisterReadOnly( "IsSelectingRegion", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( false ) ); - - public static readonly DependencyProperty IsSelectingRegionProperty = Zoombox.IsSelectingRegionPropertyKey.DependencyProperty; - - public bool IsSelectingRegion - { - get - { - return ( bool )this.GetValue( Zoombox.IsSelectingRegionProperty ); - } - } - - private void SetIsSelectingRegion( bool value ) - { - this.SetValue( Zoombox.IsSelectingRegionPropertyKey, value ); - } - - #endregion - - #region IsUsingScrollBars Property - - public static readonly DependencyProperty IsUsingScrollBarsProperty = - DependencyProperty.Register( "IsUsingScrollBars", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( false, ( PropertyChangedCallback )null ) ); - - public bool IsUsingScrollBars - { - get - { - return ( bool )this.GetValue( Zoombox.IsUsingScrollBarsProperty ); - } - set - { - this.SetValue( Zoombox.IsUsingScrollBarsProperty, value ); - } - } - - #endregion - - #region MaxScale Property - - public static readonly DependencyProperty MaxScaleProperty = - DependencyProperty.Register( "MaxScale", typeof( double ), typeof( Zoombox ), - new FrameworkPropertyMetadata( 100d, FrameworkPropertyMetadataOptions.AffectsMeasure, - new PropertyChangedCallback( Zoombox.OnMaxScaleChanged ), new CoerceValueCallback( Zoombox.CoerceMaxScaleValue ) ) ); - - public double MaxScale - { - get - { - return ( double )this.GetValue( Zoombox.MaxScaleProperty ); - } - set - { - this.SetValue( Zoombox.MaxScaleProperty, value ); - } - } - - private static void OnMaxScaleChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - Zoombox zoombox = ( Zoombox )o; - zoombox.CoerceValue( Zoombox.MinScaleProperty ); - zoombox.CoerceValue( Zoombox.ScaleProperty ); - } - - private static object CoerceMaxScaleValue( DependencyObject d, object value ) - { - Zoombox zoombox = ( Zoombox )d; - double result = ( double )value; - if( result < zoombox.MinScale ) - { - result = zoombox.MinScale; - } - return result; - } - - #endregion - - #region MinScale Property - - public static readonly DependencyProperty MinScaleProperty = - DependencyProperty.Register( "MinScale", typeof( double ), typeof( Zoombox ), - new FrameworkPropertyMetadata( 0.01d, FrameworkPropertyMetadataOptions.AffectsMeasure, - new PropertyChangedCallback( Zoombox.OnMinScaleChanged ), new CoerceValueCallback( Zoombox.CoerceMinScaleValue ) ) ); - - public double MinScale - { - get - { - return ( double )this.GetValue( Zoombox.MinScaleProperty ); - } - set - { - this.SetValue( Zoombox.MinScaleProperty, value ); - } - } - - private static void OnMinScaleChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - Zoombox zoombox = ( Zoombox )o; - zoombox.CoerceValue( Zoombox.MinScaleProperty ); - zoombox.CoerceValue( Zoombox.ScaleProperty ); - } - - private static object CoerceMinScaleValue( DependencyObject d, object value ) - { - Zoombox zoombox = ( Zoombox )d; - double result = ( double )value; - if( result > zoombox.MaxScale ) - { - result = zoombox.MaxScale; - } - return result; - } - - #endregion - - #region NavigateOnPreview Property - - public static readonly DependencyProperty NavigateOnPreviewProperty = - DependencyProperty.Register( "NavigateOnPreview", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( false ) ); - - public bool NavigateOnPreview - { - get - { - return ( bool )this.GetValue( Zoombox.NavigateOnPreviewProperty ); - } - set - { - this.SetValue( Zoombox.NavigateOnPreviewProperty, value ); - } - } - - #endregion - - #region PanDistance Property - - public static readonly DependencyProperty PanDistanceProperty = - DependencyProperty.Register( "PanDistance", typeof( double ), typeof( Zoombox ), - new FrameworkPropertyMetadata( 5d ) ); - - public double PanDistance - { - get - { - return ( double )this.GetValue( Zoombox.PanDistanceProperty ); - } - set - { - this.SetValue( Zoombox.PanDistanceProperty, value ); - } - } - - #endregion - - #region Position Property - - public static readonly DependencyProperty PositionProperty = - DependencyProperty.Register( "Position", typeof( Point ), typeof( Zoombox ), - new FrameworkPropertyMetadata( PointHelper.Empty, new PropertyChangedCallback( Zoombox.OnPositionChanged ) ) ); - - public Point Position - { - get - { - return ( Point )this.GetValue( Zoombox.PositionProperty ); - } - set - { - this.SetValue( Zoombox.PositionProperty, value ); - } - } - - private static void OnPositionChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - Zoombox zoombox = ( Zoombox )o; - if( !zoombox.IsUpdatingViewport ) - { - Point newPosition = ( Point )e.NewValue; - double scale = zoombox.Scale; - if( scale > 0 ) - { - zoombox.ZoomTo( new Point( -newPosition.X, -newPosition.Y ) ); - } - } - } - - #endregion - - #region RelativeZoomModifiers Property - - public static readonly DependencyProperty RelativeZoomModifiersProperty = - DependencyProperty.Register( "RelativeZoomModifiers", typeof( KeyModifierCollection ), typeof( Zoombox ), - new FrameworkPropertyMetadata( Zoombox.GetDefaultRelativeZoomModifiers() ) ); - - [TypeConverter( typeof( KeyModifierCollectionConverter ) )] - public KeyModifierCollection RelativeZoomModifiers - { - get - { - return ( KeyModifierCollection )this.GetValue( Zoombox.RelativeZoomModifiersProperty ); - } - set - { - this.SetValue( Zoombox.RelativeZoomModifiersProperty, value ); - } - } - - private static KeyModifierCollection GetDefaultRelativeZoomModifiers() - { - KeyModifierCollection result = new KeyModifierCollection(); - result.Add( KeyModifier.Ctrl ); - result.Add( KeyModifier.Alt ); - result.Add( KeyModifier.Exact ); - return result; - } - - #endregion - - #region Scale Property - - public static readonly DependencyProperty ScaleProperty = - DependencyProperty.Register( "Scale", typeof( double ), typeof( Zoombox ), - new FrameworkPropertyMetadata( double.NaN, - new PropertyChangedCallback( Zoombox.OnScaleChanged ), new CoerceValueCallback( Zoombox.CoerceScaleValue ) ) ); - - public double Scale - { - get - { - return ( double )this.GetValue( Zoombox.ScaleProperty ); - } - set - { - this.SetValue( Zoombox.ScaleProperty, value ); - } - } - - private static void OnScaleChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - Zoombox zoombox = ( Zoombox )o; - if( !zoombox.IsUpdatingView ) - { - double newScale = ( double )e.NewValue; - zoombox.ZoomTo( newScale ); - } - } - - private static object CoerceScaleValue( DependencyObject d, object value ) - { - Zoombox zoombox = ( Zoombox )d; - double result = ( double )value; - - if( result < zoombox.MinScale ) - { - result = zoombox.MinScale; - } - - if( result > zoombox.MaxScale ) - { - result = zoombox.MaxScale; - } - - return result; - } - - #endregion - - #region ViewFinder Property - - private static readonly DependencyPropertyKey ViewFinderPropertyKey = - DependencyProperty.RegisterReadOnly( "ViewFinder", typeof( FrameworkElement ), typeof( Zoombox ), - new FrameworkPropertyMetadata( null, new PropertyChangedCallback( Zoombox.OnViewFinderChanged ) ) ); - - public static readonly DependencyProperty ViewFinderProperty = Zoombox.ViewFinderPropertyKey.DependencyProperty; - - public FrameworkElement ViewFinder - { - get - { - return ( FrameworkElement )this.GetValue( Zoombox.ViewFinderProperty ); - } - set - { - this.SetValue( Zoombox.ViewFinderPropertyKey, value ); - } - } - - private static void OnViewFinderChanged( DependencyObject d, DependencyPropertyChangedEventArgs e ) - { - ( ( Zoombox )d ).OnViewFinderChanged( e ); - } - - private void OnViewFinderChanged( DependencyPropertyChangedEventArgs e ) - { - this.AttachToVisualTree(); - } - - #endregion - - #region ViewFinderVisibility Attached Property - - public static readonly DependencyProperty ViewFinderVisibilityProperty = - DependencyProperty.RegisterAttached( "ViewFinderVisibility", typeof( Visibility ), typeof( Zoombox ), - new FrameworkPropertyMetadata( Visibility.Visible ) ); - - public static Visibility GetViewFinderVisibility( DependencyObject d ) - { - return ( Visibility )( d.GetValue( Zoombox.ViewFinderVisibilityProperty ) ); - } - - public static void SetViewFinderVisibility( DependencyObject d, Visibility value ) - { - d.SetValue( Zoombox.ViewFinderVisibilityProperty, value ); - } - - #endregion - - #region Viewport Property - - private static readonly DependencyPropertyKey ViewportPropertyKey = - DependencyProperty.RegisterReadOnly( "Viewport", typeof( Rect ), typeof( Zoombox ), - new FrameworkPropertyMetadata( Rect.Empty, - new PropertyChangedCallback( Zoombox.OnViewportChanged ) ) ); - - public static readonly DependencyProperty ViewportProperty = Zoombox.ViewportPropertyKey.DependencyProperty; - - public Rect Viewport - { - get - { - return ( Rect )this.GetValue( Zoombox.ViewportProperty ); - } - } - - private static void OnViewportChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - // keep the Position property in sync with the Viewport - Zoombox zoombox = ( Zoombox )o; - zoombox.Position = new Point( -zoombox.Viewport.Left * zoombox.Scale / zoombox._viewboxFactor, -zoombox.Viewport.Top * zoombox.Scale / zoombox._viewboxFactor ); - } - - #endregion - - #region ViewStackCount Property - - private static readonly DependencyPropertyKey ViewStackCountPropertyKey = - DependencyProperty.RegisterReadOnly( "ViewStackCount", typeof( int ), typeof( Zoombox ), - new FrameworkPropertyMetadata( -1, - new PropertyChangedCallback( Zoombox.OnViewStackCountChanged ) ) ); - - public static readonly DependencyProperty ViewStackCountProperty = Zoombox.ViewStackCountPropertyKey.DependencyProperty; - - public int ViewStackCount - { - get - { - return ( int )this.GetValue( Zoombox.ViewStackCountProperty ); - } - } - - internal void SetViewStackCount( int value ) - { - this.SetValue( Zoombox.ViewStackCountPropertyKey, value ); - } - - private static void OnViewStackCountChanged( DependencyObject d, DependencyPropertyChangedEventArgs e ) - { - ( ( Zoombox )d ).OnViewStackCountChanged( e ); - } - - private void OnViewStackCountChanged( DependencyPropertyChangedEventArgs e ) - { - if( this.EffectiveViewStackMode == ZoomboxViewStackMode.Disabled ) - return; - - this.UpdateStackProperties(); - } - - #endregion - - #region ViewStackIndex Property - - public static readonly DependencyProperty ViewStackIndexProperty = - DependencyProperty.Register( "ViewStackIndex", typeof( int ), typeof( Zoombox ), - new FrameworkPropertyMetadata( -1, - new PropertyChangedCallback( Zoombox.OnViewStackIndexChanged ), new CoerceValueCallback( Zoombox.CoerceViewStackIndexValue ) ) ); - - public int ViewStackIndex - { - get - { - return ( int )this.GetValue( Zoombox.ViewStackIndexProperty ); - } - set - { - this.SetValue( Zoombox.ViewStackIndexProperty, value ); - } - } - - private static void OnViewStackIndexChanged( DependencyObject d, DependencyPropertyChangedEventArgs e ) - { - ( ( Zoombox )d ).OnViewStackIndexChanged( e ); - } - - private void OnViewStackIndexChanged( DependencyPropertyChangedEventArgs e ) - { - if( this.EffectiveViewStackMode == ZoomboxViewStackMode.Disabled ) - return; - - if( !this.IsUpdatingView ) - { - int viewIndex = this.ViewStackIndex; - if( viewIndex >= 0 && viewIndex < ViewStack.Count ) - { - // update the current view, but don't allow the new view - // to be added to the view stack - this.UpdateView( this.ViewStack[ viewIndex ], true, false, viewIndex ); - } - } - - this.UpdateStackProperties(); - this.RaiseEvent( new IndexChangedEventArgs( Zoombox.ViewStackIndexChangedEvent, ( int )e.OldValue, ( int )e.NewValue ) ); - } - - private static object CoerceViewStackIndexValue( DependencyObject d, object value ) - { - Zoombox zoombox = d as Zoombox; - return ( zoombox.EffectiveViewStackMode == ZoomboxViewStackMode.Disabled ) ? -1 : value; - } - - #endregion - - #region ViewStackMode Property - - public static readonly DependencyProperty ViewStackModeProperty = - DependencyProperty.Register( "ViewStackMode", typeof( ZoomboxViewStackMode ), typeof( Zoombox ), - new FrameworkPropertyMetadata( ZoomboxViewStackMode.Default, - new PropertyChangedCallback( Zoombox.OnViewStackModeChanged ), new CoerceValueCallback( Zoombox.CoerceViewStackModeValue ) ) ); - - public ZoomboxViewStackMode ViewStackMode - { - get - { - return ( ZoomboxViewStackMode )this.GetValue( Zoombox.ViewStackModeProperty ); - } - set - { - this.SetValue( Zoombox.ViewStackModeProperty, value ); - } - } - - private static void OnViewStackModeChanged( DependencyObject d, DependencyPropertyChangedEventArgs e ) - { - ( ( Zoombox )d ).OnViewStackModeChanged( e ); - } - - private void OnViewStackModeChanged( DependencyPropertyChangedEventArgs e ) - { - if( ( ZoomboxViewStackMode )e.NewValue == ZoomboxViewStackMode.Disabled && _viewStack != null ) - { - _viewStack.ClearViewStackSource(); - _viewStack = null; - } - } - - private static object CoerceViewStackModeValue( DependencyObject d, object value ) - { - Zoombox zoombox = d as Zoombox; - ZoomboxViewStackMode effectiveMode = ( ZoomboxViewStackMode )value; - - // if the effective mode is currently disabled, it must be updated first - if( zoombox.EffectiveViewStackMode == ZoomboxViewStackMode.Disabled ) - { - zoombox.SetEffectiveViewStackMode( effectiveMode ); - } - - // now determine the correct effective mode - if( effectiveMode != ZoomboxViewStackMode.Disabled ) - { - if( effectiveMode == ZoomboxViewStackMode.Default ) - { - effectiveMode = ( zoombox.ViewStack.AreViewsFromSource ? ZoomboxViewStackMode.Manual : ZoomboxViewStackMode.Auto ); - } - if( zoombox.ViewStack.AreViewsFromSource && ( ZoomboxViewStackMode )effectiveMode != ZoomboxViewStackMode.Manual ) - { - throw new InvalidOperationException( ErrorMessages.GetMessage( "ViewModeInvalidForSource" ) ); - } - } - - // update the effective mode - zoombox.SetEffectiveViewStackMode( effectiveMode ); - return value; - } - - #endregion - - #region ViewStackSource Property - - public static readonly DependencyProperty ViewStackSourceProperty = - DependencyProperty.Register( "ViewStackSource", typeof( IEnumerable ), typeof( Zoombox ), - new FrameworkPropertyMetadata( ( IEnumerable )null, - new PropertyChangedCallback( Zoombox.OnViewStackSourceChanged ) ) ); - - [Bindable( true )] - public IEnumerable ViewStackSource - { - get - { - return ( _viewStack == null ) ? null : ViewStack.Source; - } - set - { - if( value == null ) - { - this.ClearValue( Zoombox.ViewStackSourceProperty ); - } - else - { - this.SetValue( Zoombox.ViewStackSourceProperty, value ); - } - } - } - - private static void OnViewStackSourceChanged( DependencyObject d, DependencyPropertyChangedEventArgs e ) - { - Zoombox zoombox = ( Zoombox )d; - IEnumerable oldValue = ( IEnumerable )e.OldValue; - IEnumerable newValue = ( IEnumerable )e.NewValue; - - // We need to know whether the new value represents an explicit null value - // or whether it came from a binding. The latter indicates that we stay in ViewStackSource mode, - // but with a null collection. - if( e.NewValue == null && !BindingOperations.IsDataBound( d, Zoombox.ViewStackSourceProperty ) ) - { - if( zoombox.ViewStack != null ) - { - zoombox.ViewStack.ClearViewStackSource(); - } - } - else - { - zoombox.ViewStack.SetViewStackSource( newValue ); - } - - zoombox.CoerceValue( Zoombox.ViewStackModeProperty ); - } - - #endregion - - #region ZoomModifiers Property - - public static readonly DependencyProperty ZoomModifiersProperty = - DependencyProperty.Register( "ZoomModifiers", typeof( KeyModifierCollection ), typeof( Zoombox ), - new FrameworkPropertyMetadata( Zoombox.GetDefaultZoomModifiers() ) ); - - [TypeConverter( typeof( KeyModifierCollectionConverter ) )] - public KeyModifierCollection ZoomModifiers - { - get - { - return ( KeyModifierCollection )this.GetValue( Zoombox.ZoomModifiersProperty ); - } - set - { - this.SetValue( Zoombox.ZoomModifiersProperty, value ); - } - } - - private static KeyModifierCollection GetDefaultZoomModifiers() - { - KeyModifierCollection result = new KeyModifierCollection(); - result.Add( KeyModifier.Shift ); - result.Add( KeyModifier.Exact ); - return result; - } - - #endregion - - #region ZoomOnPreview Property - - public static readonly DependencyProperty ZoomOnPreviewProperty = - DependencyProperty.Register( "ZoomOnPreview", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( true ) ); - - public bool ZoomOnPreview - { - get - { - return ( bool )this.GetValue( Zoombox.ZoomOnPreviewProperty ); - } - set - { - this.SetValue( Zoombox.ZoomOnPreviewProperty, value ); - } - } - - #endregion - - #region ZoomOrigin Property - - public static readonly DependencyProperty ZoomOriginProperty = - DependencyProperty.Register( "ZoomOrigin", typeof( Point ), typeof( Zoombox ), - new FrameworkPropertyMetadata( new Point( 0.5d, 0.5d ) ) ); - - public Point ZoomOrigin - { - get - { - return ( Point )this.GetValue( Zoombox.ZoomOriginProperty ); - } - set - { - this.SetValue( Zoombox.ZoomOriginProperty, value ); - } - } - - #endregion - - #region ZoomPercentage Property - - public static readonly DependencyProperty ZoomPercentageProperty = - DependencyProperty.Register( "ZoomPercentage", typeof( double ), typeof( Zoombox ), - new FrameworkPropertyMetadata( 5d ) ); - - public double ZoomPercentage - { - get - { - return ( double )this.GetValue( Zoombox.ZoomPercentageProperty ); - } - set - { - this.SetValue( Zoombox.ZoomPercentageProperty, value ); - } - } - - #endregion - - #region ZoomOn Property - - public static readonly DependencyProperty ZoomOnProperty = - DependencyProperty.Register( "ZoomOn", typeof( ZoomboxZoomOn ), typeof( Zoombox ), - new FrameworkPropertyMetadata( ZoomboxZoomOn.Content ) ); - - public ZoomboxZoomOn ZoomOn - { - get - { - return ( ZoomboxZoomOn )this.GetValue( Zoombox.ZoomOnProperty ); - } - set - { - this.SetValue( Zoombox.ZoomOnProperty, value ); - } - } - - #endregion - - #region ZoomToSelectionModifiers Property - - public static readonly DependencyProperty ZoomToSelectionModifiersProperty = - DependencyProperty.Register( "ZoomToSelectionModifiers", typeof( KeyModifierCollection ), typeof( Zoombox ), - new FrameworkPropertyMetadata( Zoombox.GetDefaultZoomToSelectionModifiers() ) ); - - [TypeConverter( typeof( KeyModifierCollectionConverter ) )] - public KeyModifierCollection ZoomToSelectionModifiers - { - get - { - return ( KeyModifierCollection )this.GetValue( Zoombox.ZoomToSelectionModifiersProperty ); - } - set - { - this.SetValue( Zoombox.ZoomToSelectionModifiersProperty, value ); - } - } - - private static KeyModifierCollection GetDefaultZoomToSelectionModifiers() - { - KeyModifierCollection result = new KeyModifierCollection(); - result.Add( KeyModifier.Alt ); - result.Add( KeyModifier.Exact ); - return result; - } - - #endregion - - #region KeepContentInBounds Property - - public static readonly DependencyProperty KeepContentInBoundsProperty = - DependencyProperty.Register( "KeepContentInBounds", typeof( bool ), typeof( Zoombox ), - new FrameworkPropertyMetadata( false, - new PropertyChangedCallback( Zoombox.OnKeepContentInBoundsChanged ) ) ); - - public bool KeepContentInBounds - { - get - { - return ( bool )this.GetValue( Zoombox.KeepContentInBoundsProperty ); - } - set - { - this.SetValue( Zoombox.KeepContentInBoundsProperty, value ); - } - } - - private static void OnKeepContentInBoundsChanged( DependencyObject d, DependencyPropertyChangedEventArgs e ) - { - ( ( Zoombox )d ).OnKeepContentInBoundsChanged( e ); - } - - private void OnKeepContentInBoundsChanged( DependencyPropertyChangedEventArgs e ) - { - // - // Update view and see if we need to reposition the content - // - bool oldIsAnimated = this.IsAnimated; - this.IsAnimated = false; - try - { - this.UpdateView( this.CurrentView, false, false, this.ViewStackIndex ); - } - finally - { - this.IsAnimated = oldIsAnimated; - } - } - - #endregion - - #region ViewStack Property - - public ZoomboxViewStack ViewStack - { - get - { - if( _viewStack == null && this.EffectiveViewStackMode != ZoomboxViewStackMode.Disabled ) - { - _viewStack = new ZoomboxViewStack( this ); - } - return _viewStack; - } - } - - #endregion - - #region HasArrangedContentPresenter Internal Property - - internal bool HasArrangedContentPresenter - { - get - { - return _cacheBits[ ( int )CacheBits.HasArrangedContentPresenter ]; - } - set - { - _cacheBits[ ( int )CacheBits.HasArrangedContentPresenter ] = value; - } - } - - #endregion - - #region IsUpdatingView Internal Property - - internal bool IsUpdatingView - { - get - { - return _cacheBits[ ( int )CacheBits.IsUpdatingView ]; - } - set - { - _cacheBits[ ( int )CacheBits.IsUpdatingView ] = value; - } - } - - #endregion - - #region ContentOffset Private Property - - private Vector ContentOffset - { - get - { - // auto-wrapped content is always left and top aligned - if( this.IsContentWrapped || _content == null || !( _content is FrameworkElement ) ) - return new Vector( 0, 0 ); - - double x = 0; - double y = 0; - Size contentSize = this.ContentRect.Size; - - switch( ( _content as FrameworkElement ).HorizontalAlignment ) - { - case HorizontalAlignment.Center: - case HorizontalAlignment.Stretch: - x = ( this.RenderSize.Width - contentSize.Width ) / 2; - break; - - case HorizontalAlignment.Right: - x = this.RenderSize.Width - contentSize.Width; - break; - } - - switch( ( _content as FrameworkElement ).VerticalAlignment ) - { - case VerticalAlignment.Center: - case VerticalAlignment.Stretch: - y = ( this.RenderSize.Height - contentSize.Height ) / 2; - break; - - case VerticalAlignment.Bottom: - y = this.RenderSize.Height - contentSize.Height; - break; - } - - return new Vector( x, y ); - } - } - - #endregion - - #region ContentRect Private Property - - private Rect ContentRect - { - get - { - return ( _content == null ) ? Rect.Empty - : new Rect( new Size( _content.RenderSize.Width / _viewboxFactor, _content.RenderSize.Height / _viewboxFactor ) ); - } - } - - #endregion - - #region HasRenderedFirstView Private Property - - private bool HasRenderedFirstView - { - get - { - return _cacheBits[ ( int )CacheBits.HasRenderedFirstView ]; - } - set - { - _cacheBits[ ( int )CacheBits.HasRenderedFirstView ] = value; - } - } - - #endregion - - #region HasUIPermission Private Property - - private bool HasUIPermission - { - get - { - return _cacheBits[ ( int )CacheBits.HasUIPermission ]; - } - } - - #endregion - - #region IsContentWrapped Private Property - - private bool IsContentWrapped - { - get - { - return _cacheBits[ ( int )CacheBits.IsContentWrapped ]; - } - set - { - _cacheBits[ ( int )CacheBits.IsContentWrapped ] = value; - } - } - - #endregion - - #region IsDraggingViewport Private Property - - private bool IsDraggingViewport - { - get - { - return _cacheBits[ ( int )CacheBits.IsDraggingViewport ]; - } - set - { - _cacheBits[ ( int )CacheBits.IsDraggingViewport ] = value; - } - } - - #endregion - - #region IsMonitoringInput Private Property - - private bool IsMonitoringInput - { - get - { - return _cacheBits[ ( int )CacheBits.IsMonitoringInput ]; - } - set - { - _cacheBits[ ( int )CacheBits.IsMonitoringInput ] = value; - } - } - - #endregion - - #region IsResizingViewport Private Property - - private bool IsResizingViewport - { - get - { - return _cacheBits[ ( int )CacheBits.IsResizingViewport ]; - } - set - { - _cacheBits[ ( int )CacheBits.IsResizingViewport ] = value; - } - } - - #endregion - - #region IsUpdatingViewport Private Property - - private bool IsUpdatingViewport - { - get - { - return _cacheBits[ ( int )CacheBits.IsUpdatingViewport ]; - } - set - { - _cacheBits[ ( int )CacheBits.IsUpdatingViewport ] = value; - } - } - - #endregion - - #region RefocusViewOnFirstRender Private Property - - private bool RefocusViewOnFirstRender - { - get - { - return _cacheBits[ ( int )CacheBits.RefocusViewOnFirstRender ]; - } - set - { - _cacheBits[ ( int )CacheBits.RefocusViewOnFirstRender ] = value; - } - } - - #endregion - - #region ViewFinderDisplayRect Private Property - - private Rect ViewFinderDisplayRect - { - get - { - return ( _viewFinderDisplay == null ) ? Rect.Empty - : new Rect( new Point( 0, 0 ), new Point( _viewFinderDisplay.RenderSize.Width, _viewFinderDisplay.RenderSize.Height ) ); - } - } - - #endregion - - #region AnimationBeginning Event - - public static readonly RoutedEvent AnimationBeginningEvent = EventManager.RegisterRoutedEvent( "AnimationBeginning", RoutingStrategy.Bubble, typeof( RoutedEventHandler ), typeof( Zoombox ) ); - - public event RoutedEventHandler AnimationBeginning - { - add - { - this.AddHandler( Zoombox.AnimationBeginningEvent, value ); - } - remove - { - this.RemoveHandler( Zoombox.AnimationBeginningEvent, value ); - } - } - - #endregion - - #region AnimationCompleted Event - - public static readonly RoutedEvent AnimationCompletedEvent = EventManager.RegisterRoutedEvent( "AnimationCompleted", RoutingStrategy.Bubble, typeof( RoutedEventHandler ), typeof( Zoombox ) ); - - public event RoutedEventHandler AnimationCompleted - { - add - { - this.AddHandler( Zoombox.AnimationCompletedEvent, value ); - } - remove - { - this.RemoveHandler( Zoombox.AnimationCompletedEvent, value ); - } - } - - #endregion - - #region CurrentViewChanged Event - - public static readonly RoutedEvent CurrentViewChangedEvent = EventManager.RegisterRoutedEvent( "CurrentViewChanged", RoutingStrategy.Bubble, typeof( ZoomboxViewChangedEventHandler ), typeof( Zoombox ) ); - - public event ZoomboxViewChangedEventHandler CurrentViewChanged - { - add - { - this.AddHandler( Zoombox.CurrentViewChangedEvent, value ); - } - remove - { - this.RemoveHandler( Zoombox.CurrentViewChangedEvent, value ); - } - } - - #endregion - - public event EventHandler Scroll; - - #region ViewStackIndexChanged Event - - public static readonly RoutedEvent ViewStackIndexChangedEvent = EventManager.RegisterRoutedEvent( "ViewStackIndexChanged", RoutingStrategy.Bubble, typeof( IndexChangedEventHandler ), typeof( Zoombox ) ); - - public event IndexChangedEventHandler ViewStackIndexChanged - { - add - { - this.AddHandler( Zoombox.ViewStackIndexChangedEvent, value ); - } - remove - { - this.RemoveHandler( Zoombox.ViewStackIndexChangedEvent, value ); - } - } - - #endregion - - #region Back Command - - public static RoutedUICommand Back = new RoutedUICommand( "Go Back", "GoBack", typeof( Zoombox ) ); - - private void CanGoBack( object sender, CanExecuteRoutedEventArgs e ) - { - e.CanExecute = ( this.EffectiveViewStackMode != ZoomboxViewStackMode.Disabled ) - && ( this.ViewStackIndex > 0 ); - } - - private void GoBack( object sender, ExecutedRoutedEventArgs e ) - { - this.GoBack(); - } - - #endregion - - #region Center Command - - public static RoutedUICommand Center = new RoutedUICommand( "Center Content", "Center", typeof( Zoombox ) ); - - private void CenterContent( object sender, ExecutedRoutedEventArgs e ) - { - this.CenterContent(); - } - - #endregion - - #region Fill Command - - public static RoutedUICommand Fill = new RoutedUICommand( "Fill Bounds with Content", "FillToBounds", typeof( Zoombox ) ); - - private void FillToBounds( object sender, ExecutedRoutedEventArgs e ) - { - this.FillToBounds(); - } - - #endregion - - #region Fit Command - - public static RoutedUICommand Fit = new RoutedUICommand( "Fit Content within Bounds", "FitToBounds", typeof( Zoombox ) ); - - private void FitToBounds( object sender, ExecutedRoutedEventArgs e ) - { - this.FitToBounds(); - } - - #endregion - - #region Forward Command - - public static RoutedUICommand Forward = new RoutedUICommand( "Go Forward", "GoForward", typeof( Zoombox ) ); - - private void CanGoForward( object sender, CanExecuteRoutedEventArgs e ) - { - e.CanExecute = ( this.EffectiveViewStackMode != ZoomboxViewStackMode.Disabled ) - && ( this.ViewStackIndex < this.ViewStack.Count - 1 ); - } - - private void GoForward( object sender, ExecutedRoutedEventArgs e ) - { - this.GoForward(); - } - - #endregion - - #region Home Command - - public static RoutedUICommand Home = new RoutedUICommand( "Go Home", "GoHome", typeof( Zoombox ) ); - - private void CanGoHome( object sender, CanExecuteRoutedEventArgs e ) - { - e.CanExecute = ( this.EffectiveViewStackMode != ZoomboxViewStackMode.Disabled ) - && ( this.ViewStack.Count > 0 ) - && ( this.ViewStackIndex != 0 ); - } - - private void GoHome( object sender, ExecutedRoutedEventArgs e ) - { - this.GoHome(); - } - - #endregion - - #region PanDown Command - - public static RoutedUICommand PanDown = new RoutedUICommand( "Pan Down", "PanDown", typeof( Zoombox ) ); - - private void PanDownExecuted( object sender, ExecutedRoutedEventArgs e ) - { - this.Position = new Point( _basePosition.X, _basePosition.Y + PanDistance ); - } - - #endregion - - #region PanLeft Command - - public static RoutedUICommand PanLeft = new RoutedUICommand( "Pan Left", "PanLeft", typeof( Zoombox ) ); - - private void PanLeftExecuted( object sender, ExecutedRoutedEventArgs e ) - { - this.Position = new Point( _basePosition.X - this.PanDistance, _basePosition.Y ); - } - - #endregion - - #region PanRight Command - - public static RoutedUICommand PanRight = new RoutedUICommand( "Pan Right", "PanRight", typeof( Zoombox ) ); - - private void PanRightExecuted( object sender, ExecutedRoutedEventArgs e ) - { - this.Position = new Point( _basePosition.X + this.PanDistance, _basePosition.Y ); - } - - #endregion - - #region PanUp Command - - public static RoutedUICommand PanUp = new RoutedUICommand( "Pan Up", "PanUp", typeof( Zoombox ) ); - - private void PanUpExecuted( object sender, ExecutedRoutedEventArgs e ) - { - this.Position = new Point( _basePosition.X, _basePosition.Y - this.PanDistance ); - } - - #endregion - - #region Refocus Command - - public static RoutedUICommand Refocus = new RoutedUICommand( "Refocus View", "Refocus", typeof( Zoombox ) ); - - private void CanRefocusView( object sender, CanExecuteRoutedEventArgs e ) - { - e.CanExecute = ( this.EffectiveViewStackMode == ZoomboxViewStackMode.Manual ) - && ( this.ViewStackIndex >= 0 && this.ViewStackIndex < this.ViewStack.Count ) - && ( this.CurrentView != this.ViewStack[ this.ViewStackIndex ] ); - } - - private void RefocusView( object sender, ExecutedRoutedEventArgs e ) - { - this.RefocusView(); - } - - #endregion - - #region ZoomIn Command - - public static RoutedUICommand ZoomIn = new RoutedUICommand( "Zoom In", "ZoomIn", typeof( Zoombox ) ); - - private void ZoomInExecuted( object sender, ExecutedRoutedEventArgs e ) - { - this.Zoom( this.ZoomPercentage / 100 ); - } - - #endregion - - #region ZoomOut Command - - public static RoutedUICommand ZoomOut = new RoutedUICommand( "Zoom Out", "ZoomOut", typeof( Zoombox ) ); - - private void ZoomOutExecuted( object sender, ExecutedRoutedEventArgs e ) - { - this.Zoom( -this.ZoomPercentage / 100 ); - } - - #endregion - - public void CenterContent() - { - if( _content != null ) - { - this.SetScrollBars(); - this.ZoomTo( ZoomboxView.Center ); - } - } - - public void FillToBounds() - { - if( _content != null ) - { - this.SetScrollBars(); - this.ZoomTo( ZoomboxView.Fill ); - } - } - - public void FitToBounds() - { - if( _content != null ) - { - this.SetScrollBars(); - this.ZoomTo( ZoomboxView.Fit ); - } - } - - public void GoBack() - { - if( this.EffectiveViewStackMode == ZoomboxViewStackMode.Disabled ) - return; - - if( this.ViewStackIndex > 0 ) - { - this.ViewStackIndex--; - } - } - - public void GoForward() - { - if( this.EffectiveViewStackMode == ZoomboxViewStackMode.Disabled ) - return; - - if( this.ViewStackIndex < this.ViewStack.Count - 1 ) - { - this.ViewStackIndex++; - } - } - - public void GoHome() - { - if( this.EffectiveViewStackMode == ZoomboxViewStackMode.Disabled ) - return; - - if( this.ViewStackIndex > 0 ) - { - this.ViewStackIndex = 0; - } - } - - public override void OnApplyTemplate() - { - this.AttachToVisualTree(); - base.OnApplyTemplate(); - } - - public void RefocusView() - { - if( this.EffectiveViewStackMode == ZoomboxViewStackMode.Disabled ) - return; - - if( this.ViewStackIndex >= 0 && this.ViewStackIndex < this.ViewStack.Count - && this.CurrentView != this.ViewStack[ this.ViewStackIndex ] ) - { - this.UpdateView( this.ViewStack[ this.ViewStackIndex ], true, false, this.ViewStackIndex ); - } - } - - public void Zoom( double percentage ) - { - // if there is nothing to scale, just return - if( _content == null ) - return; - - this.Zoom( percentage, this.GetZoomRelativePoint() ); - } - - public void Zoom( double percentage, Point relativeTo ) - { - // if there is nothing to scale, just return - if( _content == null ) - return; - - // adjust the current scale relative to the given point - double scale = this.Scale * ( 1 + percentage ); - this.ZoomTo( scale, relativeTo ); - } - - public void ZoomTo( Point position ) - { - // if there is nothing to pan, just return - if( _content == null ) - return; - - // zoom to the new region - this.ZoomTo( new ZoomboxView( new Point( -position.X, -position.Y ) ) ); - } - - public void ZoomTo( Rect region ) - { - if( _content == null ) - return; - - // adjust the current scale and position - this.UpdateView( new ZoomboxView( region ), true, true ); - } - - public void ZoomTo( double scale ) - { - // if there is nothing to scale, just return - if( _content == null ) - return; - - // adjust the current scale relative to the center of the content within the control - this.ZoomTo( scale, true ); - } - - public void ZoomTo( double scale, Point relativeTo ) - { - this.ZoomTo( scale, relativeTo, true, true ); - } - - public void ZoomTo( ZoomboxView view ) - { - this.UpdateView( view, true, true ); - } - - internal void UpdateStackProperties() - { - this.SetValue( Zoombox.HasBackStackPropertyKey, this.ViewStackIndex > 0 ); - this.SetValue( Zoombox.HasForwardStackPropertyKey, this.ViewStack.Count > this.ViewStackIndex + 1 ); - CommandManager.InvalidateRequerySuggested(); - } - - protected override Size MeasureOverride( Size constraint ) - { - if( _content != null ) - { - // measure visuals according to supplied constraint - Size size = base.MeasureOverride( constraint ); - - // now re-measure content to let the child be whatever size it desires - _content.Measure( new Size( double.PositiveInfinity, double.PositiveInfinity ) ); - return size; - } - - - // avoid returning infinity - if( double.IsInfinity( constraint.Height ) ) - { - constraint.Height = 0; - } - - if( double.IsInfinity( constraint.Width ) ) - { - constraint.Width = 0; - } - return constraint; - } - - protected override void OnContentChanged( object oldContent, object newContent ) - { - // disconnect SizeChanged handler from old content - if( oldContent is FrameworkElement ) - { - ( oldContent as FrameworkElement ).RemoveHandler( FrameworkElement.SizeChangedEvent, new SizeChangedEventHandler( this.OnContentSizeChanged ) ); - } - else - { - this.RemoveHandler( FrameworkElement.SizeChangedEvent, new SizeChangedEventHandler( this.OnContentSizeChanged ) ); - } - - // connect SizeChanged handler to new content - if( _content is FrameworkElement ) - { - ( _content as FrameworkElement ).AddHandler( FrameworkElement.SizeChangedEvent, new SizeChangedEventHandler( this.OnContentSizeChanged ), true ); - } - else - { - this.AddHandler( FrameworkElement.SizeChangedEvent, new SizeChangedEventHandler( this.OnContentSizeChanged ), true ); - } - - // update the Visual property of the view finder display panel's VisualBrush - if( _viewFinderDisplay != null && _viewFinderDisplay.VisualBrush != null ) - { - _viewFinderDisplay.VisualBrush.Visual = _content; - } - } - - protected override void OnGotKeyboardFocus( KeyboardFocusChangedEventArgs e ) - { - this.MonitorInput(); - base.OnGotKeyboardFocus( e ); - } - - protected override void OnLostKeyboardFocus( KeyboardFocusChangedEventArgs e ) - { - this.MonitorInput(); - base.OnLostKeyboardFocus( e ); - } - - protected override void OnInitialized( EventArgs e ) - { - base.OnInitialized( e ); - this.CoerceValue( Zoombox.IsAnimatedProperty ); - } - - protected override void OnRender( DrawingContext drawingContext ) - { - if( this.HasArrangedContentPresenter && !this.HasRenderedFirstView ) - { - this.HasRenderedFirstView = true; - if( this.RefocusViewOnFirstRender ) - { - this.RefocusViewOnFirstRender = false; - bool oldAnimated = this.IsAnimated; - this.IsAnimated = false; - try - { - this.RefocusView(); - } - finally - { - this.IsAnimated = oldAnimated; - } - } - } - - base.OnRender( drawingContext ); - } - - - - - private static void RefocusView( DependencyObject o, DependencyPropertyChangedEventArgs e ) - { - Zoombox zoombox = o as Zoombox; - zoombox.UpdateView( zoombox.CurrentView, true, false, zoombox.ViewStackIndex ); - } - - private void AttachToVisualTree() - { - if( _isUpdatingVisualTree ) - return; - - _isUpdatingVisualTree = true; - - // detach from the old tree - this.DetachFromVisualTree(); - - // create the drag adorner for selection operations - _dragAdorner = new DragAdorner( this ); - - // check the template for a SelectionBrush resource - if( this.Template.Resources.Contains( "SelectionBrush" ) ) - _dragAdorner.Brush = this.Template.Resources[ "SelectionBrush" ] as Brush; - - // check the template for a SelectionPen resource - if( this.Template.Resources.Contains( "SelectionPen" ) ) - _dragAdorner.Pen = this.Template.Resources[ "SelectionPen" ] as Pen; - - // check the template for key bindings - if( this.Template.Resources.Contains( "InputBindings" ) ) - { - InputBindingCollection inputBindings = this.Template.Resources[ "InputBindings" ] as InputBindingCollection; - if( inputBindings != null ) - { - this.InputBindings.AddRange( inputBindings ); - } - } - - // locate the content presenter - _contentPresenter = VisualTreeHelperEx.FindDescendantByType( this, typeof( ContentPresenter ) ) as ContentPresenter; - if( _contentPresenter == null ) - throw new InvalidTemplateException( ErrorMessages.GetMessage( "ZoomboxTemplateNeedsContent" ) ); - - _verticalScrollBar = this.GetTemplateChild( PART_VerticalScrollBar ) as ScrollBar; - if( _verticalScrollBar == null ) - throw new InvalidTemplateException( ErrorMessages.GetMessage( "Zoombox vertical scrollBar not found." ) ); - - _verticalScrollBar.Scroll += this.VerticalScrollBar_Scroll; - - _horizontalScrollBar = this.GetTemplateChild( PART_HorizontalScrollBar ) as ScrollBar; - if( _horizontalScrollBar == null ) - throw new InvalidTemplateException( ErrorMessages.GetMessage( "Zoombox horizontal scrollBar not found." ) ); - - _horizontalScrollBar.Scroll += this.HorizontalScrollBar_Scroll; - - // check the template for an AdornerDecorator - AdornerLayer al = null; - AdornerDecorator ad = VisualTreeHelperEx.FindDescendantByType( this, typeof( AdornerDecorator ) ) as AdornerDecorator; - if( ad != null ) - { - al = ad.AdornerLayer; - } - else - { - // look for an inherited adorner layer - try - { - al = AdornerLayer.GetAdornerLayer( this ); - } - catch( Exception ) - { - } - } - - // add the drag adorner to the adorner layer - if( al != null ) - { - al.Add( _dragAdorner ); - } - - // TODO: Why is it necessary to walk the visual tree the first time through? - // If we don't do the following, the content is not laid out correctly (centered) initially. - VisualTreeHelperEx.FindDescendantWithPropertyValue( this, Button.IsPressedProperty, true ); - - // User has not defined a ViewFinder, use the one from this template - if( this.GetValue( Zoombox.ViewFinderPropertyKey.DependencyProperty ) == null ) - { - // set a reference to the ViewFinder element, if present - this.SetValue( Zoombox.ViewFinderPropertyKey, this.Template.FindName( "ViewFinder", this ) as FrameworkElement ); - Zoombox.SetViewFinderVisibility( this, Visibility.Collapsed ); - } - else - { - //user has defined a ViewFinder, hide the one from this template - Zoombox.SetViewFinderVisibility( this, Visibility.Hidden ); - } - - // locate the view finder display panel - if( this.ViewFinder != null ) - { - _viewFinderDisplay = VisualTreeHelperEx.FindDescendantByType( this.ViewFinder, typeof( ZoomboxViewFinderDisplay ) ) as ZoomboxViewFinderDisplay; - } - - // if a ViewFinder was specified but no display panel is present, throw an exception - if( this.ViewFinder != null && _viewFinderDisplay == null ) - throw new InvalidTemplateException( ErrorMessages.GetMessage( "ZoomboxHasViewFinderButNotDisplay" ) ); - - // set up the VisualBrush and adorner for the display panel - if( _viewFinderDisplay != null ) - { - // create VisualBrush for the view finder display panel - this.CreateVisualBrushForViewFinder( _content ); - - // hook up event handlers for dragging and resizing the viewport - _viewFinderDisplay.MouseMove += new MouseEventHandler( this.ViewFinderDisplayMouseMove ); - _viewFinderDisplay.MouseLeftButtonDown += new MouseButtonEventHandler( this.ViewFinderDisplayBeginCapture ); - _viewFinderDisplay.MouseLeftButtonUp += new MouseButtonEventHandler( this.ViewFinderDisplayEndCapture ); - - // bind the ViewportRect property of the display to the Viewport of the Zoombox - Binding binding = new Binding( "Viewport" ); - binding.Mode = BindingMode.OneWay; - binding.Converter = new ViewFinderSelectionConverter( this ); - binding.Source = this; - _viewFinderDisplay.SetBinding( ZoomboxViewFinderDisplay.ViewportRectProperty, binding ); - } - - this.UpdateViewFinderDisplayContentBounds(); - - // set up event handler to run once the content presenter has been arranged - _contentPresenter.LayoutUpdated += new EventHandler( this.ContentPresenterFirstArranged ); - - _isUpdatingVisualTree = false; - } - - private void CreateVisualBrushForViewFinder( Visual visual ) - { - _viewFinderDisplay.VisualBrush = new VisualBrush( visual ); - _viewFinderDisplay.VisualBrush.Stretch = Stretch.Uniform; - _viewFinderDisplay.VisualBrush.AlignmentX = AlignmentX.Left; - _viewFinderDisplay.VisualBrush.AlignmentY = AlignmentY.Top; - } - - private void ContentPresenterFirstArranged( object sender, EventArgs e ) - { - // remove the handler - _contentPresenter.LayoutUpdated -= new EventHandler( this.ContentPresenterFirstArranged ); - - // it's now safe to update the view - this.HasArrangedContentPresenter = true; - this.InvalidateVisual(); - - // temporarily disable animations - bool oldAnimated = IsAnimated; - this.IsAnimated = false; - try - { - // set the initial view - double scale = this.Scale; - Point position = this.Position; - - // if there are items in the ViewStack and a ViewStackIndex is set, use it - if( this.EffectiveViewStackMode != ZoomboxViewStackMode.Disabled ) - { - bool isInitialViewSet = false; - if( this.ViewStack.Count > 0 ) - { - if( this.ViewStackIndex >= 0 ) - { - if( this.ViewStackIndex > this.ViewStack.Count - 1 ) - { - this.ViewStackIndex = this.ViewStack.Count - 1; - } - else - { - this.UpdateView( this.ViewStack[ this.ViewStackIndex ], false, false, this.ViewStackIndex ); - } - } - else if( this.EffectiveViewStackMode != ZoomboxViewStackMode.Auto ) - { - // if this is not an auto-stack, then ensure the index is set to a valid value - if( this.ViewStackIndex < 0 ) - { - this.ViewStackIndex = 0; - } - } - - // if a ViewStackIndex has been set, apply the scale and position values, iff different than the default values - if( this.ViewStackIndex >= 0 ) - { - isInitialViewSet = true; - if( !DoubleHelper.IsNaN( scale ) || !PointHelper.IsEmpty( position ) ) - { - this.UpdateView( new ZoomboxView( scale, position ), false, false ); - } - } - } - - if( !isInitialViewSet ) - { - // set initial view according to the scale and position values and push it on the stack, as necessary - ZoomboxView initialView = new ZoomboxView( DoubleHelper.IsNaN( Scale ) ? 1.0 : Scale, - PointHelper.IsEmpty( position ) ? new Point() : position ); - - if( this.EffectiveViewStackMode == ZoomboxViewStackMode.Auto ) - { - this.ViewStack.PushView( initialView ); - this.ViewStackIndex = 0; - } - else - { - this.UpdateView( initialView, false, false ); - } - } - } - else - { - // just set initial view according to the scale and position values - ZoomboxView initialView = new ZoomboxView( DoubleHelper.IsNaN( Scale ) ? 1.0 : this.Scale, position ); - this.UpdateView( initialView, false, false ); - } - } - finally - { - IsAnimated = oldAnimated; - } - //When ViewFinder is modified, this will refresh the ZoomboxViewFinderDisplay - this.ZoomTo( this.Scale ); - } - - private void DetachFromVisualTree() - { - // remove the drag adorner - if( (_dragAdorner != null) && ( AdornerLayer.GetAdornerLayer( this ) != null ) ) - AdornerLayer.GetAdornerLayer( this ).Remove( _dragAdorner ); - - // remove the layout updated handler, if present - if( _contentPresenter != null ) - { - _contentPresenter.LayoutUpdated -= new EventHandler( this.ContentPresenterFirstArranged ); - } - - //locate the vertical scrollBar - if( _verticalScrollBar != null ) - { - _verticalScrollBar.Scroll -= this.VerticalScrollBar_Scroll; - } - - //locate the horizontal scrollBar - if( _horizontalScrollBar != null ) - { - _horizontalScrollBar.Scroll -= this.HorizontalScrollBar_Scroll; - } - - // remove the view finder display panel's visual brush and adorner - if( _viewFinderDisplay != null ) - { - _viewFinderDisplay.MouseMove -= new MouseEventHandler( this.ViewFinderDisplayMouseMove ); - _viewFinderDisplay.MouseLeftButtonDown -= new MouseButtonEventHandler( this.ViewFinderDisplayBeginCapture ); - _viewFinderDisplay.MouseLeftButtonUp -= new MouseButtonEventHandler( this.ViewFinderDisplayEndCapture ); - BindingOperations.ClearBinding( _viewFinderDisplay, ZoomboxViewFinderDisplay.ViewportRectProperty ); - _viewFinderDisplay = null; - } - - // set object references to null - _contentPresenter = null; - } - - private void Zoombox_Loaded( object sender, RoutedEventArgs e ) - { - this.SetScrollBars(); - } - - private void VerticalScrollBar_Scroll( object sender, ScrollEventArgs e ) - { - double diff = -(e.NewValue + _relativePosition.Y); - - if( e.ScrollEventType == ScrollEventType.LargeIncrement ) - { - diff = -_verticalScrollBar.ViewportSize; - } - else if( e.ScrollEventType == ScrollEventType.LargeDecrement ) - { - diff = _verticalScrollBar.ViewportSize; - } - - this.OnDrag( new DragDeltaEventArgs( 0d, diff / this.Scale ), false ); - - // Raise the Scroll event to user - EventHandler handler = this.Scroll; - if( handler != null ) - { - handler( this, e ); - } - } - - private void HorizontalScrollBar_Scroll( object sender, ScrollEventArgs e ) - { - double diff = -( e.NewValue + _relativePosition.X ); - if( e.ScrollEventType == ScrollEventType.LargeIncrement ) - { - diff = -_horizontalScrollBar.ViewportSize; - } - else if( e.ScrollEventType == ScrollEventType.LargeDecrement ) - { - diff = _horizontalScrollBar.ViewportSize; - } - - this.OnDrag( new DragDeltaEventArgs( diff / this.Scale, 0d ), false ); - - // Raise the Scroll event to user - EventHandler handler = this.Scroll; - if( handler != null ) - { - handler( this, e ); - } - } - - private void DragDisplayViewport( DragDeltaEventArgs e, bool end ) - { - // get the scale of the view finder display panel, the selection rect, and the VisualBrush rect - double scale = _viewFinderDisplay.Scale; - Rect viewportRect = _viewFinderDisplay.ViewportRect; - Rect vbRect = _viewFinderDisplay.ContentBounds; - - // if the entire content is visible, do nothing - if( viewportRect.Contains( vbRect ) ) - return; - - // ensure that we stay within the bounds of the VisualBrush - double dx = e.HorizontalChange; - double dy = e.VerticalChange; - - // check left boundary - if( viewportRect.Left < vbRect.Left ) - { - dx = Math.Max( 0, dx ); - } - else if( viewportRect.Left + dx < vbRect.Left ) - { - dx = vbRect.Left - viewportRect.Left; - } - - // check right boundary - if( viewportRect.Right > vbRect.Right ) - { - dx = Math.Min( 0, dx ); - } - else if( viewportRect.Right + dx > vbRect.Left + vbRect.Width ) - { - dx = vbRect.Left + vbRect.Width - viewportRect.Right; - } - - // check top boundary - if( viewportRect.Top < vbRect.Top ) - { - dy = Math.Max( 0, dy ); - } - else if( viewportRect.Top + dy < vbRect.Top ) - { - dy = vbRect.Top - viewportRect.Top; - } - - // check bottom boundary - if( viewportRect.Bottom > vbRect.Bottom ) - { - dy = Math.Min( 0, dy ); - } - else if( viewportRect.Bottom + dy > vbRect.Top + vbRect.Height ) - { - dy = vbRect.Top + vbRect.Height - viewportRect.Bottom; - } - - // call the main OnDrag handler that is used when dragging the content directly - this.OnDrag( new DragDeltaEventArgs( -dx / scale / _viewboxFactor, -dy / scale / _viewboxFactor ), end ); - - // for a drag operation, update the origin with each delta - _originPoint = _originPoint + new Vector( dx, dy ); - } - - private void InitCommands() - { - CommandBinding binding = new CommandBinding( Zoombox.Back, this.GoBack, this.CanGoBack ); - this.CommandBindings.Add( binding ); - - binding = new CommandBinding( Zoombox.Center, this.CenterContent ); - this.CommandBindings.Add( binding ); - - binding = new CommandBinding( Zoombox.Fill, this.FillToBounds ); - this.CommandBindings.Add( binding ); - - binding = new CommandBinding( Zoombox.Fit, this.FitToBounds ); - this.CommandBindings.Add( binding ); - - binding = new CommandBinding( Zoombox.Forward, this.GoForward, this.CanGoForward ); - this.CommandBindings.Add( binding ); - - binding = new CommandBinding( Zoombox.Home, this.GoHome, this.CanGoHome ); - this.CommandBindings.Add( binding ); - - binding = new CommandBinding( Zoombox.PanDown, this.PanDownExecuted ); - this.CommandBindings.Add( binding ); - - binding = new CommandBinding( Zoombox.PanLeft, this.PanLeftExecuted ); - this.CommandBindings.Add( binding ); - - binding = new CommandBinding( Zoombox.PanRight, this.PanRightExecuted ); - this.CommandBindings.Add( binding ); - - binding = new CommandBinding( Zoombox.PanUp, this.PanUpExecuted ); - this.CommandBindings.Add( binding ); - - binding = new CommandBinding( Zoombox.Refocus, this.RefocusView, this.CanRefocusView ); - this.CommandBindings.Add( binding ); - - binding = new CommandBinding( Zoombox.ZoomIn, this.ZoomInExecuted ); - this.CommandBindings.Add( binding ); - - binding = new CommandBinding( Zoombox.ZoomOut, this.ZoomOutExecuted ); - this.CommandBindings.Add( binding ); - } - - private void MonitorInput() - { - // cannot pre-process input in partial trust - if( this.HasUIPermission ) - { - this.PreProcessInput(); - } - } - - private void OnContentSizeChanged( object sender, SizeChangedEventArgs e ) - { - this.UpdateViewFinderDisplayContentBounds(); - - if( this.HasArrangedContentPresenter ) - { - if( this.HasRenderedFirstView ) - { - this.SetScrollBars(); - this.UpdateView( this.CurrentView, true, false, this.CurrentViewIndex ); - } - else - { - // if the content size changes after the content presenter has been arranged, - // but before the first view is rendered, invalidate the render so we can refocus - // the view on the first render - this.RefocusViewOnFirstRender = true; - this.InvalidateVisual(); - } - } - } - - private void OnDrag( DragDeltaEventArgs e, bool end ) - { - Point relativePosition = _relativePosition; - double scale = this.Scale; - Point newPosition = relativePosition + ( this.ContentOffset * scale ) + new Vector( e.HorizontalChange * scale, e.VerticalChange * scale ); - if( this.IsUsingScrollBars ) - { - newPosition.X = Math.Max( Math.Min( newPosition.X, 0d ), -_horizontalScrollBar.Maximum ); - newPosition.Y = Math.Max( Math.Min( newPosition.Y, 0d ), -_verticalScrollBar.Maximum ); - } - - // update the transform - this.UpdateView( new ZoomboxView( scale, newPosition ), false, end ); - } - - private void OnLayoutUpdated( object sender, EventArgs e ) - { - this.UpdateViewport(); - } - - private void OnSelectRegion( DragDeltaEventArgs e, bool end ) - { - // draw adorner rect - if( end ) - { - _dragAdorner.Rect = Rect.Empty; - - if( _trueContent != null ) - { - // get the selected region (in the content's coordinate space) based on the adorner's last position and size - Rect selection = - new Rect( - this.TranslatePoint( _dragAdorner.LastPosition, _trueContent ), - this.TranslatePoint( _dragAdorner.LastPosition + new Vector( _dragAdorner.LastSize.Width, _dragAdorner.LastSize.Height ), _trueContent ) ); - - // zoom to the selection - this.ZoomTo( selection ); - } - } - else - { - _dragAdorner.Rect = - Rect.Intersect( - new Rect( - _originPoint, - new Vector( e.HorizontalChange, e.VerticalChange ) ), - new Rect( - new Point( 0, 0 ), - new Point( this.RenderSize.Width, this.RenderSize.Height ) ) ); - } - } - - private void OnSizeChanged( object sender, SizeChangedEventArgs e ) - { - if( !this.HasArrangedContentPresenter ) - return; - - this.SetScrollBars(); - - // when the size is changing, the viewbox factor must be updated before updating the view - this.UpdateViewboxFactor(); - - bool oldIsAnimated = this.IsAnimated; - this.IsAnimated = false; - try - { - this.UpdateView( this.CurrentView, false, false, this.ViewStackIndex ); - } - finally - { - this.IsAnimated = oldIsAnimated; - } - } - - private void SetScrollBars() - { - if( _content == null || _verticalScrollBar == null || _horizontalScrollBar == null ) - return; - - var contentSize = ( _content is Viewbox ) ? ( ( Viewbox )_content ).Child.DesiredSize : this.RenderSize; - - _verticalScrollBar.SmallChange = 10d; - _verticalScrollBar.LargeChange = 10d; - _verticalScrollBar.Minimum = 0d; - _verticalScrollBar.ViewportSize = this.RenderSize.Height; - _verticalScrollBar.Maximum = contentSize.Height - _verticalScrollBar.ViewportSize; - - _horizontalScrollBar.SmallChange = 10d; - _horizontalScrollBar.LargeChange = 10d; - _horizontalScrollBar.Minimum = 0d; - _horizontalScrollBar.ViewportSize = this.RenderSize.Width; - _horizontalScrollBar.Maximum = contentSize.Width - _horizontalScrollBar.ViewportSize; - } - - private void PreProcessInput() - { - // if mouse is over the Zoombox element or if it has keyboard focus, pre-process input - // to update the KeyModifier trigger properties (e.g., DragModifiersAreActive) - if( this.IsMouseOver || this.IsKeyboardFocusWithin ) - { - if( !this.IsMonitoringInput ) - { - this.IsMonitoringInput = true; - InputManager.Current.PreNotifyInput += new NotifyInputEventHandler( this.PreProcessInput ); - this.UpdateKeyModifierTriggerProperties(); - } - } - else - { - if( this.IsMonitoringInput ) - { - this.IsMonitoringInput = false; - InputManager.Current.PreNotifyInput -= new NotifyInputEventHandler( this.PreProcessInput ); - - this.SetAreDragModifiersActive( false ); - this.SetAreRelativeZoomModifiersActive( false ); - this.SetAreZoomModifiersActive( false ); - this.SetAreZoomToSelectionModifiersActive( false ); - } - } - } - - private void PreProcessInput( object sender, NotifyInputEventArgs e ) - { - if( e.StagingItem.Input is KeyEventArgs ) - { - this.UpdateKeyModifierTriggerProperties(); - } - } - - private void ProcessMouseLeftButtonDown( MouseButtonEventArgs e ) - { - if( this.ZoomToSelectionModifiers.AreActive ) - { - this.SetIsDraggingContent( false ); - this.SetIsSelectingRegion( true ); - } - else if( this.DragModifiers.AreActive ) - { - this.SetIsSelectingRegion( false ); - this.SetIsDraggingContent( true ); - } - else - { - this.SetIsSelectingRegion( false ); - this.SetIsDraggingContent( false ); - } - - // if nothing to do, just return - if( !this.IsSelectingRegion && !this.IsDraggingContent ) - return; - - // set the origin point and capture the mouse - _originPoint = e.GetPosition( this ); - _contentPresenter.CaptureMouse(); - e.Handled = true; - if( this.IsDraggingContent ) - { - // execute the Drag operation - this.OnDrag( new DragDeltaEventArgs( 0, 0 ), false ); - } - else if( this.IsSelectingRegion ) - { - this.OnSelectRegion( new DragDeltaEventArgs( 0, 0 ), false ); - } - } - - private void ProcessMouseLeftButtonUp( MouseButtonEventArgs e ) - { - if( !this.IsDraggingContent && !this.IsSelectingRegion ) - return; - - bool endDrag = this.IsDraggingContent; - - this.SetIsDraggingContent( false ); - this.SetIsSelectingRegion( false ); - - _originPoint = new Point(); - _contentPresenter.ReleaseMouseCapture(); - e.Handled = true; - - if( endDrag ) - { - this.OnDrag( new DragDeltaEventArgs( 0, 0 ), true ); - } - else - { - this.OnSelectRegion( new DragDeltaEventArgs( 0, 0 ), true ); - } - } - - private void ProcessMouseMove( MouseEventArgs e ) - { - if( e.MouseDevice.LeftButton != MouseButtonState.Pressed ) - return; - - if( !this.IsDraggingContent && !this.IsSelectingRegion ) - return; - - Point pos = e.GetPosition( this ); - e.Handled = true; - - if( this.IsDraggingContent ) - { - Vector delta = ( pos - _originPoint ) / this.Scale; - this.OnDrag( new DragDeltaEventArgs( delta.X, delta.Y ), false ); - _originPoint = pos; - } - else if( this.IsSelectingRegion ) - { - Vector delta = pos - _originPoint; - this.OnSelectRegion( new DragDeltaEventArgs( delta.X, delta.Y ), false ); - } - } - - private void ProcessMouseWheelZoom( MouseWheelEventArgs e ) - { - if( _content == null ) - return; - - // check modifiers to see if there's work to do - bool doZoom = this.ZoomModifiers.AreActive; - bool doRelativeZoom = this.RelativeZoomModifiers.AreActive; - - // can't do both, so assume relative zoom - if( doZoom && doRelativeZoom ) - { - doZoom = false; - } - - if( !( doZoom || doRelativeZoom ) ) - return; - - e.Handled = true; - double percentage = ( ( e.Delta / Zoombox.MOUSE_WHEEL_DELTA ) * this.ZoomPercentage ) / 100; - - // Are we doing a zoom relative to the current mouse position? - if( doRelativeZoom ) - { - this.Zoom( percentage, Mouse.GetPosition( _content ) ); - } - else - { - this.Zoom( percentage ); - } - } - - private void ProcessNavigationButton( RoutedEventArgs e ) - { - if( e is MouseButtonEventArgs ) - { - MouseButtonEventArgs mbea = e as MouseButtonEventArgs; - if( mbea.ChangedButton == MouseButton.XButton1 - || mbea.ChangedButton == MouseButton.XButton2 ) - { - if( mbea.ChangedButton == MouseButton.XButton2 ) - { - this.GoForward(); - } - else - { - this.GoBack(); - } - mbea.Handled = true; - } - } - else if( e is KeyEventArgs ) - { - KeyEventArgs kea = e as KeyEventArgs; - if( kea.Key == Key.Back || kea.Key == Key.BrowserBack || kea.Key == Key.BrowserForward ) - { - if( kea.Key == Key.BrowserForward ) - { - this.GoForward(); - } - else - { - this.GoBack(); - } - kea.Handled = true; - } - } - } - - private void ResizeDisplayViewport( DragDeltaEventArgs e, ResizeEdge relativeTo ) - { - // get the existing viewport rect and scale - Rect viewportRect = _viewFinderDisplay.ViewportRect; - double scale = _viewFinderDisplay.Scale; - - // ensure that we stay within the bounds of the VisualBrush - double x = Math.Max( _resizeViewportBounds.Left, Math.Min( _resizeDraggingPoint.X + e.HorizontalChange, _resizeViewportBounds.Right ) ); - double y = Math.Max( _resizeViewportBounds.Top, Math.Min( _resizeDraggingPoint.Y + e.VerticalChange, _resizeViewportBounds.Bottom ) ); - - // get the selected region in the coordinate space of the content - Point anchorPoint = new Point( _resizeAnchorPoint.X / scale, _resizeAnchorPoint.Y / scale ); - Vector newRegionVector = new Vector( ( x - _resizeAnchorPoint.X ) / scale / _viewboxFactor, ( y - _resizeAnchorPoint.Y ) / scale / _viewboxFactor ); - Rect region = new Rect( anchorPoint, newRegionVector ); - - // now translate the region from the coordinate space of the content - // to the coordinate space of the content presenter - region = - new Rect( - _content.TranslatePoint( region.TopLeft, _contentPresenter ), - _content.TranslatePoint( region.BottomRight, _contentPresenter ) ); - - // calculate actual scale value - double aspectX = this.RenderSize.Width / region.Width; - double aspectY = this.RenderSize.Height / region.Height; - scale = aspectX < aspectY ? aspectX : aspectY; - - // scale relative to the anchor point - this.ZoomTo( scale, anchorPoint, false, false ); - } - - private void UpdateKeyModifierTriggerProperties() - { - this.SetAreDragModifiersActive( this.DragModifiers.AreActive ); - this.SetAreRelativeZoomModifiersActive( this.RelativeZoomModifiers.AreActive ); - this.SetAreZoomModifiersActive( this.ZoomModifiers.AreActive ); - this.SetAreZoomToSelectionModifiersActive( this.ZoomToSelectionModifiers.AreActive ); - } - - private void UpdateView( ZoomboxView view, bool allowAnimation, bool allowStackAddition ) - { - this.UpdateView( view, allowAnimation, allowStackAddition, -1 ); - } - - private void UpdateView( ZoomboxView view, bool allowAnimation, bool allowStackAddition, int stackIndex ) - { - if( _contentPresenter == null || _content == null || !this.HasArrangedContentPresenter ) - return; - - // if an absolute view is being used and only a Scale value has been specified, - // use the ZoomTo() function to perform a relative zoom - if( view.ViewKind == ZoomboxViewKind.Absolute && PointHelper.IsEmpty( view.Position ) ) - { - this.ZoomTo( view.Scale, allowStackAddition ); - return; - } - - // disallow reentrancy - if( !this.IsUpdatingView ) - { - this.IsUpdatingView = true; - try - { - // determine the new scale and position - double newRelativeScale = _viewboxFactor; - Point newRelativePosition = new Point(); - Rect region = Rect.Empty; - switch( view.ViewKind ) - { - case ZoomboxViewKind.Empty: - break; - - case ZoomboxViewKind.Absolute: - newRelativeScale = DoubleHelper.IsNaN( view.Scale ) ? _relativeScale : view.Scale; - newRelativePosition = PointHelper.IsEmpty( view.Position ) ? _relativePosition - : new Point( view.Position.X, view.Position.Y ) - this.ContentOffset * newRelativeScale; - break; - - case ZoomboxViewKind.Region: - region = view.Region; - break; - - case ZoomboxViewKind.Center: - { - // get the current ContentRect in the coordinate space of the Zoombox control - Rect currentContentRect = - new Rect( - _content.TranslatePoint( this.ContentRect.TopLeft, this ), - _content.TranslatePoint( this.ContentRect.BottomRight, this ) ); - - // inflate (or deflate) the rect by the appropriate amounts in the x & y directions - region = Rect.Inflate( currentContentRect, - ( this.RenderSize.Width / _viewboxFactor - currentContentRect.Width ) / 2, - ( this.RenderSize.Height / _viewboxFactor - currentContentRect.Height ) / 2 ); - - // now translate the centered rect back to the coordinate space of the content - region = new Rect( this.TranslatePoint( region.TopLeft, _content ), this.TranslatePoint( region.BottomRight, _content ) ); - } - break; - - case ZoomboxViewKind.Fit: - region = this.ContentRect; - break; - - case ZoomboxViewKind.Fill: - region = this.CalculateFillRect(); - break; - } - - if( view.ViewKind != ZoomboxViewKind.Empty ) - { - if( !region.IsEmpty ) - { // ZOOMING TO A REGION - this.CalculatePositionAndScale( region, ref newRelativePosition, ref newRelativeScale ); - } - else if( view != ZoomboxView.Empty ) - { // USING ABSOLUTE POSITION AND SCALE VALUES - - // ensure that the scale value falls within the valid range - if( newRelativeScale > MaxScale ) - { - newRelativeScale = MaxScale; - } - else if( newRelativeScale < MinScale ) - { - newRelativeScale = MinScale; - } - } - - double currentScale = _relativeScale; - double currentX = _relativePosition.X; - double currentY = _relativePosition.Y; - - ScaleTransform st = null; - TranslateTransform tt = null; - TransformGroup tg = null; - - if( _contentPresenter.RenderTransform != Transform.Identity ) - { - tg = _contentPresenter.RenderTransform as TransformGroup; - st = tg.Children[ 0 ] as ScaleTransform; - tt = tg.Children[ 1 ] as TranslateTransform; - currentScale = st.ScaleX; - currentX = tt.X; - currentY = tt.Y; - } - - if( KeepContentInBounds == true ) - { - Rect boundsRect = new Rect( new Size( this.ContentRect.Width * newRelativeScale, this.ContentRect.Height * newRelativeScale ) ); - - // Calc viewport rect (should be inside bounds content rect) - Point viewportPosition = new Point( -newRelativePosition.X, -newRelativePosition.Y ); - Rect viewportRect = new Rect( viewportPosition, _contentPresenter.RenderSize ); - - if( DoubleHelper.AreVirtuallyEqual( _relativeScale, newRelativeScale ) ) // we are positioning the content, not scaling - { - // Handle the width and height seperately since the content extent - // could be contained only partially in the viewport. Also if the viewport is only - // partially contained within the content extent. - - // - // Content extent width is greater than the viewport's width (Zoomed in). Make sure we restrict - // the viewport X inside the content. - // - if( this.IsGreaterThanOrClose( boundsRect.Width, viewportRect.Width ) ) - { - if( boundsRect.Right < viewportRect.Right ) - { - newRelativePosition.X = -( boundsRect.Width - viewportRect.Width ); - } - - if( boundsRect.Left > viewportRect.Left ) - { - newRelativePosition.X = 0; - } - } - // - // Viewport width is greater than the content extent's width (Zoomed out). Make sure we restrict - // the content X inside the viewport. - // - else if( this.IsGreaterThanOrClose( viewportRect.Width, boundsRect.Width ) ) - { - if( viewportRect.Right < boundsRect.Right ) - { - newRelativePosition.X = viewportRect.Width - boundsRect.Width; - } - - if( viewportRect.Left > boundsRect.Left ) - { - newRelativePosition.X = 0; - } - } - - // - // Content extent height is greater than the viewport's height (Zoomed in). Make sure we restrict - // the viewport Y inside the content. - // - if( this.IsGreaterThanOrClose( boundsRect.Height, viewportRect.Height ) ) - { - if( boundsRect.Bottom < viewportRect.Bottom ) - { - newRelativePosition.Y = -( boundsRect.Height - viewportRect.Height ); - } - - if( boundsRect.Top > viewportRect.Top ) - { - newRelativePosition.Y = 0; - } - } - // - // Viewport height is greater than the content extent's height (Zoomed out). Make sure we restrict - // the content Y inside the viewport. - // - else if( this.IsGreaterThanOrClose( viewportRect.Height, boundsRect.Height ) ) - { - if( viewportRect.Bottom < boundsRect.Bottom ) - { - newRelativePosition.Y = viewportRect.Height - boundsRect.Height; - } - - if( viewportRect.Top > boundsRect.Top ) - { - newRelativePosition.Y = 0; - } - } - } - } - - st = new ScaleTransform( newRelativeScale / _viewboxFactor, newRelativeScale / _viewboxFactor ); - tt = new TranslateTransform( newRelativePosition.X, newRelativePosition.Y ); - tg = new TransformGroup(); - tg.Children.Add( st ); - tg.Children.Add( tt ); - - _contentPresenter.RenderTransform = tg; - - var initialContentSize = ( _content is Viewbox ) ? ( ( Viewbox )_content ).Child.DesiredSize : this.RenderSize; - var scaledContentSize = new Size( initialContentSize.Width * newRelativeScale, initialContentSize.Height * newRelativeScale ); - - if( allowAnimation && IsAnimated ) - { - DoubleAnimation daScale = new DoubleAnimation( currentScale, newRelativeScale / _viewboxFactor, AnimationDuration ); - daScale.AccelerationRatio = this.AnimationAccelerationRatio; - daScale.DecelerationRatio = this.AnimationDecelerationRatio; - - DoubleAnimation daTranslateX = new DoubleAnimation( currentX, newRelativePosition.X, AnimationDuration ); - daTranslateX.AccelerationRatio = this.AnimationAccelerationRatio; - daTranslateX.DecelerationRatio = this.AnimationDecelerationRatio; - - DoubleAnimation daTranslateY = new DoubleAnimation( currentY, newRelativePosition.Y, AnimationDuration ); - daTranslateY.AccelerationRatio = this.AnimationAccelerationRatio; - daTranslateY.DecelerationRatio = this.AnimationDecelerationRatio; - daTranslateY.CurrentTimeInvalidated += new EventHandler( this.UpdateViewport ); - daTranslateY.CurrentStateInvalidated += new EventHandler( this.ZoomAnimationCompleted ); - - // raise animation beginning event before beginning the animations - RaiseEvent( new RoutedEventArgs( AnimationBeginningEvent, this ) ); - - st.BeginAnimation( ScaleTransform.ScaleXProperty, daScale ); - st.BeginAnimation( ScaleTransform.ScaleYProperty, daScale ); - tt.BeginAnimation( TranslateTransform.XProperty, daTranslateX ); - tt.BeginAnimation( TranslateTransform.YProperty, daTranslateY ); - - if( this.IsUsingScrollBars ) - { - //Vertical scrollBar animations - DoubleAnimation verticalMaxAnimation = new DoubleAnimation(); - verticalMaxAnimation.From = _verticalScrollBar.Maximum; - verticalMaxAnimation.To = scaledContentSize.Height - _verticalScrollBar.ViewportSize; - verticalMaxAnimation.Duration = AnimationDuration; - _verticalScrollBar.BeginAnimation( ScrollBar.MaximumProperty, verticalMaxAnimation ); - - DoubleAnimation verticalValueAnimation = new DoubleAnimation(); - verticalValueAnimation.From = _verticalScrollBar.Value; - verticalValueAnimation.To = -newRelativePosition.Y; - verticalValueAnimation.Duration = AnimationDuration; - verticalValueAnimation.Completed += this.VerticalValueAnimation_Completed; - _verticalScrollBar.BeginAnimation( ScrollBar.ValueProperty, verticalValueAnimation ); - - //Horizontal scrollBar animations - DoubleAnimation horizontalMaxAnimation = new DoubleAnimation(); - horizontalMaxAnimation.From = _horizontalScrollBar.Maximum; - horizontalMaxAnimation.To = scaledContentSize.Width - _horizontalScrollBar.ViewportSize; - horizontalMaxAnimation.Duration = AnimationDuration; - _horizontalScrollBar.BeginAnimation( ScrollBar.MaximumProperty, horizontalMaxAnimation ); - - DoubleAnimation horizontalValueAnimation = new DoubleAnimation(); - horizontalValueAnimation.From = _horizontalScrollBar.Value; - horizontalValueAnimation.To = -newRelativePosition.X; - horizontalValueAnimation.Duration = AnimationDuration; - horizontalValueAnimation.Completed += this.HorizontalValueAnimation_Completed; - _horizontalScrollBar.BeginAnimation( ScrollBar.ValueProperty, horizontalValueAnimation ); - } - } - else if( this.IsUsingScrollBars ) - { - //Vertical scrollBar - _verticalScrollBar.Maximum = scaledContentSize.Height - _verticalScrollBar.ViewportSize; - _verticalScrollBar.Value = -newRelativePosition.Y; - //Horizontal scrollBar - _horizontalScrollBar.Maximum = scaledContentSize.Width - _horizontalScrollBar.ViewportSize; - _horizontalScrollBar.Value = -newRelativePosition.X; - } - - // maintain the relative scale and position for dragging and animating purposes - _relativePosition = newRelativePosition; - _relativeScale = newRelativeScale; - - // update the Scale and Position properties to keep them in sync with the current view - this.Scale = newRelativeScale; - _basePosition = newRelativePosition + this.ContentOffset * newRelativeScale; - this.UpdateViewport(); - } - - // add the current view to the view stack - if( this.EffectiveViewStackMode == ZoomboxViewStackMode.Auto && allowStackAddition ) - { - // if the last view was pushed on the stack within the last 300 milliseconds, discard it - // since proximally close views are probably the result of a mouse wheel scroll - if( this.ViewStack.Count > 1 - && Math.Abs( DateTime.Now.Ticks - _lastStackAddition.Ticks ) < TimeSpan.FromMilliseconds( 300 ).Ticks ) - { - this.ViewStack.RemoveAt( this.ViewStack.Count - 1 ); - _lastStackAddition = DateTime.Now - TimeSpan.FromMilliseconds( 300 ); - } - - // if the current view is the same as the last view, do nothing - if( this.ViewStack.Count > 0 && view == this.ViewStack.SelectedView ) - { - // do nothing - } - else - { - // otherwise, push the current view on stack - this.ViewStack.PushView( view ); - this.ViewStackIndex++; - stackIndex = this.ViewStackIndex; - - // update the timestamp for the last stack addition - _lastStackAddition = DateTime.Now; - } - } - - // update the stack indices used by CurrentViewChanged event - _lastViewIndex = this.CurrentViewIndex; - this.SetCurrentViewIndex( stackIndex ); - - // set the new view parameters - // NOTE: this is the only place where the CurrentView member should be set - this.SetCurrentView( view ); - } - finally - { - this.IsUpdatingView = false; - } - } - } - - private bool IsGreaterThanOrClose( double value1, double value2 ) - { - return value1 <= value2 ? DoubleHelper.AreVirtuallyEqual( value1, value2 ) : true; - } - - private Rect CalculateFillRect() - { - // determine the x-y ratio of the current Viewport - double xyRatio = this.RenderSize.Width / this.RenderSize.Height; - - // now find the maximal rect within the ContentRect that has the same ratio - double x = 0; - double y = 0; - double width = this.ContentRect.Width; - double height = this.ContentRect.Height; - if( xyRatio > width / height ) - { - height = width / xyRatio; - y = ( this.ContentRect.Height - height ) / 2; - } - else - { - width = height * xyRatio; - x = ( this.ContentRect.Width - width ) / 2; - } - - return new Rect( x, y, width, height ); - } - - private void CalculatePositionAndScale( Rect region, ref Point newRelativePosition, ref double newRelativeScale ) - { - // if there is nothing to scale, just return - // if the region has no area, just return - if( region.Width == 0 || region.Height == 0 ) - return; - - // verify that the selected region intersects with the content, which prevents - // the scale operation from zooming the content out of the current view - if( !this.ContentRect.IntersectsWith( region ) ) - return; - - // translate the region from the coordinate space of the content - // to the coordinate space of the content presenter - region = - new Rect( - _content.TranslatePoint( region.TopLeft, _contentPresenter ), - _content.TranslatePoint( region.BottomRight, _contentPresenter ) ); - - // calculate actual zoom, which must fit the entire selection - // while maintaining a 1:1 ratio - double aspectX = this.RenderSize.Width / region.Width; - double aspectY = this.RenderSize.Height / region.Height; - newRelativeScale = aspectX < aspectY ? aspectX : aspectY; - - // ensure that the scale value falls within the valid range - if( newRelativeScale > this.MaxScale ) - { - newRelativeScale = this.MaxScale; - } - else if( newRelativeScale < this.MinScale ) - { - newRelativeScale = this.MinScale; - } - - // determine the new content position for this zoom operation based - // on HorizontalContentAlignment and VerticalContentAlignment - double horizontalOffset = 0; - double verticalOffset = 0; - switch( this.HorizontalContentAlignment ) - { - case HorizontalAlignment.Center: - case HorizontalAlignment.Stretch: - horizontalOffset = ( this.RenderSize.Width - region.Width * newRelativeScale ) / 2; - break; - - case HorizontalAlignment.Right: - horizontalOffset = ( this.RenderSize.Width - region.Width * newRelativeScale ); - break; - } - switch( VerticalContentAlignment ) - { - case VerticalAlignment.Center: - case VerticalAlignment.Stretch: - verticalOffset = ( this.RenderSize.Height - region.Height * newRelativeScale ) / 2; - break; - - case VerticalAlignment.Bottom: - verticalOffset = ( this.RenderSize.Height - region.Height * newRelativeScale ); - break; - } - newRelativePosition = - new Point( -region.TopLeft.X * newRelativeScale, -region.TopLeft.Y * newRelativeScale ) - + new Vector( horizontalOffset, verticalOffset ); - } - - private void UpdateViewFinderDisplayContentBounds() - { - if( _content == null || _trueContent == null || _viewFinderDisplay == null || _viewFinderDisplay.AvailableSize.IsEmpty ) - return; - - this.UpdateViewboxFactor(); - - // ensure the display panel has a size - Size contentSize = _content.RenderSize; - Size viewFinderSize = _viewFinderDisplay.AvailableSize; - if( viewFinderSize.Width > 0d && DoubleHelper.AreVirtuallyEqual( viewFinderSize.Height, 0d ) ) - { - // update height to accomodate width, while keeping a ratio equal to the actual content - viewFinderSize = new Size( viewFinderSize.Width, contentSize.Height * viewFinderSize.Width / contentSize.Width ); - } - else if( viewFinderSize.Height > 0d && DoubleHelper.AreVirtuallyEqual( viewFinderSize.Width, 0d ) ) - { - // update width to accomodate height, while keeping a ratio equal to the actual content - viewFinderSize = new Size( contentSize.Width * viewFinderSize.Height / contentSize.Height, viewFinderSize.Width ); - } - - // determine the scale of the view finder display panel - double aspectX = viewFinderSize.Width / contentSize.Width; - double aspectY = viewFinderSize.Height / contentSize.Height; - double scale = aspectX < aspectY ? aspectX : aspectY; - - // determine the rect of the VisualBrush - double vbWidth = contentSize.Width * scale; - double vbHeight = contentSize.Height * scale; - - // set the ContentBounds and Scale properties on the view finder display panel - _viewFinderDisplay.Scale = scale; - _viewFinderDisplay.ContentBounds = new Rect( new Size( vbWidth, vbHeight ) ); - } - - private void UpdateViewboxFactor() - { - if( _content == null || _trueContent == null ) - return; - - double contentWidth = _content.RenderSize.Width; - double trueContentWidth = _trueContent.RenderSize.Width; - - if( DoubleHelper.AreVirtuallyEqual( contentWidth, 0d ) || DoubleHelper.AreVirtuallyEqual( trueContentWidth, 0d ) ) - { - _viewboxFactor = 1d; - } - else - { - _viewboxFactor = contentWidth / trueContentWidth; - } - } - - private void UpdateViewport() - { - // if we haven't attached to the visual tree yet or we don't have content, just return - if( _contentPresenter == null || _trueContent == null ) - return; - - this.IsUpdatingViewport = true; - try - { - // calculate the current viewport - Rect viewport = - new Rect( - this.TranslatePoint( new Point( 0d, 0d ), _trueContent ), - this.TranslatePoint( new Point( RenderSize.Width, RenderSize.Height ), _trueContent ) ); - - // if the viewport has changed, set the Viewport dependency property - if( !DoubleHelper.AreVirtuallyEqual( viewport, this.Viewport ) ) - { - this.SetValue( Zoombox.ViewportPropertyKey, viewport ); - } - } - finally - { - this.IsUpdatingViewport = false; - } - } - - private void UpdateViewport( object sender, EventArgs e ) - { - this.UpdateViewport(); - } - - private void ViewFinderDisplayBeginCapture( object sender, MouseButtonEventArgs e ) - { - const double ARBITRARY_LARGE_VALUE = 10000000000; - - // if we need to acquire capture, the Tag property of the view finder display panel - // will be a ResizeEdge value. - if( _viewFinderDisplay.Tag is ResizeEdge ) - { - // if the Tag is ResizeEdge.None, then its a drag operation; otherwise, its a resize - if( ( ResizeEdge )_viewFinderDisplay.Tag == ResizeEdge.None ) - { - this.IsDraggingViewport = true; - } - else - { - this.IsResizingViewport = true; - Vector direction = new Vector(); - switch( ( ResizeEdge )_viewFinderDisplay.Tag ) - { - case ResizeEdge.TopLeft: - _resizeDraggingPoint = _viewFinderDisplay.ViewportRect.TopLeft; - _resizeAnchorPoint = _viewFinderDisplay.ViewportRect.BottomRight; - direction = new Vector( -1, -1 ); - break; - - case ResizeEdge.TopRight: - _resizeDraggingPoint = _viewFinderDisplay.ViewportRect.TopRight; - _resizeAnchorPoint = _viewFinderDisplay.ViewportRect.BottomLeft; - direction = new Vector( 1, -1 ); - break; - - case ResizeEdge.BottomLeft: - _resizeDraggingPoint = _viewFinderDisplay.ViewportRect.BottomLeft; - _resizeAnchorPoint = _viewFinderDisplay.ViewportRect.TopRight; - direction = new Vector( -1, 1 ); - break; - - case ResizeEdge.BottomRight: - _resizeDraggingPoint = _viewFinderDisplay.ViewportRect.BottomRight; - _resizeAnchorPoint = _viewFinderDisplay.ViewportRect.TopLeft; - direction = new Vector( 1, 1 ); - break; - case ResizeEdge.Left: - _resizeDraggingPoint = new Point( _viewFinderDisplay.ViewportRect.Left, - _viewFinderDisplay.ViewportRect.Top + ( _viewFinderDisplay.ViewportRect.Height / 2 ) ); - _resizeAnchorPoint = new Point( _viewFinderDisplay.ViewportRect.Right, - _viewFinderDisplay.ViewportRect.Top + ( _viewFinderDisplay.ViewportRect.Height / 2 ) ); - direction = new Vector( -1, 0 ); - break; - case ResizeEdge.Top: - _resizeDraggingPoint = new Point( _viewFinderDisplay.ViewportRect.Left + ( _viewFinderDisplay.ViewportRect.Width / 2 ), - _viewFinderDisplay.ViewportRect.Top ); - _resizeAnchorPoint = new Point( _viewFinderDisplay.ViewportRect.Left + ( _viewFinderDisplay.ViewportRect.Width / 2 ), - _viewFinderDisplay.ViewportRect.Bottom ); - direction = new Vector( 0, -1 ); - break; - case ResizeEdge.Right: - _resizeDraggingPoint = new Point( _viewFinderDisplay.ViewportRect.Right, - _viewFinderDisplay.ViewportRect.Top + ( _viewFinderDisplay.ViewportRect.Height / 2 ) ); - _resizeAnchorPoint = new Point( _viewFinderDisplay.ViewportRect.Left, - _viewFinderDisplay.ViewportRect.Top + ( _viewFinderDisplay.ViewportRect.Height / 2 ) ); - direction = new Vector( 1, 0 ); - break; - case ResizeEdge.Bottom: - _resizeDraggingPoint = new Point( _viewFinderDisplay.ViewportRect.Left + ( _viewFinderDisplay.ViewportRect.Width / 2 ), - _viewFinderDisplay.ViewportRect.Bottom ); - _resizeAnchorPoint = new Point( _viewFinderDisplay.ViewportRect.Left + ( _viewFinderDisplay.ViewportRect.Width / 2 ), - _viewFinderDisplay.ViewportRect.Top ); - direction = new Vector( 0, 1 ); - break; - } - double scale = _viewFinderDisplay.Scale; - Rect contentRect = _viewFinderDisplay.ContentBounds; - Vector minVector = new Vector( direction.X * ARBITRARY_LARGE_VALUE, direction.Y * ARBITRARY_LARGE_VALUE ); - Vector maxVector = new Vector( direction.X * contentRect.Width / MaxScale, direction.Y * contentRect.Height / MaxScale ); - _resizeViewportBounds = new Rect( _resizeAnchorPoint + minVector, _resizeAnchorPoint + maxVector ); - } - - // store the origin of the operation and acquire capture - _originPoint = e.GetPosition( _viewFinderDisplay ); - _viewFinderDisplay.CaptureMouse(); - e.Handled = true; - } - } - - private void ViewFinderDisplayEndCapture( object sender, MouseButtonEventArgs e ) - { - // if a drag or resize is in progress, end it and release capture - if( this.IsDraggingViewport || this.IsResizingViewport ) - { - // call the DragDisplayViewport method to end the operation - // and store the current position on the stack - this.DragDisplayViewport( new DragDeltaEventArgs( 0, 0 ), true ); - - // reset the dragging state variables and release capture - this.IsDraggingViewport = false; - this.IsResizingViewport = false; - _originPoint = new Point(); - _viewFinderDisplay.ReleaseMouseCapture(); - e.Handled = true; - } - } - - private void ViewFinderDisplayMouseMove( object sender, MouseEventArgs e ) - { - // if a drag operation is in progress, update the operation - if( e.MouseDevice.LeftButton == MouseButtonState.Pressed - && ( this.IsDraggingViewport || this.IsResizingViewport ) ) - { - Point pos = e.GetPosition( _viewFinderDisplay ); - Vector delta = pos - _originPoint; - if( this.IsDraggingViewport ) - { - this.DragDisplayViewport( new DragDeltaEventArgs( delta.X, delta.Y ), false ); - } - else - { - this.ResizeDisplayViewport( new DragDeltaEventArgs( delta.X, delta.Y ), ( ResizeEdge )_viewFinderDisplay.Tag ); - } - e.Handled = true; - } - else - { - // update the cursor based on the nearest corner - Point mousePos = e.GetPosition( _viewFinderDisplay ); - Rect viewportRect = _viewFinderDisplay.ViewportRect; - double cornerDelta = viewportRect.Width * viewportRect.Height > 100 ? 5.0 - : Math.Sqrt( viewportRect.Width * viewportRect.Height ) / 2; - - // if the mouse is within the Rect and the Rect does not encompass the entire content, set the appropriate cursor - if( viewportRect.Contains( mousePos ) - && !DoubleHelper.AreVirtuallyEqual( Rect.Intersect( viewportRect, _viewFinderDisplay.ContentBounds ), _viewFinderDisplay.ContentBounds ) ) - { - if( PointHelper.DistanceBetween( mousePos, viewportRect.TopLeft ) < cornerDelta ) - { - _viewFinderDisplay.Tag = ResizeEdge.TopLeft; - _viewFinderDisplay.Cursor = Cursors.SizeNWSE; - } - else if( PointHelper.DistanceBetween( mousePos, viewportRect.BottomRight ) < cornerDelta ) - { - _viewFinderDisplay.Tag = ResizeEdge.BottomRight; - _viewFinderDisplay.Cursor = Cursors.SizeNWSE; - } - else if( PointHelper.DistanceBetween( mousePos, viewportRect.TopRight ) < cornerDelta ) - { - _viewFinderDisplay.Tag = ResizeEdge.TopRight; - _viewFinderDisplay.Cursor = Cursors.SizeNESW; - } - else if( PointHelper.DistanceBetween( mousePos, viewportRect.BottomLeft ) < cornerDelta ) - { - _viewFinderDisplay.Tag = ResizeEdge.BottomLeft; - _viewFinderDisplay.Cursor = Cursors.SizeNESW; - } - else if( mousePos.X <= viewportRect.Left + cornerDelta ) - { - _viewFinderDisplay.Tag = ResizeEdge.Left; - _viewFinderDisplay.Cursor = Cursors.SizeWE; - } - else if( mousePos.Y <= viewportRect.Top + cornerDelta ) - { - _viewFinderDisplay.Tag = ResizeEdge.Top; - _viewFinderDisplay.Cursor = Cursors.SizeNS; - } - else if( mousePos.X >= viewportRect.Right - cornerDelta ) - { - _viewFinderDisplay.Tag = ResizeEdge.Right; - _viewFinderDisplay.Cursor = Cursors.SizeWE; - } - else if( mousePos.Y >= viewportRect.Bottom - cornerDelta ) - { - _viewFinderDisplay.Tag = ResizeEdge.Bottom; - _viewFinderDisplay.Cursor = Cursors.SizeNS; - } - else - { - _viewFinderDisplay.Tag = ResizeEdge.None; - _viewFinderDisplay.Cursor = Cursors.SizeAll; - } - } - else - { - _viewFinderDisplay.Tag = null; - _viewFinderDisplay.Cursor = Cursors.Arrow; - } - } - } - - private void ZoomAnimationCompleted( object sender, EventArgs e ) - { - if( ( sender as AnimationClock ).CurrentState != ClockState.Active ) - { - // remove the event handlers - ( sender as AnimationClock ).CurrentStateInvalidated -= new EventHandler( this.ZoomAnimationCompleted ); - ( sender as AnimationClock ).CurrentTimeInvalidated -= new EventHandler( this.UpdateViewport ); - - // raise animation completed event - this.RaiseEvent( new RoutedEventArgs( Zoombox.AnimationCompletedEvent, this ) ); - } - } - - private void VerticalValueAnimation_Completed( object sender, EventArgs e ) - { - //When the animaton is completed, with the FillBehavior to HoldEnd, - //the ScrollBarValue will be overriden with the final animation value, preventing future scroll. - //To remove it use BeginAnimation with null. - //http://msdn.microsoft.com/en-us/library/aa970493(v=vs.110).aspx - - // only do this when all the overlapped animations are done or limits values reached. - if( ( _verticalScrollBar.Value == -_relativePosition.Y ) - || ( _verticalScrollBar.Value == _verticalScrollBar.Maximum ) - || ( _verticalScrollBar.Value == _verticalScrollBar.Minimum ) ) - { - var finalValue = _verticalScrollBar.Value; - //this will reset Value to original value of animation - _verticalScrollBar.BeginAnimation( ScrollBar.ValueProperty, null ); - //this will set to last value of the animation. - _verticalScrollBar.Value = finalValue; - } - } - - private void HorizontalValueAnimation_Completed( object sender, EventArgs e ) - { - //When the animaton is completed, with the FillBehavior to HoldEnd, - //the ScrollBarValue will be overriden with the final animation value, preventing future scroll. - //To remove it use BeginAnimation with null. - //http://msdn.microsoft.com/en-us/library/aa970493(v=vs.110).aspx - - // only do this when all the overlapped animations are done or limits values reached. - if( ( _horizontalScrollBar.Value == -_relativePosition.X ) - || ( _horizontalScrollBar.Value == _horizontalScrollBar.Maximum ) - || ( _horizontalScrollBar.Value == _horizontalScrollBar.Minimum ) ) - { - var finalValue = _horizontalScrollBar.Value; - //this will reset Value to original value of animation - _horizontalScrollBar.BeginAnimation( ScrollBar.ValueProperty, null ); - //this will set to last value of the animation. - _horizontalScrollBar.Value = finalValue; - } - } - - private void ZoomTo( double scale, bool allowStackAddition ) - { - // if there is nothing to scale, just return - if( _content == null ) - return; - - // adjust the current scale relative to the zoom origin - this.ZoomTo( scale, this.GetZoomRelativePoint(), true, allowStackAddition ); - } - - private void ZoomTo( double scale, Point relativeTo, bool restrictRelativePointToContent, bool allowStackAddition ) - { - // if there is nothing to scale, just return - if( _content == null ) - return; - - if( double.IsNaN( scale ) ) - return; - - // if necessary, verify that the relativeTo point falls within the content - if( restrictRelativePointToContent && !( new Rect( _content.RenderSize ) ).Contains( relativeTo ) ) - return; - - // ensure that the scale value falls within the valid range - if( scale > this.MaxScale ) - { - scale = this.MaxScale; - } - else if( scale < this.MinScale ) - { - scale = this.MinScale; - } - - // internally, updates are always relative to the Zoombox control - Point translateFrom = relativeTo; - if( this.HasRenderedFirstView ) - { - // Note that this TranslatePoint approach will not work until the first render occurs - relativeTo = _content.TranslatePoint( relativeTo, this ); - - // adjust translateFrom based on relativeTo - translateFrom = this.TranslatePoint( relativeTo, _contentPresenter ); - } - else if( _contentPresenter != null ) - { - // prior to the first render, just use the ContentPresenter's transform and do not adjust translateFrom - if( _contentPresenter.RenderTransform == Transform.Identity ) - { - // in order for this approach to work, we must at least make one pass to update a generic view - // with Scale = 1.0 and Position = 0,0 - this.UpdateView( new ZoomboxView( 1, new Point( 0, 0 ) ), false, false ); - } - - // now there should be a valid RenderTransform - relativeTo = ( _contentPresenter.RenderTransform as Transform ).Transform( relativeTo ); - } - - // determine the new content position for this zoom operation - Point translateTo = new Point( relativeTo.X - ( translateFrom.X * scale / _viewboxFactor ), - relativeTo.Y - ( translateFrom.Y * scale / _viewboxFactor ) ) - + this.ContentOffset * scale / _viewboxFactor; - this.UpdateView( new ZoomboxView( scale, translateTo ), !this.IsResizingViewport, allowStackAddition ); - } - - private Point GetZoomRelativePoint() - { - Point zoomPoint; - - if( ZoomOn == ZoomboxZoomOn.View ) - { - // Transform the viewport point to the content - Point viewportZoomOrigin = new Point(); - - viewportZoomOrigin.X = this.Viewport.X + ( this.Viewport.Width * this.ZoomOrigin.X ); - viewportZoomOrigin.Y = this.Viewport.Y + ( this.Viewport.Height * this.ZoomOrigin.Y ); - - Point contentZoomOrigin = _trueContent.TranslatePoint( viewportZoomOrigin, _content ); - - if( contentZoomOrigin.X < 0 ) - { - contentZoomOrigin.X = 0; - } - else if( contentZoomOrigin.X > _content.RenderSize.Width ) - { - contentZoomOrigin.X = _content.RenderSize.Width; - } - - if( contentZoomOrigin.Y < 0 ) - { - contentZoomOrigin.Y = 0; - } - else if( contentZoomOrigin.Y > _content.RenderSize.Height ) - { - contentZoomOrigin.Y = _content.RenderSize.Height; - } - - zoomPoint = contentZoomOrigin; - } - else - { - zoomPoint = new Point( _content.RenderSize.Width * ZoomOrigin.X, _content.RenderSize.Height * ZoomOrigin.Y ); - } - - return zoomPoint; - } - - #region OnKeyDown Methods - - protected override void OnPreviewKeyDown( KeyEventArgs e ) - { - if( this.NavigateOnPreview && !e.Handled ) - { - this.ProcessNavigationButton( e ); - } - - base.OnPreviewKeyDown( e ); - } - - protected override void OnKeyDown( KeyEventArgs e ) - { - if( !this.NavigateOnPreview && !e.Handled ) - { - this.ProcessNavigationButton( e ); - } - - base.OnKeyDown( e ); - } - - #endregion - - #region OnMouseDown Methods - - protected override void OnPreviewMouseDown( MouseButtonEventArgs e ) - { - if( this.NavigateOnPreview && !e.Handled ) - { - this.ProcessNavigationButton( e ); - } - - base.OnPreviewMouseDown( e ); - } - - protected override void OnMouseDown( MouseButtonEventArgs e ) - { - if( !this.NavigateOnPreview && !e.Handled ) - { - this.ProcessNavigationButton( e ); - } - - base.OnMouseDown( e ); - } - - #endregion - - #region OnMouseEnter Methods - - protected override void OnMouseEnter( MouseEventArgs e ) - { - this.MonitorInput(); - - base.OnMouseEnter( e ); - } - - #endregion - - #region OnMouseLeave Methods - - protected override void OnMouseLeave( MouseEventArgs e ) - { - this.MonitorInput(); - - base.OnMouseLeave( e ); - } - - #endregion - - #region OnMouseLeftButton Methods - - protected override void OnPreviewMouseLeftButtonDown( MouseButtonEventArgs e ) - { - if( this.DragOnPreview && !e.Handled && _contentPresenter != null ) - { - this.ProcessMouseLeftButtonDown( e ); - } - - base.OnPreviewMouseLeftButtonDown( e ); - } - - protected override void OnMouseLeftButtonDown( MouseButtonEventArgs e ) - { - if( !this.DragOnPreview && !e.Handled && _contentPresenter != null ) - { - this.ProcessMouseLeftButtonDown( e ); - } - - base.OnMouseLeftButtonDown( e ); - } - - protected override void OnPreviewMouseLeftButtonUp( MouseButtonEventArgs e ) - { - if( this.DragOnPreview && !e.Handled && _contentPresenter != null ) - { - this.ProcessMouseLeftButtonUp( e ); - } - - base.OnPreviewMouseLeftButtonUp( e ); - } - - protected override void OnMouseLeftButtonUp( MouseButtonEventArgs e ) - { - if( !this.DragOnPreview && !e.Handled && _contentPresenter != null ) - { - this.ProcessMouseLeftButtonUp( e ); - } - - base.OnMouseLeftButtonUp( e ); - } - - #endregion - - #region OnMouseMove Methods - - protected override void OnPreviewMouseMove( MouseEventArgs e ) - { - if( this.DragOnPreview && !e.Handled && _contentPresenter != null ) - { - this.ProcessMouseMove( e ); - } - - base.OnPreviewMouseMove( e ); - } - - protected override void OnMouseMove( MouseEventArgs e ) - { - if( !this.DragOnPreview && !e.Handled && _contentPresenter != null ) - { - this.ProcessMouseMove( e ); - } - - base.OnMouseMove( e ); - } - - #endregion - - #region OnMouseWheel Methods - - protected override void OnPreviewMouseWheel( MouseWheelEventArgs e ) - { - if( this.ZoomOnPreview && !e.Handled && _contentPresenter != null ) - { - this.ProcessMouseWheelZoom( e ); - } - - base.OnPreviewMouseWheel( e ); - } - - protected override void OnMouseWheel( MouseWheelEventArgs e ) - { - if( !this.ZoomOnPreview && !e.Handled && _contentPresenter != null ) - { - this.ProcessMouseWheelZoom( e ); - } - - base.OnMouseWheel( e ); - } - - #endregion - - #region Private Fields - - // the default value for a single mouse wheel delta appears to be 28 - private static int MOUSE_WHEEL_DELTA = 28; - - // the content control's one and only content presenter - private ContentPresenter _contentPresenter = null; - - //The Scrollbars - private ScrollBar _verticalScrollBar = null; - private ScrollBar _horizontalScrollBar = null; - - // the content of the Zoombox (cast as a UIElement) - private UIElement _content = null; - - // the drag adorner used for selecting a region in a zoom-to-selection operation - private DragAdorner _dragAdorner = null; - - // the view stack - private ZoomboxViewStack _viewStack = null; - - // the view finder display panel - // this is used to show the current viewport - private ZoomboxViewFinderDisplay _viewFinderDisplay = null; - - // state variables used during drag and select operations - private Rect _resizeViewportBounds = Rect.Empty; - private Point _resizeAnchorPoint = new Point( 0, 0 ); - private Point _resizeDraggingPoint = new Point( 0, 0 ); - private Point _originPoint = new Point( 0, 0 ); - - private double _viewboxFactor = 1.0; - private double _relativeScale = 1.0; - private Point _relativePosition = new Point(); - private Point _basePosition = new Point(); - - // used to track the time delta between stack operations - private DateTime _lastStackAddition; - - // used to provide stack index when view changes - private int _lastViewIndex = -1; - - private BitVector32 _cacheBits = new BitVector32( 0 ); - - #endregion - - #region ViewFinderSelectionConverter Nested Type - - private sealed class ViewFinderSelectionConverter : IValueConverter - { - public ViewFinderSelectionConverter( Zoombox zoombox ) - { - _zoombox = zoombox; - } - - public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) - { - Rect viewport = ( Rect )value; - if( viewport.IsEmpty ) - return viewport; - - // adjust the viewport from the coordinate space of the Content element - // to the coordinate space of the view finder display panel - double scale = _zoombox._viewFinderDisplay.Scale * _zoombox._viewboxFactor; - Rect result = new Rect( viewport.Left * scale, viewport.Top * scale, - viewport.Width * scale, viewport.Height * scale ); - result.Offset( _zoombox._viewFinderDisplay.ContentBounds.Left, - _zoombox._viewFinderDisplay.ContentBounds.Top ); - return result; - } - - public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) - { - return null; - } - - private readonly Zoombox _zoombox; - } - - #endregion - - #region DragAdorner Nested Type - - internal sealed class DragAdorner : Adorner - { - public DragAdorner( UIElement adornedElement ) - : base( adornedElement ) - { - this.ClipToBounds = true; - } - - public static readonly DependencyProperty BrushProperty = - DependencyProperty.Register( "Brush", typeof( Brush ), typeof( DragAdorner ), - new FrameworkPropertyMetadata( Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender ) ); - - public Brush Brush - { - get - { - return ( Brush )this.GetValue( DragAdorner.BrushProperty ); - } - set - { - this.SetValue( DragAdorner.BrushProperty, value ); - } - } - - public static readonly DependencyProperty PenProperty = - DependencyProperty.Register( "Pen", typeof( Pen ), typeof( DragAdorner ), - new FrameworkPropertyMetadata( new Pen( new SolidColorBrush( Color.FromArgb( 0x7F, 0x3F, 0x3F, 0x3F ) ), 2d ), FrameworkPropertyMetadataOptions.AffectsRender ) ); - - public Pen Pen - { - get - { - return ( Pen )this.GetValue( DragAdorner.PenProperty ); - } - set - { - this.SetValue( DragAdorner.PenProperty, value ); - } - } - - public static readonly DependencyProperty RectProperty = - DependencyProperty.Register( "Rect", typeof( Rect ), typeof( DragAdorner ), - new FrameworkPropertyMetadata( Rect.Empty, FrameworkPropertyMetadataOptions.AffectsRender, - new PropertyChangedCallback( DragAdorner.OnRectChanged ) ) ); - - public Rect Rect - { - get - { - return ( Rect )this.GetValue( DragAdorner.RectProperty ); - } - set - { - this.SetValue( DragAdorner.RectProperty, value ); - } - } - - private static void OnRectChanged( DependencyObject d, DependencyPropertyChangedEventArgs e ) - { - DragAdorner dragAdorner = ( DragAdorner )d; - Rect rect = ( Rect )e.NewValue; - - // ignore empty values - if( rect.IsEmpty ) - return; - - // if the value is not empty, cache the position and size - dragAdorner._cachedPosition = ( ( Rect )e.NewValue ).TopLeft; - dragAdorner._cachedSize = ( ( Rect )e.NewValue ).Size; - } - - public Point LastPosition - { - get - { - return _cachedPosition; - } - } - - public Size LastSize - { - get - { - return _cachedSize; - } - } - - protected override void OnRender( DrawingContext drawingContext ) - { - drawingContext.DrawRectangle( Brush, Pen, Rect ); - } - - private Point _cachedPosition; - private Size _cachedSize; - } - - #endregion - - #region CacheBits Nested Type - - private enum CacheBits - { - IsUpdatingView = 0x00000001, - IsUpdatingViewport = 0x00000002, - IsDraggingViewport = 0x00000004, - IsResizingViewport = 0x00000008, - IsMonitoringInput = 0x00000010, - IsContentWrapped = 0x00000020, - HasArrangedContentPresenter = 0x00000040, - HasRenderedFirstView = 0x00000080, - RefocusViewOnFirstRender = 0x00000100, - HasUIPermission = 0x00000200, - } - - #endregion - - #region ResizeEdge Nested Type - - private enum ResizeEdge - { - None, - TopLeft, - TopRight, - BottomLeft, - BottomRight, - Left, - Top, - Right, - Bottom, - } - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxCursors.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxCursors.cs deleted file mode 100644 index 1a81dfea..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxCursors.cs +++ /dev/null @@ -1,73 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System.Reflection; -using System.Security; -using System.Security.Permissions; -using System.Windows.Input; -using Xceed.Wpf.Toolkit.Core.Utilities; - -namespace Xceed.Wpf.Toolkit.Zoombox -{ - public class ZoomboxCursors - { - #region Constructors - - static ZoomboxCursors() - { - try - { - new EnvironmentPermission( PermissionState.Unrestricted ).Demand(); - _zoom = new Cursor( ResourceHelper.LoadResourceStream( Assembly.GetExecutingAssembly(), "Zoombox/Resources/Zoom.cur" ) ); - _zoomRelative = new Cursor( ResourceHelper.LoadResourceStream( Assembly.GetExecutingAssembly(), "Zoombox/Resources/ZoomRelative.cur" ) ); - } - catch( SecurityException ) - { - // partial trust, so just use default cursors - } - } - - #endregion - - #region Zoom Static Property - - public static Cursor Zoom - { - get - { - return _zoom; - } - } - - private static readonly Cursor _zoom = Cursors.Arrow; - - #endregion - - #region ZoomRelative Static Property - - public static Cursor ZoomRelative - { - get - { - return _zoomRelative; - } - } - - private static readonly Cursor _zoomRelative = Cursors.Arrow; - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxView.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxView.cs deleted file mode 100644 index e88029c1..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxView.cs +++ /dev/null @@ -1,314 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.ComponentModel; -using System.Windows; -using Xceed.Wpf.Toolkit.Core.Utilities; -using Xceed.Wpf.Toolkit.Core; - -namespace Xceed.Wpf.Toolkit.Zoombox -{ - [TypeConverter( typeof( ZoomboxViewConverter ) )] - public class ZoomboxView - { - #region Constructors - - public ZoomboxView() - { - } - - public ZoomboxView( double scale ) - { - this.Scale = scale; - } - - public ZoomboxView( Point position ) - { - this.Position = position; - } - - public ZoomboxView( double scale, Point position ) - { - this.Position = position; - this.Scale = scale; - } - - public ZoomboxView( Rect region ) - { - this.Region = region; - } - - public ZoomboxView( double x, double y ) - : this( new Point( x, y ) ) - { - } - - public ZoomboxView( double scale, double x, double y ) - : this( scale, new Point( x, y ) ) - { - } - - public ZoomboxView( double x, double y, double width, double height ) - : this( new Rect( x, y, width, height ) ) - { - } - - #endregion - - #region Empty Static Property - - public static ZoomboxView Empty - { - get - { - return _empty; - } - } - - private static readonly ZoomboxView _empty = new ZoomboxView( ZoomboxViewKind.Empty ); - - #endregion - - #region Fill Static Property - - public static ZoomboxView Fill - { - get - { - return _fill; - } - } - - private static readonly ZoomboxView _fill = new ZoomboxView( ZoomboxViewKind.Fill ); - - #endregion - - #region Fit Static Property - - public static ZoomboxView Fit - { - get - { - return _fit; - } - } - - private static readonly ZoomboxView _fit = new ZoomboxView( ZoomboxViewKind.Fit ); - - #endregion - - #region Center Static Property - - public static ZoomboxView Center - { - get - { - return _center; - } - } - - private static readonly ZoomboxView _center = new ZoomboxView( ZoomboxViewKind.Center ); - - #endregion - - #region ViewKind Property - - public ZoomboxViewKind ViewKind - { - get - { - if( _kindHeight > 0 ) - { - return ZoomboxViewKind.Region; - } - else - { - return ( ZoomboxViewKind )( int )_kindHeight; - } - } - } - - private double _kindHeight = ( int )ZoomboxViewKind.Empty; - - #endregion - - #region Position Property - - public Point Position - { - get - { - if( this.ViewKind != ZoomboxViewKind.Absolute ) - throw new InvalidOperationException( ErrorMessages.GetMessage( "PositionOnlyAccessibleOnAbsolute" ) ); - - return new Point( _x, _y ); - } - set - { - if( this.ViewKind != ZoomboxViewKind.Absolute && this.ViewKind != ZoomboxViewKind.Empty ) - throw new InvalidOperationException( String.Format( ErrorMessages.GetMessage( "ZoomboxViewAlreadyInitialized" ), this.ViewKind.ToString() ) ); - - _x = value.X; - _y = value.Y; - _kindHeight = ( int )ZoomboxViewKind.Absolute; - } - } - - private double _x = double.NaN; - private double _y = double.NaN; - - #endregion - - #region Scale Property - - public double Scale - { - get - { - if( this.ViewKind != ZoomboxViewKind.Absolute ) - throw new InvalidOperationException( ErrorMessages.GetMessage( "ScaleOnlyAccessibleOnAbsolute" ) ); - - return _scaleWidth; - } - set - { - if( this.ViewKind != ZoomboxViewKind.Absolute && this.ViewKind != ZoomboxViewKind.Empty ) - throw new InvalidOperationException( String.Format( ErrorMessages.GetMessage( "ZoomboxViewAlreadyInitialized" ), this.ViewKind.ToString() ) ); - - _scaleWidth = value; - _kindHeight = ( int )ZoomboxViewKind.Absolute; - } - } - - private double _scaleWidth = double.NaN; - - #endregion - - #region Region Property - - public Rect Region - { - get - { - // a region view has a positive _typeHeight value - if( _kindHeight < 0 ) - throw new InvalidOperationException( ErrorMessages.GetMessage( "RegionOnlyAccessibleOnRegionalView" ) ); - - return new Rect( _x, _y, _scaleWidth, _kindHeight ); - } - set - { - if( this.ViewKind != ZoomboxViewKind.Region && this.ViewKind != ZoomboxViewKind.Empty ) - throw new InvalidOperationException( String.Format( ErrorMessages.GetMessage( "ZoomboxViewAlreadyInitialized" ), this.ViewKind.ToString() ) ); - - if( !value.IsEmpty ) - { - _x = value.X; - _y = value.Y; - _scaleWidth = value.Width; - _kindHeight = value.Height; - } - } - } - - #endregion - - public override int GetHashCode() - { - return _x.GetHashCode() ^ _y.GetHashCode() ^ _scaleWidth.GetHashCode() ^ _kindHeight.GetHashCode(); - } - - public override bool Equals( object o ) - { - bool result = false; - if( o is ZoomboxView ) - { - ZoomboxView other = ( ZoomboxView )o; - if( this.ViewKind == other.ViewKind ) - { - switch( this.ViewKind ) - { - case ZoomboxViewKind.Absolute: - result = ( DoubleHelper.AreVirtuallyEqual( _scaleWidth, other._scaleWidth ) ) - && ( DoubleHelper.AreVirtuallyEqual( Position, other.Position ) ); - break; - - case ZoomboxViewKind.Region: - result = DoubleHelper.AreVirtuallyEqual( Region, other.Region ); - break; - - default: - result = true; - break; - } - } - } - return result; - } - - public override string ToString() - { - switch( ViewKind ) - { - case ZoomboxViewKind.Empty: - return "ZoomboxView: Empty"; - - case ZoomboxViewKind.Center: - return "ZoomboxView: Center"; - - case ZoomboxViewKind.Fill: - return "ZoomboxView: Fill"; - - case ZoomboxViewKind.Fit: - return "ZoomboxView: Fit"; - - case ZoomboxViewKind.Absolute: - return string.Format( "ZoomboxView: Scale = {0}; Position = ({1}, {2})", _scaleWidth.ToString( "f" ), _x.ToString( "f" ), _y.ToString( "f" ) ); - - case ZoomboxViewKind.Region: - return string.Format( "ZoomboxView: Region = ({0}, {1}, {2}, {3})", _x.ToString( "f" ), _y.ToString( "f" ), _scaleWidth.ToString( "f" ), _kindHeight.ToString( "f" ) ); - } - - return base.ToString(); - } - - private ZoomboxView( ZoomboxViewKind viewType ) - { - _kindHeight = ( int )viewType; - } - - #region Operators Methods - - public static bool operator ==( ZoomboxView v1, ZoomboxView v2 ) - { - if( ( object )v1 == null ) - return ( object )v2 == null; - - if( ( object )v2 == null ) - return ( object )v1 == null; - - return v1.Equals( v2 ); - } - - public static bool operator !=( ZoomboxView v1, ZoomboxView v2 ) - { - return !( v1 == v2 ); - } - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewChangedEventArgs.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewChangedEventArgs.cs deleted file mode 100644 index c37c34d4..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewChangedEventArgs.cs +++ /dev/null @@ -1,96 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using Xceed.Wpf.Toolkit.Core; - -namespace Xceed.Wpf.Toolkit.Zoombox -{ - public class ZoomboxViewChangedEventArgs : PropertyChangedEventArgs - { - #region Constructors - - public ZoomboxViewChangedEventArgs( - ZoomboxView oldView, - ZoomboxView newView, - int oldViewStackIndex, - int newViewStackIndex ) - : base( Zoombox.CurrentViewChangedEvent, oldView, newView ) - { - _newViewStackIndex = newViewStackIndex; - _oldViewStackIndex = oldViewStackIndex; - } - - #endregion - - #region NewViewStackIndex Property - - public int NewViewStackIndex - { - get - { - return _newViewStackIndex; - } - } - - private readonly int _newViewStackIndex = -1; - - #endregion - - #region NewViewStackIndex Property - - public int OldViewStackIndex - { - get - { - return _oldViewStackIndex; - } - } - - private readonly int _oldViewStackIndex = -1; - - #endregion - - #region NewViewStackIndex Property - - public bool IsNewViewFromStack - { - get - { - return _newViewStackIndex >= 0; - } - } - - #endregion - - #region NewViewStackIndex Property - - public bool IsOldViewFromStack - { - get - { - return _oldViewStackIndex >= 0; - } - } - - #endregion - - protected override void InvokeEventHandler( Delegate genericHandler, object genericTarget ) - { - ( ( ZoomboxViewChangedEventHandler )genericHandler )( genericTarget, this ); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewChangedEventHandler.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewChangedEventHandler.cs deleted file mode 100644 index 26c53afe..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewChangedEventHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -namespace Xceed.Wpf.Toolkit.Zoombox -{ - public delegate void ZoomboxViewChangedEventHandler( object sender, ZoomboxViewChangedEventArgs e ); -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewConverter.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewConverter.cs deleted file mode 100644 index dfef6069..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewConverter.cs +++ /dev/null @@ -1,207 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Globalization; -using System.Windows; -using Xceed.Wpf.Toolkit.Core.Utilities; - -namespace Xceed.Wpf.Toolkit.Zoombox -{ - public sealed class ZoomboxViewConverter : TypeConverter - { - #region Converter Static Property - - internal static ZoomboxViewConverter Converter - { - get - { - if( _converter == null ) - { - _converter = new ZoomboxViewConverter(); - } - return _converter; - } - } - - private static ZoomboxViewConverter _converter; //null - - #endregion - - public override bool CanConvertFrom( ITypeDescriptorContext typeDescriptorContext, Type type ) - { - return ( type == typeof( string ) ) - || ( type == typeof( double ) ) - || ( type == typeof( Point ) ) - || ( type == typeof( Rect ) ) - || ( base.CanConvertFrom( typeDescriptorContext, type ) ); - } - - public override bool CanConvertTo( ITypeDescriptorContext typeDescriptorContext, Type type ) - { - return ( type == typeof( string ) ) - || ( base.CanConvertTo( typeDescriptorContext, type ) ); - } - - public override object ConvertFrom( - ITypeDescriptorContext typeDescriptorContext, - CultureInfo cultureInfo, - object value ) - { - ZoomboxView result = null; - if( value is double ) - { - result = new ZoomboxView( ( double )value ); - } - else if( value is Point ) - { - result = new ZoomboxView( ( Point )value ); - } - else if( value is Rect ) - { - result = new ZoomboxView( ( Rect )value ); - } - else if( value is string ) - { - if( string.IsNullOrEmpty( ( value as string ).Trim() ) ) - { - result = ZoomboxView.Empty; - } - else - { - switch( ( value as string ).Trim().ToLower() ) - { - case "center": - result = ZoomboxView.Center; - break; - - case "empty": - result = ZoomboxView.Empty; - break; - - case "fill": - result = ZoomboxView.Fill; - break; - - case "fit": - result = ZoomboxView.Fit; - break; - - default: - // parse double values; respect the following separators: ' ', ';', or ',' - List values = new List(); - foreach( string token in ( value as string ).Split( new char[] { ' ', ';', ',' }, StringSplitOptions.RemoveEmptyEntries ) ) - { - double d; - if( double.TryParse( token, out d ) ) - { - values.Add( d ); - } - if( values.Count >= 4 ) - { - // disregard additional values - break; - } - } - - switch( values.Count ) - { - case 1: // scale - result = new ZoomboxView( values[ 0 ] ); - break; - - case 2: // x, y - result = new ZoomboxView( values[ 0 ], values[ 1 ] ); - break; - - case 3: // scale, x, y - result = new ZoomboxView( values[ 0 ], values[ 1 ], values[ 2 ] ); - break; - - case 4: // x, y, width, height - result = new ZoomboxView( values[ 0 ], values[ 1 ], values[ 2 ], values[ 3 ] ); - break; - } - break; - } - } - } - return ( result == null ? base.ConvertFrom( typeDescriptorContext, cultureInfo, value ) : result ); - } - - public override object ConvertTo( - ITypeDescriptorContext typeDescriptorContext, - CultureInfo cultureInfo, - object value, - Type destinationType ) - { - object result = null; - ZoomboxView view = value as ZoomboxView; - - if( view != null ) - { - if( destinationType == typeof( string ) ) - { - result = "Empty"; - switch( view.ViewKind ) - { - case ZoomboxViewKind.Absolute: - if( PointHelper.IsEmpty( view.Position ) ) - { - if( !DoubleHelper.IsNaN( view.Scale ) ) - { - result = view.Scale.ToString(); - } - } - else if( DoubleHelper.IsNaN( view.Scale ) ) - { - result = view.Position.X.ToString() + "," + view.Position.Y.ToString(); - } - else - { - result = view.Scale.ToString() + "," - + view.Position.X.ToString() + "," - + view.Position.Y.ToString(); - } - break; - - case ZoomboxViewKind.Center: - result = "Center"; - break; - - case ZoomboxViewKind.Fill: - result = "Fill"; - break; - - case ZoomboxViewKind.Fit: - result = "Fit"; - break; - - case ZoomboxViewKind.Region: - result = view.Region.X.ToString() + "," - + view.Region.Y.ToString() + "," - + view.Region.Width.ToString() + "," - + view.Region.Height.ToString(); - break; - } - } - } - return ( result == null ? base.ConvertTo( typeDescriptorContext, cultureInfo, value, destinationType ) : result ); - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewException.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewException.cs deleted file mode 100644 index a9c524eb..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewException.cs +++ /dev/null @@ -1,32 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; - -namespace Xceed.Wpf.Toolkit.Zoombox -{ - public class ZoomboxViewException : Exception - { - #region Constructors - - public ZoomboxViewException( string message ) - : base( message ) - { - } - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewFinderDisplay.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewFinderDisplay.cs deleted file mode 100644 index ee199759..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewFinderDisplay.cs +++ /dev/null @@ -1,284 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Windows; -using System.Windows.Media; -using Xceed.Wpf.Toolkit.Core.Utilities; - -namespace Xceed.Wpf.Toolkit.Zoombox -{ - public class ZoomboxViewFinderDisplay : FrameworkElement - { - #region Constructors - - static ZoomboxViewFinderDisplay() - { - ZoomboxViewFinderDisplay.DefaultStyleKeyProperty.OverrideMetadata( typeof( ZoomboxViewFinderDisplay ), new FrameworkPropertyMetadata( typeof( ZoomboxViewFinderDisplay ) ) ); - } - - public ZoomboxViewFinderDisplay() - { - } - - #endregion - - #region Background Property - - public static readonly DependencyProperty BackgroundProperty = - DependencyProperty.Register( "Background", typeof( Brush ), typeof( ZoomboxViewFinderDisplay ), - new FrameworkPropertyMetadata( new SolidColorBrush( Color.FromArgb( 0xC0, 0xFF, 0xFF, 0xFF ) ), FrameworkPropertyMetadataOptions.AffectsRender ) ); - - public Brush Background - { - get - { - return ( Brush )this.GetValue( ZoomboxViewFinderDisplay.BackgroundProperty ); - } - set - { - this.SetValue( ZoomboxViewFinderDisplay.BackgroundProperty, value ); - } - } - - #endregion - - #region ContentBounds Property - - private static readonly DependencyPropertyKey ContentBoundsPropertyKey = - DependencyProperty.RegisterReadOnly( "ContentBounds", typeof( Rect ), typeof( ZoomboxViewFinderDisplay ), - new FrameworkPropertyMetadata( ( Rect )Rect.Empty, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender ) ); - - public static readonly DependencyProperty ContentBoundsProperty = ZoomboxViewFinderDisplay.ContentBoundsPropertyKey.DependencyProperty; - - internal Rect ContentBounds - { - get - { - return ( Rect )this.GetValue( ZoomboxViewFinderDisplay.ContentBoundsProperty ); - } - set - { - this.SetValue( ZoomboxViewFinderDisplay.ContentBoundsPropertyKey, value ); - } - } - - #endregion - - #region ShadowBrush Property - - public static readonly DependencyProperty ShadowBrushProperty = - DependencyProperty.Register( "ShadowBrush", typeof( Brush ), typeof( ZoomboxViewFinderDisplay ), - new FrameworkPropertyMetadata( new SolidColorBrush( Color.FromArgb( 0x80, 0xFF, 0xFF, 0xFF ) ), FrameworkPropertyMetadataOptions.AffectsRender ) ); - - public Brush ShadowBrush - { - get - { - return ( Brush )this.GetValue( ZoomboxViewFinderDisplay.ShadowBrushProperty ); - } - set - { - this.SetValue( ZoomboxViewFinderDisplay.ShadowBrushProperty, value ); - } - } - - #endregion - - #region ViewportBrush Property - - public static readonly DependencyProperty ViewportBrushProperty = - DependencyProperty.Register( "ViewportBrush", typeof( Brush ), typeof( ZoomboxViewFinderDisplay ), - new FrameworkPropertyMetadata( Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender ) ); - - public Brush ViewportBrush - { - get - { - return ( Brush )this.GetValue( ZoomboxViewFinderDisplay.ViewportBrushProperty ); - } - set - { - this.SetValue( ZoomboxViewFinderDisplay.ViewportBrushProperty, value ); - } - } - - #endregion - - #region ViewportPen Property - - public static readonly DependencyProperty ViewportPenProperty = - DependencyProperty.Register( "ViewportPen", typeof( Pen ), typeof( ZoomboxViewFinderDisplay ), - new FrameworkPropertyMetadata( new Pen( new SolidColorBrush( Color.FromArgb( 0x80, 0x00, 0x00, 0x00 ) ), 1d ), FrameworkPropertyMetadataOptions.AffectsRender ) ); - - public Pen ViewportPen - { - get - { - return ( Pen )this.GetValue( ZoomboxViewFinderDisplay.ViewportPenProperty ); - } - set - { - this.SetValue( ZoomboxViewFinderDisplay.ViewportPenProperty, value ); - } - } - - #endregion - - #region ViewportRect Property - - public static readonly DependencyProperty ViewportRectProperty = - DependencyProperty.Register( "ViewportRect", typeof( Rect ), typeof( ZoomboxViewFinderDisplay ), - new FrameworkPropertyMetadata( Rect.Empty, FrameworkPropertyMetadataOptions.AffectsRender ) ); - - public Rect ViewportRect - { - get - { - return ( Rect )this.GetValue( ZoomboxViewFinderDisplay.ViewportRectProperty ); - } - set - { - this.SetValue( ZoomboxViewFinderDisplay.ViewportRectProperty, value ); - } - } - - #endregion - - #region VisualBrush Property - - private static readonly DependencyPropertyKey VisualBrushPropertyKey = - DependencyProperty.RegisterReadOnly( "VisualBrush", typeof( VisualBrush ), typeof( ZoomboxViewFinderDisplay ), - new FrameworkPropertyMetadata( ( VisualBrush )null ) ); - - public static readonly DependencyProperty VisualBrushProperty = ZoomboxViewFinderDisplay.VisualBrushPropertyKey.DependencyProperty; - - internal VisualBrush VisualBrush - { - get - { - return ( VisualBrush )this.GetValue( ZoomboxViewFinderDisplay.VisualBrushProperty ); - } - set - { - this.SetValue( ZoomboxViewFinderDisplay.VisualBrushPropertyKey, value ); - } - } - - #endregion - - #region AvailableSize Internal Property - - internal Size AvailableSize - { - get - { - return _availableSize; - } - } - - private Size _availableSize = Size.Empty; - - #endregion - - #region Scale Internal Property - - internal double Scale - { - get - { - return _scale; - } - set - { - _scale = value; - } - } - - private double _scale = 1d; - - #endregion - - protected override Size ArrangeOverride( Size finalSize ) - { - // Note that we do not call the Arrange method on any children - // because a ViewFinderDisplay has no children - - // the control's RenderSize should always match its DesiredSize - return this.DesiredSize; - } - - protected override Size MeasureOverride( Size availableSize ) - { - // Note that we do not call the Measure method on any children - // because a ViewFinderDisplay has no children. It is merely used - // as a surface for the view finder's VisualBrush. - - // store the available size for use by the Zoombox control - _availableSize = availableSize; - - // Simulate size-to-content for the display panel by ensuring a width and height - // based on the content bounds. Otherwise, the display panel may have no size, since it doesn't - // contain content. - double width = DoubleHelper.IsNaN( this.ContentBounds.Width ) ? 0 : Math.Max( 0, this.ContentBounds.Width ); - double height = DoubleHelper.IsNaN( this.ContentBounds.Height ) ? 0 : Math.Max( 0, this.ContentBounds.Height ); - Size displayPanelSize = new Size( width, height ); - - // Now ensure that the result fits within the available size while maintaining - // the width/height ratio of the content bounds - if( displayPanelSize.Width > availableSize.Width || displayPanelSize.Height > availableSize.Height ) - { - double aspectX = availableSize.Width / displayPanelSize.Width; - double aspectY = availableSize.Height / displayPanelSize.Height; - double scale = ( aspectX < aspectY ) ? aspectX : aspectY; - displayPanelSize = new Size( displayPanelSize.Width * scale, displayPanelSize.Height * scale ); - } - - return displayPanelSize; - } - - protected override void OnRender( DrawingContext dc ) - { - base.OnRender( dc ); - - dc.DrawRectangle( this.Background, null, this.ContentBounds ); - - dc.DrawRectangle( this.VisualBrush, null, this.ContentBounds ); - - if( this.ViewportRect.IntersectsWith( new Rect( this.RenderSize ) ) ) - { - // draw shadow rectangles over the non-viewport regions - Rect r1 = new Rect( new Point( 0, 0 ), new Size( this.RenderSize.Width, Math.Max( 0, this.ViewportRect.Top ) ) ); - Rect r2 = new Rect( new Point( 0, this.ViewportRect.Top ), new Size( Math.Max( 0, this.ViewportRect.Left ), this.ViewportRect.Height ) ); - Rect r3 = new Rect( new Point( this.ViewportRect.Right, this.ViewportRect.Top ), new Size( Math.Max( 0, this.RenderSize.Width - this.ViewportRect.Right ), this.ViewportRect.Height ) ); - Rect r4 = new Rect( new Point( 0, this.ViewportRect.Bottom ), new Size( this.RenderSize.Width, Math.Max( 0, this.RenderSize.Height - this.ViewportRect.Bottom ) ) ); - dc.DrawRectangle( this.ShadowBrush, null, r1 ); - dc.DrawRectangle( this.ShadowBrush, null, r2 ); - dc.DrawRectangle( this.ShadowBrush, null, r3 ); - dc.DrawRectangle( this.ShadowBrush, null, r4 ); - - // draw the rectangle around the viewport region - dc.DrawRectangle( this.ViewportBrush, this.ViewportPen, this.ViewportRect ); - } - else - { - // if no part of the Rect is visible, just draw a - // shadow over the entire content bounds - dc.DrawRectangle( this.ShadowBrush, null, new Rect( this.RenderSize ) ); - } - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewKind.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewKind.cs deleted file mode 100644 index dfcfa88d..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewKind.cs +++ /dev/null @@ -1,29 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - - -namespace Xceed.Wpf.Toolkit.Zoombox -{ - public enum ZoomboxViewKind - { - Absolute = -5, - Fit = -4, - Fill = -3, - Center = -2, - Empty = -1, - Region, - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewStack.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewStack.cs deleted file mode 100644 index a4e03ff8..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewStack.cs +++ /dev/null @@ -1,555 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -using System; -using System.Collections; -using System.Collections.ObjectModel; -using System.Collections.Specialized; -using System.Windows; -using Xceed.Wpf.Toolkit.Core; - -namespace Xceed.Wpf.Toolkit.Zoombox -{ - public sealed class ZoomboxViewStack : Collection, IWeakEventListener - { - #region Constructors - - public ZoomboxViewStack( Zoombox zoombox ) - { - _zoomboxRef = new WeakReference( zoombox ); - } - - #endregion - - #region SelectedView Property - - public ZoomboxView SelectedView - { - get - { - int currentIndex = this.Zoombox.ViewStackIndex; - return ( currentIndex < 0 || currentIndex > Count - 1 ) ? ZoomboxView.Empty : this[ currentIndex ]; - } - } - - #endregion - - #region AreViewsFromSource Internal Property - - internal bool AreViewsFromSource - { - get - { - return _cacheBits[ ( int )CacheBits.AreViewsFromSource ]; - } - set - { - _cacheBits[ ( int )CacheBits.AreViewsFromSource ] = value; - } - } - - #endregion - - #region Source Internal Property - - internal IEnumerable Source - { - get - { - return _source; - } - } - - // if the view stack is generated by items within the ViewStackSource collection - // of the Zoombox, then we maintain a strong reference to the source - private IEnumerable _source; //null - - #endregion - - #region IsChangeFromSource Private Property - - private bool IsChangeFromSource - { - get - { - return _cacheBits[ ( int )CacheBits.IsChangeFromSource ]; - } - set - { - _cacheBits[ ( int )CacheBits.IsChangeFromSource ] = value; - } - } - - #endregion - - #region IsMovingViews Private Property - - private bool IsMovingViews - { - get - { - return _cacheBits[ ( int )CacheBits.IsMovingViews ]; - } - set - { - _cacheBits[ ( int )CacheBits.IsMovingViews ] = value; - } - } - - #endregion - - #region IsResettingViews Private Property - - private bool IsResettingViews - { - get - { - return _cacheBits[ ( int )CacheBits.IsResettingViews ]; - } - set - { - _cacheBits[ ( int )CacheBits.IsResettingViews ] = value; - } - } - - #endregion - - #region IsSettingInitialViewAfterClear Private Property - - private bool IsSettingInitialViewAfterClear - { - get - { - return _cacheBits[ ( int )CacheBits.IsSettingInitialViewAfterClear ]; - } - set - { - _cacheBits[ ( int )CacheBits.IsSettingInitialViewAfterClear ] = value; - } - } - - #endregion - - #region Zoombox Private Property - - private Zoombox Zoombox - { - get - { - return _zoomboxRef.Target as Zoombox; - } - } - - // maintain a weak reference to the Zoombox that owns the stack - private WeakReference _zoomboxRef; - - #endregion - - internal void ClearViewStackSource() - { - if( this.AreViewsFromSource ) - { - this.AreViewsFromSource = false; - this.MonitorSource( false ); - _source = null; - using( new SourceAccess( this ) ) - { - this.Clear(); - } - this.Zoombox.CoerceValue( Zoombox.ViewStackModeProperty ); - } - } - - internal void PushView( ZoomboxView view ) - { - // clear the forward stack - int currentIndex = this.Zoombox.ViewStackIndex; - while( this.Count - 1 > currentIndex ) - { - this.RemoveAt( Count - 1 ); - } - this.Add( view ); - } - - internal void SetViewStackSource( IEnumerable source ) - { - if( _source != source ) - { - this.MonitorSource( false ); - _source = source; - this.MonitorSource( true ); - this.AreViewsFromSource = true; - this.Zoombox.CoerceValue( Zoombox.ViewStackModeProperty ); - this.ResetViews(); - } - } - - protected override void ClearItems() - { - this.VerifyStackModification(); - - bool currentDeleted = ( this.Zoombox.CurrentViewIndex >= 0 ); - base.ClearItems(); - this.Zoombox.SetViewStackCount( Count ); - - // if resetting the views due to a change in the view source collection, just return - if( this.IsResettingViews ) - return; - - if( this.Zoombox.EffectiveViewStackMode == ZoomboxViewStackMode.Auto && this.Zoombox.CurrentView != ZoomboxView.Empty ) - { - this.IsSettingInitialViewAfterClear = true; - try - { - this.Add( this.Zoombox.CurrentView ); - } - finally - { - this.IsSettingInitialViewAfterClear = false; - } - this.Zoombox.ViewStackIndex = 0; - if( currentDeleted ) - { - this.Zoombox.SetCurrentViewIndex( 0 ); - } - } - else - { - this.Zoombox.ViewStackIndex = -1; - this.Zoombox.SetCurrentViewIndex( -1 ); - } - } - - protected override void InsertItem( int index, ZoomboxView view ) - { - this.VerifyStackModification(); - - if( this.Zoombox.HasArrangedContentPresenter - && this.Zoombox.ViewStackIndex >= index - && !this.IsSettingInitialViewAfterClear - && !this.IsResettingViews - && !this.IsMovingViews ) - { - bool oldUpdatingView = this.Zoombox.IsUpdatingView; - this.Zoombox.IsUpdatingView = true; - try - { - this.Zoombox.ViewStackIndex++; - if( this.Zoombox.CurrentViewIndex != -1 ) - { - this.Zoombox.SetCurrentViewIndex( this.Zoombox.CurrentViewIndex + 1 ); - } - } - finally - { - this.Zoombox.IsUpdatingView = oldUpdatingView; - } - } - - base.InsertItem( index, view ); - this.Zoombox.SetViewStackCount( Count ); - } - - protected override void RemoveItem( int index ) - { - this.VerifyStackModification(); - - bool currentDeleted = ( this.Zoombox.ViewStackIndex == index ); - if( !this.IsMovingViews ) - { - // if an item below the current index was deleted - // (or if the last item is currently selected and it was deleted), - // adjust the ViewStackIndex and CurrentViewIndex values - if( this.Zoombox.HasArrangedContentPresenter - && ( this.Zoombox.ViewStackIndex > index - || ( currentDeleted && this.Zoombox.ViewStackIndex == this.Zoombox.ViewStack.Count - 1 ) ) ) - { - // if removing the last item, just clear the stack, which ensures the proper - // behavior based on the ViewStackMode - if( currentDeleted && this.Zoombox.ViewStack.Count == 1 ) - { - this.Clear(); - return; - } - - bool oldUpdatingView = this.Zoombox.IsUpdatingView; - this.Zoombox.IsUpdatingView = true; - try - { - this.Zoombox.ViewStackIndex--; - if( this.Zoombox.CurrentViewIndex != -1 ) - { - this.Zoombox.SetCurrentViewIndex( this.Zoombox.CurrentViewIndex - 1 ); - } - } - finally - { - this.Zoombox.IsUpdatingView = oldUpdatingView; - } - } - } - - base.RemoveItem( index ); - - // if the current view was deleted, we may need to update the view index - // (unless a non-stack view is in effect) - if( !this.IsMovingViews && currentDeleted && this.Zoombox.CurrentViewIndex != -1 ) - { - this.Zoombox.RefocusView(); - } - - this.Zoombox.SetViewStackCount( Count ); - } - - protected override void SetItem( int index, ZoomboxView view ) - { - this.VerifyStackModification(); - - base.SetItem( index, view ); - - // if the set item is the current item, update the zoombox - if( index == this.Zoombox.CurrentViewIndex ) - { - this.Zoombox.RefocusView(); - } - } - - private static ZoomboxView GetViewFromSourceItem( object item ) - { - ZoomboxView view = ( item is ZoomboxView ) ? item as ZoomboxView : ZoomboxViewConverter.Converter.ConvertFrom( item ) as ZoomboxView; - if( view == null ) - throw new InvalidCastException( string.Format( ErrorMessages.GetMessage( "UnableToConvertToZoomboxView" ), item ) ); - - return view; - } - - private void InsertViews( int index, IList newItems ) - { - using( new SourceAccess( this ) ) - { - foreach( object item in newItems ) - { - ZoomboxView view = ZoomboxViewStack.GetViewFromSourceItem( item ); - if( index >= this.Count ) - { - this.Add( view ); - } - else - { - this.Insert( index, view ); - } - index++; - } - } - } - - private void MonitorSource( bool monitor ) - { - if( _source != null && ( _source is INotifyCollectionChanged ) ) - { - if( monitor ) - { - CollectionChangedEventManager.AddListener( _source as INotifyCollectionChanged, this ); - } - else - { - CollectionChangedEventManager.RemoveListener( _source as INotifyCollectionChanged, this ); - } - } - } - - private void MoveViews( int oldIndex, int newIndex, IList movedItems ) - { - using( new SourceAccess( this ) ) - { - int currentIndex = this.Zoombox.ViewStackIndex; - int indexAfterMove = currentIndex; - - // adjust the current index, if it was affected by the move - if( !( ( oldIndex < currentIndex && newIndex < currentIndex ) - || ( oldIndex > currentIndex && newIndex > currentIndex ) ) ) - { - if( currentIndex >= oldIndex && currentIndex < oldIndex + movedItems.Count ) - { - indexAfterMove += newIndex - oldIndex; - } - else if( currentIndex >= newIndex ) - { - indexAfterMove += movedItems.Count; - } - } - - this.IsMovingViews = true; - try - { - for( int i = 0; i < movedItems.Count; i++ ) - { - this.RemoveAt( oldIndex ); - } - for( int i = 0; i < movedItems.Count; i++ ) - { - this.Insert( newIndex + i, ZoomboxViewStack.GetViewFromSourceItem( movedItems[ i ] ) ); - } - if( indexAfterMove != currentIndex ) - { - this.Zoombox.ViewStackIndex = indexAfterMove; - this.Zoombox.SetCurrentViewIndex( indexAfterMove ); - } - } - finally - { - this.IsMovingViews = false; - } - } - } - - private void OnSourceCollectionChanged( object sender, NotifyCollectionChangedEventArgs e ) - { - switch( e.Action ) - { - case NotifyCollectionChangedAction.Add: - this.InsertViews( e.NewStartingIndex, e.NewItems ); - break; - - case NotifyCollectionChangedAction.Move: - this.MoveViews( e.OldStartingIndex, e.NewStartingIndex, e.OldItems ); - break; - - case NotifyCollectionChangedAction.Remove: - this.RemoveViews( e.OldStartingIndex, e.OldItems ); - break; - - case NotifyCollectionChangedAction.Replace: - this.ResetViews(); - break; - - case NotifyCollectionChangedAction.Reset: - this.ResetViews(); - break; - } - } - - private void ResetViews() - { - using( new SourceAccess( this ) ) - { - int currentIndex = this.Zoombox.ViewStackIndex; - this.IsResettingViews = true; - try - { - this.Clear(); - foreach( object item in _source ) - { - ZoomboxView view = ZoomboxViewStack.GetViewFromSourceItem( item ); - this.Add( view ); - } - - currentIndex = Math.Min( Math.Max( 0, currentIndex ), this.Count - 1 ); - - this.Zoombox.ViewStackIndex = currentIndex; - this.Zoombox.SetCurrentViewIndex( currentIndex ); - this.Zoombox.RefocusView(); - } - finally - { - this.IsResettingViews = false; - } - } - } - - private void RemoveViews( int index, IList removedItems ) - { - using( new SourceAccess( this ) ) - { - for( int i = 0; i < removedItems.Count; i++ ) - { - this.RemoveAt( index ); - } - } - } - - private void VerifyStackModification() - { - if( this.AreViewsFromSource && !this.IsChangeFromSource ) - throw new InvalidOperationException( ErrorMessages.GetMessage( "ViewStackCannotBeManipulatedNow" ) ); - } - - #region IWeakEventListener Members - - public bool ReceiveWeakEvent( Type managerType, object sender, EventArgs e ) - { - if( managerType == typeof( CollectionChangedEventManager ) ) - { - this.OnSourceCollectionChanged( sender, ( NotifyCollectionChangedEventArgs )e ); - } - else - { - return false; - } - - return true; - } - - #endregion - - #region Private Fields - - // to save memory, store bool variables in a bit vector - private BitVector32 _cacheBits = new BitVector32( 0 ); - - #endregion - - #region SourceAccess Nested Type - - private sealed class SourceAccess : IDisposable - { - public SourceAccess( ZoomboxViewStack viewStack ) - { - _viewStack = viewStack; - _viewStack.IsChangeFromSource = true; - } - - ~SourceAccess() - { - this.Dispose(); - } - - public void Dispose() - { - _viewStack.IsChangeFromSource = false; - _viewStack = null; - GC.SuppressFinalize( this ); - } - - private ZoomboxViewStack _viewStack; - } - - #endregion - - #region CacheBits Nested Type - - private enum CacheBits - { - AreViewsFromSource = 0x00000001, - IsChangeFromSource = 0x00000002, - IsResettingViews = 0x00000004, - IsMovingViews = 0x00000008, - IsSettingInitialViewAfterClear = 0x00000010, - } - - #endregion - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewStackMode.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewStackMode.cs deleted file mode 100644 index 707d2e86..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxViewStackMode.cs +++ /dev/null @@ -1,26 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -namespace Xceed.Wpf.Toolkit.Zoombox -{ - public enum ZoomboxViewStackMode - { - Auto, - Default, - Disabled, - Manual, - } -} diff --git a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxZoomOn.cs b/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxZoomOn.cs deleted file mode 100644 index 49c4e8f7..00000000 --- a/ExtendedWPFToolkitSolution/Src/Xceed.Wpf.Toolkit/Zoombox/ZoomboxZoomOn.cs +++ /dev/null @@ -1,24 +0,0 @@ -/************************************************************************************* - - Toolkit for WPF - - Copyright (C) 2007-2019 Xceed Software Inc. - - This program is provided to you under the terms of the Microsoft Public - License (Ms-PL) as published at https://github.com/xceedsoftware/wpftoolkit/blob/master/license.md - - For more features, controls, and fast professional support, - pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/ - - Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids - - ***********************************************************************************/ - -namespace Xceed.Wpf.Toolkit.Zoombox -{ - public enum ZoomboxZoomOn - { - Content = 1, - View, - } -}