58 changed files with 7281 additions and 1291 deletions
@ -0,0 +1,31 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
public enum AutoSelectBehavior |
|||
{ |
|||
Never, |
|||
OnFocus |
|||
} |
|||
} |
|||
@ -0,0 +1,301 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System.Windows.Controls; |
|||
using System.Windows.Input; |
|||
using System.Windows; |
|||
using System.Windows.Automation; |
|||
using Xceed.Wpf.Toolkit.Core.Utilities; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
public class AutoSelectTextBox : TextBox |
|||
{ |
|||
static AutoSelectTextBox() |
|||
{ |
|||
AutomationProperties.AutomationIdProperty.OverrideMetadata( typeof( AutoSelectTextBox ), new UIPropertyMetadata( "AutoSelectTextBox" ) ); |
|||
} |
|||
|
|||
#region AutoSelectBehavior PROPERTY
|
|||
|
|||
public AutoSelectBehavior AutoSelectBehavior |
|||
{ |
|||
get |
|||
{ |
|||
return ( AutoSelectBehavior )GetValue( AutoSelectBehaviorProperty ); |
|||
} |
|||
set |
|||
{ |
|||
SetValue( AutoSelectBehaviorProperty, value ); |
|||
} |
|||
} |
|||
|
|||
public static readonly DependencyProperty AutoSelectBehaviorProperty = |
|||
DependencyProperty.Register( "AutoSelectBehavior", typeof( AutoSelectBehavior ), typeof( AutoSelectTextBox ), |
|||
new UIPropertyMetadata( AutoSelectBehavior.Never ) ); |
|||
|
|||
#endregion AutoSelectBehavior PROPERTY
|
|||
|
|||
#region AutoMoveFocus PROPERTY
|
|||
|
|||
public bool AutoMoveFocus |
|||
{ |
|||
get |
|||
{ |
|||
return ( bool )GetValue( AutoMoveFocusProperty ); |
|||
} |
|||
set |
|||
{ |
|||
SetValue( AutoMoveFocusProperty, value ); |
|||
} |
|||
} |
|||
|
|||
public static readonly DependencyProperty AutoMoveFocusProperty = |
|||
DependencyProperty.Register( "AutoMoveFocus", typeof( bool ), typeof( AutoSelectTextBox ), new UIPropertyMetadata( false ) ); |
|||
|
|||
#endregion AutoMoveFocus PROPERTY
|
|||
|
|||
#region QueryMoveFocus EVENT
|
|||
|
|||
public static readonly RoutedEvent QueryMoveFocusEvent = EventManager.RegisterRoutedEvent( "QueryMoveFocus", |
|||
RoutingStrategy.Bubble, |
|||
typeof( QueryMoveFocusEventHandler ), |
|||
typeof( AutoSelectTextBox ) ); |
|||
#endregion QueryMoveFocus EVENT
|
|||
|
|||
protected override void OnPreviewKeyDown( KeyEventArgs e ) |
|||
{ |
|||
if( !this.AutoMoveFocus ) |
|||
{ |
|||
base.OnPreviewKeyDown( e ); |
|||
return; |
|||
} |
|||
|
|||
if( ( e.Key == Key.Left ) |
|||
&& ( ( Keyboard.Modifiers == ModifierKeys.None ) |
|||
|| ( Keyboard.Modifiers == ModifierKeys.Control ) ) ) |
|||
{ |
|||
e.Handled = this.MoveFocusLeft(); |
|||
} |
|||
|
|||
if( ( e.Key == Key.Right ) |
|||
&& ( ( Keyboard.Modifiers == ModifierKeys.None ) |
|||
|| ( Keyboard.Modifiers == ModifierKeys.Control ) ) ) |
|||
{ |
|||
e.Handled = this.MoveFocusRight(); |
|||
} |
|||
|
|||
if( ( ( e.Key == Key.Up ) || ( e.Key == Key.PageUp ) ) |
|||
&& ( ( Keyboard.Modifiers == ModifierKeys.None ) |
|||
|| ( Keyboard.Modifiers == ModifierKeys.Control ) ) ) |
|||
{ |
|||
e.Handled = this.MoveFocusUp(); |
|||
} |
|||
|
|||
if( ( ( e.Key == Key.Down ) || ( e.Key == Key.PageDown ) ) |
|||
&& ( ( Keyboard.Modifiers == ModifierKeys.None ) |
|||
|| ( Keyboard.Modifiers == ModifierKeys.Control ) ) ) |
|||
{ |
|||
e.Handled = this.MoveFocusDown(); |
|||
} |
|||
|
|||
base.OnPreviewKeyDown( e ); |
|||
} |
|||
|
|||
protected override void OnPreviewGotKeyboardFocus( KeyboardFocusChangedEventArgs e ) |
|||
{ |
|||
base.OnPreviewGotKeyboardFocus( e ); |
|||
|
|||
if( this.AutoSelectBehavior == AutoSelectBehavior.OnFocus ) |
|||
{ |
|||
// If the focus was not in one of our child ( or popup ), we select all the text.
|
|||
if( !TreeHelper.IsDescendantOf( e.OldFocus as DependencyObject, this ) ) |
|||
this.SelectAll(); |
|||
} |
|||
} |
|||
|
|||
protected override void OnPreviewMouseLeftButtonDown( MouseButtonEventArgs e ) |
|||
{ |
|||
base.OnPreviewMouseLeftButtonDown( e ); |
|||
|
|||
if( this.AutoSelectBehavior == AutoSelectBehavior.Never ) |
|||
return; |
|||
|
|||
if( this.IsKeyboardFocusWithin == false ) |
|||
{ |
|||
this.Focus(); |
|||
e.Handled = true; |
|||
} |
|||
} |
|||
|
|||
protected override void OnTextChanged( TextChangedEventArgs e ) |
|||
{ |
|||
base.OnTextChanged( e ); |
|||
|
|||
if( !this.AutoMoveFocus ) |
|||
return; |
|||
|
|||
if( ( this.Text.Length != 0 ) |
|||
&& ( this.Text.Length == this.MaxLength ) |
|||
&& ( this.CaretIndex == this.MaxLength ) ) |
|||
{ |
|||
if( this.CanMoveFocus( FocusNavigationDirection.Right, true ) == true ) |
|||
{ |
|||
FocusNavigationDirection direction = ( this.FlowDirection == FlowDirection.LeftToRight ) |
|||
? FocusNavigationDirection.Right |
|||
: FocusNavigationDirection.Left; |
|||
|
|||
this.MoveFocus( new TraversalRequest( direction ) ); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private bool CanMoveFocus( FocusNavigationDirection direction, bool reachedMax ) |
|||
{ |
|||
QueryMoveFocusEventArgs e = new QueryMoveFocusEventArgs( direction, reachedMax ); |
|||
this.RaiseEvent( e ); |
|||
return e.CanMoveFocus; |
|||
} |
|||
|
|||
private bool MoveFocusLeft() |
|||
{ |
|||
if( this.FlowDirection == FlowDirection.LeftToRight ) |
|||
{ |
|||
//occurs only if the cursor is at the beginning of the text
|
|||
if( ( this.CaretIndex == 0 ) && ( this.SelectionLength == 0 ) ) |
|||
{ |
|||
if( ComponentCommands.MoveFocusBack.CanExecute( null, this ) ) |
|||
{ |
|||
ComponentCommands.MoveFocusBack.Execute( null, this ); |
|||
return true; |
|||
} |
|||
else if( this.CanMoveFocus( FocusNavigationDirection.Left, false ) ) |
|||
{ |
|||
this.MoveFocus( new TraversalRequest( FocusNavigationDirection.Left ) ); |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
//occurs only if the cursor is at the end of the text
|
|||
if( ( this.CaretIndex == this.Text.Length ) && ( this.SelectionLength == 0 ) ) |
|||
{ |
|||
if( ComponentCommands.MoveFocusBack.CanExecute( null, this ) ) |
|||
{ |
|||
ComponentCommands.MoveFocusBack.Execute( null, this ); |
|||
return true; |
|||
} |
|||
else if( this.CanMoveFocus( FocusNavigationDirection.Left, false ) ) |
|||
{ |
|||
this.MoveFocus( new TraversalRequest( FocusNavigationDirection.Left ) ); |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
private bool MoveFocusRight() |
|||
{ |
|||
if( this.FlowDirection == FlowDirection.LeftToRight ) |
|||
{ |
|||
//occurs only if the cursor is at the beginning of the text
|
|||
if( ( this.CaretIndex == this.Text.Length ) && ( this.SelectionLength == 0 ) ) |
|||
{ |
|||
if( ComponentCommands.MoveFocusForward.CanExecute( null, this ) ) |
|||
{ |
|||
ComponentCommands.MoveFocusForward.Execute( null, this ); |
|||
return true; |
|||
} |
|||
else if( this.CanMoveFocus( FocusNavigationDirection.Right, false ) ) |
|||
{ |
|||
this.MoveFocus( new TraversalRequest( FocusNavigationDirection.Right ) ); |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
//occurs only if the cursor is at the end of the text
|
|||
if( ( this.CaretIndex == 0 ) && ( this.SelectionLength == 0 ) ) |
|||
{ |
|||
if( ComponentCommands.MoveFocusForward.CanExecute( null, this ) ) |
|||
{ |
|||
ComponentCommands.MoveFocusForward.Execute( null, this ); |
|||
return true; |
|||
} |
|||
else if( this.CanMoveFocus( FocusNavigationDirection.Right, false ) ) |
|||
{ |
|||
this.MoveFocus( new TraversalRequest( FocusNavigationDirection.Right ) ); |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
private bool MoveFocusUp() |
|||
{ |
|||
int lineNumber = this.GetLineIndexFromCharacterIndex( this.SelectionStart ); |
|||
|
|||
//occurs only if the cursor is on the first line
|
|||
if( lineNumber == 0 ) |
|||
{ |
|||
if( ComponentCommands.MoveFocusUp.CanExecute( null, this ) ) |
|||
{ |
|||
ComponentCommands.MoveFocusUp.Execute( null, this ); |
|||
return true; |
|||
} |
|||
else if( this.CanMoveFocus( FocusNavigationDirection.Up, false ) ) |
|||
{ |
|||
this.MoveFocus( new TraversalRequest( FocusNavigationDirection.Up ) ); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
private bool MoveFocusDown() |
|||
{ |
|||
int lineNumber = this.GetLineIndexFromCharacterIndex( this.SelectionStart ); |
|||
|
|||
//occurs only if the cursor is on the first line
|
|||
if( lineNumber == ( this.LineCount - 1 ) ) |
|||
{ |
|||
if( ComponentCommands.MoveFocusDown.CanExecute( null, this ) ) |
|||
{ |
|||
ComponentCommands.MoveFocusDown.Execute( null, this ); |
|||
return true; |
|||
} |
|||
else if( this.CanMoveFocus( FocusNavigationDirection.Down, false ) ) |
|||
{ |
|||
this.MoveFocus( new TraversalRequest( FocusNavigationDirection.Down ) ); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,76 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System.Windows; |
|||
using System.Windows.Input; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1003:UseGenericEventHandlerInstances" )] |
|||
public delegate void QueryMoveFocusEventHandler( object sender, QueryMoveFocusEventArgs e ); |
|||
|
|||
public class QueryMoveFocusEventArgs : RoutedEventArgs |
|||
{ |
|||
//default CTOR private to prevent its usage.
|
|||
private QueryMoveFocusEventArgs() |
|||
{ |
|||
} |
|||
|
|||
//internal to prevent anybody from building this type of event.
|
|||
internal QueryMoveFocusEventArgs( FocusNavigationDirection direction, bool reachedMaxLength ) |
|||
: base( AutoSelectTextBox.QueryMoveFocusEvent ) |
|||
{ |
|||
m_navigationDirection = direction; |
|||
m_reachedMaxLength = reachedMaxLength; |
|||
} |
|||
|
|||
public FocusNavigationDirection FocusNavigationDirection |
|||
{ |
|||
get |
|||
{ |
|||
return m_navigationDirection; |
|||
} |
|||
} |
|||
|
|||
public bool ReachedMaxLength |
|||
{ |
|||
get |
|||
{ |
|||
return m_reachedMaxLength; |
|||
} |
|||
} |
|||
|
|||
public bool CanMoveFocus |
|||
{ |
|||
get |
|||
{ |
|||
return m_canMove; |
|||
} |
|||
set |
|||
{ |
|||
m_canMove = value; |
|||
} |
|||
} |
|||
|
|||
private FocusNavigationDirection m_navigationDirection; |
|||
private bool m_reachedMaxLength; |
|||
private bool m_canMove = true; //defaults to true... if nobody does nothing, then its capable of moving focus.
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace Xceed.Wpf.Toolkit.Core.Input |
|||
{ |
|||
public interface IValidateInput |
|||
{ |
|||
event InputValidationErrorEventHandler InputValidationError; |
|||
void CommitInput(); |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
|
|||
namespace Xceed.Wpf.Toolkit.Core.Input |
|||
{ |
|||
public delegate void InputValidationErrorEventHandler( object sender, InputValidationErrorEventArgs e ); |
|||
|
|||
public class InputValidationErrorEventArgs : EventArgs |
|||
{ |
|||
public InputValidationErrorEventArgs( string errorMsg ) |
|||
{ |
|||
_errorMessage = errorMsg; |
|||
} |
|||
|
|||
public string ErrorMessage |
|||
{ |
|||
get |
|||
{ |
|||
return _errorMessage; |
|||
} |
|||
} |
|||
|
|||
private string _errorMessage; |
|||
} |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Windows.Controls; |
|||
|
|||
namespace Xceed.Wpf.Toolkit.Primitives |
|||
{ |
|||
internal class CachedTextInfo : ICloneable |
|||
{ |
|||
private CachedTextInfo( string text, int caretIndex, int selectionStart, int selectionLength ) |
|||
{ |
|||
this.Text = text; |
|||
this.CaretIndex = caretIndex; |
|||
this.SelectionStart = selectionStart; |
|||
this.SelectionLength = selectionLength; |
|||
} |
|||
|
|||
public CachedTextInfo( TextBox textBox ) |
|||
: this( textBox.Text, textBox.CaretIndex, textBox.SelectionStart, textBox.SelectionLength ) |
|||
{ |
|||
} |
|||
|
|||
public string Text { get; private set; } |
|||
public int CaretIndex { get; private set; } |
|||
public int SelectionStart { get; private set; } |
|||
public int SelectionLength { get; private set; } |
|||
|
|||
#region ICloneable Members
|
|||
|
|||
public object Clone() |
|||
{ |
|||
return new CachedTextInfo( this.Text, this.CaretIndex, this.SelectionStart, this.SelectionLength ); |
|||
} |
|||
|
|||
#endregion
|
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,57 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Xceed.Wpf.Toolkit.Core |
|||
{ |
|||
public class QueryTextFromValueEventArgs : EventArgs |
|||
{ |
|||
public QueryTextFromValueEventArgs( object value, string text ) |
|||
{ |
|||
m_value = value; |
|||
m_text = text; |
|||
} |
|||
|
|||
#region Value Property
|
|||
|
|||
private object m_value; |
|||
|
|||
public object Value |
|||
{ |
|||
get { return m_value; } |
|||
} |
|||
|
|||
#endregion Value Property
|
|||
|
|||
#region Text Property
|
|||
|
|||
private string m_text; |
|||
|
|||
public string Text |
|||
{ |
|||
get { return m_text; } |
|||
set { m_text = value; } |
|||
} |
|||
|
|||
#endregion Text Property
|
|||
} |
|||
} |
|||
@ -0,0 +1,70 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Xceed.Wpf.Toolkit.Core |
|||
{ |
|||
public class QueryValueFromTextEventArgs : EventArgs |
|||
{ |
|||
public QueryValueFromTextEventArgs( string text, object value ) |
|||
{ |
|||
m_text = text; |
|||
m_value = value; |
|||
} |
|||
|
|||
#region Text Property
|
|||
|
|||
private string m_text; |
|||
|
|||
public string Text |
|||
{ |
|||
get { return m_text; } |
|||
} |
|||
|
|||
#endregion Text Property
|
|||
|
|||
#region Value Property
|
|||
|
|||
private object m_value; |
|||
|
|||
public object Value |
|||
{ |
|||
get { return m_value; } |
|||
set { m_value = value; } |
|||
} |
|||
|
|||
#endregion Value Property
|
|||
|
|||
#region HasParsingError Property
|
|||
|
|||
private bool m_hasParsingError; |
|||
|
|||
public bool HasParsingError |
|||
{ |
|||
get { return m_hasParsingError; } |
|||
set { m_hasParsingError = value; } |
|||
} |
|||
|
|||
#endregion HasParsingError Property
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,163 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.ComponentModel; |
|||
using System.Diagnostics; |
|||
using System.Linq.Expressions; |
|||
|
|||
namespace Xceed.Wpf.Toolkit.Core.Utilities |
|||
{ |
|||
[DebuggerStepThrough] |
|||
internal sealed class NotifyPropertyChangedHelper |
|||
{ |
|||
#region Constructor
|
|||
|
|||
internal NotifyPropertyChangedHelper( |
|||
INotifyPropertyChanged owner, |
|||
Action<string> notifyPropertyChangedDelegate ) |
|||
{ |
|||
if( owner == null ) |
|||
throw new ArgumentNullException( "owner" ); |
|||
|
|||
if( notifyPropertyChangedDelegate == null ) |
|||
throw new ArgumentNullException( "notifyPropertyChangedDelegate" ); |
|||
|
|||
m_owner = owner; |
|||
m_delegate = notifyPropertyChangedDelegate; |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
internal static bool PropertyChanged( string propertyName, PropertyChangedEventArgs e, bool targetPropertyOnly ) |
|||
{ |
|||
string target = e.PropertyName; |
|||
if( target == propertyName ) |
|||
return true; |
|||
|
|||
return ( !targetPropertyOnly ) |
|||
&& ( string.IsNullOrEmpty( target ) ); |
|||
} |
|||
|
|||
internal static bool PropertyChanged<TOwner, TMember>( |
|||
Expression<Func<TMember>> expression, |
|||
PropertyChangedEventArgs e, |
|||
bool targetPropertyOnly ) |
|||
{ |
|||
var body = expression.Body as MemberExpression; |
|||
if( body == null ) |
|||
throw new ArgumentException( "The expression must target a property or field.", "expression" ); |
|||
|
|||
return NotifyPropertyChangedHelper.PropertyChanged( body, typeof( TOwner ), e, targetPropertyOnly ); |
|||
} |
|||
|
|||
internal static bool PropertyChanged<TOwner, TMember>( |
|||
Expression<Func<TOwner, TMember>> expression, |
|||
PropertyChangedEventArgs e, |
|||
bool targetPropertyOnly ) |
|||
{ |
|||
var body = expression.Body as MemberExpression; |
|||
if( body == null ) |
|||
throw new ArgumentException( "The expression must target a property or field.", "expression" ); |
|||
|
|||
return NotifyPropertyChangedHelper.PropertyChanged( body, typeof( TOwner ), e, targetPropertyOnly ); |
|||
} |
|||
|
|||
internal void RaisePropertyChanged( string propertyName ) |
|||
{ |
|||
ReflectionHelper.ValidatePropertyName( m_owner, propertyName ); |
|||
|
|||
this.InvokeDelegate( propertyName ); |
|||
} |
|||
|
|||
internal void RaisePropertyChanged<TMember>( Expression<Func<TMember>> expression ) |
|||
{ |
|||
if( expression == null ) |
|||
throw new ArgumentNullException( "expression" ); |
|||
|
|||
var body = expression.Body as MemberExpression; |
|||
if( body == null ) |
|||
throw new ArgumentException( "The expression must target a property or field.", "expression" ); |
|||
|
|||
var propertyName = NotifyPropertyChangedHelper.GetPropertyName( body, m_owner.GetType() ); |
|||
|
|||
this.InvokeDelegate( propertyName ); |
|||
} |
|||
|
|||
internal void HandleReferenceChanged<TMember>( Expression<Func<TMember>> expression, ref TMember localReference, TMember newValue ) where TMember : class |
|||
{ |
|||
if( localReference != newValue ) |
|||
{ |
|||
this.ExecutePropertyChanged( expression, ref localReference, newValue ); |
|||
} |
|||
} |
|||
|
|||
internal void HandleEqualityChanged<TMember>( Expression<Func<TMember>> expression, ref TMember localReference, TMember newValue ) |
|||
{ |
|||
if( !object.Equals( localReference, newValue ) ) |
|||
{ |
|||
this.ExecutePropertyChanged( expression, ref localReference, newValue ); |
|||
} |
|||
} |
|||
|
|||
private void ExecutePropertyChanged<TMember>( Expression<Func<TMember>> expression, ref TMember localReference, TMember newValue ) |
|||
{ |
|||
TMember oldValue = localReference; |
|||
localReference = newValue; |
|||
this.RaisePropertyChanged( expression ); |
|||
} |
|||
|
|||
internal static string GetPropertyName<TMember>( Expression<Func<TMember>> expression, Type ownerType ) |
|||
{ |
|||
var body = expression.Body as MemberExpression; |
|||
if( body == null ) |
|||
throw new ArgumentException( "The expression must target a property or field.", "expression" ); |
|||
|
|||
return NotifyPropertyChangedHelper.GetPropertyName( body, ownerType ); |
|||
} |
|||
|
|||
private static bool PropertyChanged( MemberExpression expression, Type ownerType, PropertyChangedEventArgs e, bool targetPropertyOnly ) |
|||
{ |
|||
var propertyName = NotifyPropertyChangedHelper.GetPropertyName( expression, ownerType ); |
|||
|
|||
return NotifyPropertyChangedHelper.PropertyChanged( propertyName, e, targetPropertyOnly ); |
|||
} |
|||
|
|||
private static string GetPropertyName( MemberExpression expression, Type ownerType ) |
|||
{ |
|||
var targetType = expression.Expression.Type; |
|||
if( !targetType.IsAssignableFrom( ownerType ) ) |
|||
throw new ArgumentException( "The expression must target a property or field on the appropriate owner.", "expression" ); |
|||
|
|||
return ReflectionHelper.GetPropertyOrFieldName( expression ); |
|||
} |
|||
|
|||
private void InvokeDelegate( string propertyName ) |
|||
{ |
|||
m_delegate.Invoke( propertyName ); |
|||
} |
|||
|
|||
#region Private Fields
|
|||
|
|||
private readonly INotifyPropertyChanged m_owner; |
|||
private readonly Action<string> m_delegate; |
|||
|
|||
#endregion
|
|||
} |
|||
} |
|||
@ -0,0 +1,136 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.ComponentModel; |
|||
using System.Diagnostics; |
|||
using System.Linq.Expressions; |
|||
using System.Reflection; |
|||
|
|||
namespace Xceed.Wpf.Toolkit.Core.Utilities |
|||
{ |
|||
internal static class ReflectionHelper |
|||
{ |
|||
/// <summary>
|
|||
/// Check the existence of the specified public instance (i.e. non static) property against
|
|||
/// the type of the specified source object. If the property is not defined by the type,
|
|||
/// a debug assertion will fail. Typically used to validate the parameter of a
|
|||
/// RaisePropertyChanged method.
|
|||
/// </summary>
|
|||
/// <param name="sourceObject">The object for which the type will be checked.</param>
|
|||
/// <param name="propertyName">The name of the property.</param>
|
|||
[System.Diagnostics.Conditional( "DEBUG" )] |
|||
internal static void ValidatePublicPropertyName( object sourceObject, string propertyName ) |
|||
{ |
|||
if( sourceObject == null ) |
|||
throw new ArgumentNullException( "sourceObject" ); |
|||
|
|||
if( propertyName == null ) |
|||
throw new ArgumentNullException( "propertyName" ); |
|||
|
|||
System.Diagnostics.Debug.Assert( sourceObject.GetType().GetProperty( propertyName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Public ) != null, |
|||
string.Format( "Public property {0} not found on object of type {1}.", propertyName, sourceObject.GetType().FullName ) ); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Check the existence of the specified instance (i.e. non static) property against
|
|||
/// the type of the specified source object. If the property is not defined by the type,
|
|||
/// a debug assertion will fail. Typically used to validate the parameter of a
|
|||
/// RaisePropertyChanged method.
|
|||
/// </summary>
|
|||
/// <param name="sourceObject">The object for which the type will be checked.</param>
|
|||
/// <param name="propertyName">The name of the property.</param>
|
|||
[System.Diagnostics.Conditional( "DEBUG" )] |
|||
internal static void ValidatePropertyName( object sourceObject, string propertyName ) |
|||
{ |
|||
if( sourceObject == null ) |
|||
throw new ArgumentNullException( "sourceObject" ); |
|||
|
|||
if( propertyName == null ) |
|||
throw new ArgumentNullException( "propertyName" ); |
|||
|
|||
System.Diagnostics.Debug.Assert( sourceObject.GetType().GetProperty( propertyName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic ) != null, |
|||
string.Format( "Public property {0} not found on object of type {1}.", propertyName, sourceObject.GetType().FullName ) ); |
|||
} |
|||
|
|||
internal static bool TryGetEnumDescriptionAttributeValue( Enum enumeration, out string description ) |
|||
{ |
|||
try |
|||
{ |
|||
FieldInfo fieldInfo = enumeration.GetType().GetField( enumeration.ToString() ); |
|||
DescriptionAttribute[] attributes = fieldInfo.GetCustomAttributes( typeof( DescriptionAttribute ), true ) as DescriptionAttribute[]; |
|||
if( ( attributes != null ) && ( attributes.Length > 0 ) ) |
|||
{ |
|||
description = attributes[ 0 ].Description; |
|||
return true; |
|||
} |
|||
} |
|||
catch |
|||
{ |
|||
} |
|||
|
|||
description = String.Empty; |
|||
return false; |
|||
} |
|||
|
|||
[DebuggerStepThrough] |
|||
internal static string GetPropertyOrFieldName( MemberExpression expression ) |
|||
{ |
|||
string propertyOrFieldName; |
|||
if( !ReflectionHelper.TryGetPropertyOrFieldName( expression, out propertyOrFieldName ) ) |
|||
throw new InvalidOperationException( "Unable to retrieve the property or field name." ); |
|||
|
|||
return propertyOrFieldName; |
|||
} |
|||
|
|||
[DebuggerStepThrough] |
|||
internal static string GetPropertyOrFieldName<TMember>( Expression<Func<TMember>> expression ) |
|||
{ |
|||
string propertyOrFieldName; |
|||
if( !ReflectionHelper.TryGetPropertyOrFieldName( expression, out propertyOrFieldName ) ) |
|||
throw new InvalidOperationException( "Unable to retrieve the property or field name." ); |
|||
|
|||
return propertyOrFieldName; |
|||
} |
|||
|
|||
[DebuggerStepThrough] |
|||
internal static bool TryGetPropertyOrFieldName( MemberExpression expression, out string propertyOrFieldName ) |
|||
{ |
|||
propertyOrFieldName = null; |
|||
|
|||
if( expression == null ) |
|||
return false; |
|||
|
|||
propertyOrFieldName = expression.Member.Name; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
[DebuggerStepThrough] |
|||
internal static bool TryGetPropertyOrFieldName<TMember>( Expression<Func<TMember>> expression, out string propertyOrFieldName ) |
|||
{ |
|||
propertyOrFieldName = null; |
|||
|
|||
if( expression == null ) |
|||
return false; |
|||
|
|||
return ReflectionHelper.TryGetPropertyOrFieldName( expression.Body as MemberExpression, out propertyOrFieldName ); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,238 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Windows; |
|||
using System.Windows.Media; |
|||
using System.Windows.Controls.Primitives; |
|||
|
|||
namespace Xceed.Wpf.Toolkit.Core.Utilities |
|||
{ |
|||
internal static class TreeHelper |
|||
{ |
|||
/// <summary>
|
|||
/// Tries its best to return the specified element's parent. It will
|
|||
/// try to find, in this order, the VisualParent, LogicalParent, LogicalTemplatedParent.
|
|||
/// It only works for Visual, FrameworkElement or FrameworkContentElement.
|
|||
/// </summary>
|
|||
/// <param name="element">The element to which to return the parent. It will only
|
|||
/// work if element is a Visual, a FrameworkElement or a FrameworkContentElement.</param>
|
|||
/// <remarks>If the logical parent is not found (Parent), we check the TemplatedParent
|
|||
/// (see FrameworkElement.Parent documentation). But, we never actually witnessed
|
|||
/// this situation.</remarks>
|
|||
public static DependencyObject GetParent( DependencyObject element ) |
|||
{ |
|||
return TreeHelper.GetParent( element, true ); |
|||
} |
|||
|
|||
private static DependencyObject GetParent( DependencyObject element, bool recurseIntoPopup ) |
|||
{ |
|||
if( recurseIntoPopup ) |
|||
{ |
|||
// Case 126732 : To correctly detect parent of a popup we must do that exception case
|
|||
Popup popup = element as Popup; |
|||
|
|||
if( ( popup != null ) && ( popup.PlacementTarget != null ) ) |
|||
return popup.PlacementTarget; |
|||
} |
|||
|
|||
Visual visual = element as Visual; |
|||
DependencyObject parent = ( visual == null ) ? null : VisualTreeHelper.GetParent( visual ); |
|||
|
|||
if( parent == null ) |
|||
{ |
|||
// No Visual parent. Check in the logical tree.
|
|||
FrameworkElement fe = element as FrameworkElement; |
|||
|
|||
if( fe != null ) |
|||
{ |
|||
parent = fe.Parent; |
|||
|
|||
if( parent == null ) |
|||
{ |
|||
parent = fe.TemplatedParent; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
FrameworkContentElement fce = element as FrameworkContentElement; |
|||
|
|||
if( fce != null ) |
|||
{ |
|||
parent = fce.Parent; |
|||
|
|||
if( parent == null ) |
|||
{ |
|||
parent = fce.TemplatedParent; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
return parent; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// This will search for a parent of the specified type.
|
|||
/// </summary>
|
|||
/// <typeparam name="T">The type of the element to find</typeparam>
|
|||
/// <param name="startingObject">The node where the search begins. This element is not checked.</param>
|
|||
/// <returns>Returns the found element. Null if nothing is found.</returns>
|
|||
public static T FindParent<T>( DependencyObject startingObject ) where T : DependencyObject |
|||
{ |
|||
return TreeHelper.FindParent<T>( startingObject, false, null ); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// This will search for a parent of the specified type.
|
|||
/// </summary>
|
|||
/// <typeparam name="T">The type of the element to find</typeparam>
|
|||
/// <param name="startingObject">The node where the search begins.</param>
|
|||
/// <param name="checkStartingObject">Should the specified startingObject be checked first.</param>
|
|||
/// <returns>Returns the found element. Null if nothing is found.</returns>
|
|||
public static T FindParent<T>( DependencyObject startingObject, bool checkStartingObject ) where T : DependencyObject |
|||
{ |
|||
return TreeHelper.FindParent<T>( startingObject, checkStartingObject, null ); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// This will search for a parent of the specified type.
|
|||
/// </summary>
|
|||
/// <typeparam name="T">The type of the element to find</typeparam>
|
|||
/// <param name="startingObject">The node where the search begins.</param>
|
|||
/// <param name="checkStartingObject">Should the specified startingObject be checked first.</param>
|
|||
/// <param name="additionalCheck">Provide a callback to check additional properties
|
|||
/// of the found elements. Can be left Null if no additional criteria are needed.</param>
|
|||
/// <returns>Returns the found element. Null if nothing is found.</returns>
|
|||
/// <example>Button button = TreeHelper.FindParent<Button>( this, foundChild => foundChild.Focusable );</example>
|
|||
public static T FindParent<T>( DependencyObject startingObject, bool checkStartingObject, Func<T, bool> additionalCheck ) where T : DependencyObject |
|||
{ |
|||
T foundElement; |
|||
DependencyObject parent = ( checkStartingObject ? startingObject : TreeHelper.GetParent( startingObject, true ) ); |
|||
|
|||
while( parent != null ) |
|||
{ |
|||
foundElement = parent as T; |
|||
|
|||
if( foundElement != null ) |
|||
{ |
|||
if( additionalCheck == null ) |
|||
{ |
|||
return foundElement; |
|||
} |
|||
else |
|||
{ |
|||
if( additionalCheck( foundElement ) ) |
|||
return foundElement; |
|||
} |
|||
} |
|||
|
|||
parent = TreeHelper.GetParent( parent, true ); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// This will search for a child of the specified type. The search is performed
|
|||
/// hierarchically, breadth first (as opposed to depth first).
|
|||
/// </summary>
|
|||
/// <typeparam name="T">The type of the element to find</typeparam>
|
|||
/// <param name="parent">The root of the tree to search for. This element itself is not checked.</param>
|
|||
/// <returns>Returns the found element. Null if nothing is found.</returns>
|
|||
public static T FindChild<T>( DependencyObject parent ) where T : DependencyObject |
|||
{ |
|||
return TreeHelper.FindChild<T>( parent, null ); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// This will search for a child of the specified type. The search is performed
|
|||
/// hierarchically, breadth first (as opposed to depth first).
|
|||
/// </summary>
|
|||
/// <typeparam name="T">The type of the element to find</typeparam>
|
|||
/// <param name="parent">The root of the tree to search for. This element itself is not checked.</param>
|
|||
/// <param name="additionalCheck">Provide a callback to check additional properties
|
|||
/// of the found elements. Can be left Null if no additional criteria are needed.</param>
|
|||
/// <returns>Returns the found element. Null if nothing is found.</returns>
|
|||
/// <example>Button button = TreeHelper.FindChild<Button>( this, foundChild => foundChild.Focusable );</example>
|
|||
public static T FindChild<T>( DependencyObject parent, Func<T, bool> additionalCheck ) where T : DependencyObject |
|||
{ |
|||
int childrenCount = VisualTreeHelper.GetChildrenCount( parent ); |
|||
T child; |
|||
|
|||
for( int index = 0; index < childrenCount; index++ ) |
|||
{ |
|||
child = VisualTreeHelper.GetChild( parent, index ) as T; |
|||
|
|||
if( child != null ) |
|||
{ |
|||
if( additionalCheck == null ) |
|||
{ |
|||
return child; |
|||
} |
|||
else |
|||
{ |
|||
if( additionalCheck( child ) ) |
|||
return child; |
|||
} |
|||
} |
|||
} |
|||
|
|||
for( int index = 0; index < childrenCount; index++ ) |
|||
{ |
|||
child = TreeHelper.FindChild<T>( VisualTreeHelper.GetChild( parent, index ), additionalCheck ); |
|||
|
|||
if( child != null ) |
|||
return child; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns true if the specified element is a child of parent somewhere in the visual
|
|||
/// tree. This method will work for Visual, FrameworkElement and FrameworkContentElement.
|
|||
/// </summary>
|
|||
/// <param name="element">The element that is potentially a child of the specified parent.</param>
|
|||
/// <param name="parent">The element that is potentially a parent of the specified element.</param>
|
|||
public static bool IsDescendantOf( DependencyObject element, DependencyObject parent ) |
|||
{ |
|||
return TreeHelper.IsDescendantOf( element, parent, true ); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns true if the specified element is a child of parent somewhere in the visual
|
|||
/// tree. This method will work for Visual, FrameworkElement and FrameworkContentElement.
|
|||
/// </summary>
|
|||
/// <param name="element">The element that is potentially a child of the specified parent.</param>
|
|||
/// <param name="parent">The element that is potentially a parent of the specified element.</param>
|
|||
public static bool IsDescendantOf( DependencyObject element, DependencyObject parent, bool recurseIntoPopup ) |
|||
{ |
|||
while( element != null ) |
|||
{ |
|||
if( element == parent ) |
|||
return true; |
|||
|
|||
element = TreeHelper.GetParent( element, recurseIntoPopup ); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,153 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Windows; |
|||
using System.Collections; |
|||
using System.Windows.Data; |
|||
|
|||
namespace Xceed.Wpf.Toolkit.Core.Utilities |
|||
{ |
|||
/// <summary>
|
|||
/// This helper class will raise events when a specific
|
|||
/// path value on one or many items changes.
|
|||
/// </summary>
|
|||
internal class ValueChangeHelper : DependencyObject |
|||
{ |
|||
|
|||
#region Value Property
|
|||
/// <summary>
|
|||
/// This private property serves as the target of a binding that monitors the value of the binding
|
|||
/// of each item in the source.
|
|||
/// </summary>
|
|||
private static readonly DependencyProperty ValueProperty = DependencyProperty.Register( "Value", typeof( object ), typeof( ValueChangeHelper ), new UIPropertyMetadata( null, OnValueChanged ) ); |
|||
private object Value |
|||
{ |
|||
get |
|||
{ |
|||
return ( object )GetValue( ValueProperty ); |
|||
} |
|||
set |
|||
{ |
|||
SetValue( ValueProperty, value ); |
|||
} |
|||
} |
|||
|
|||
private static void OnValueChanged( DependencyObject sender, DependencyPropertyChangedEventArgs args ) |
|||
{ |
|||
( ( ValueChangeHelper )sender ).RaiseValueChanged(); |
|||
} |
|||
#endregion
|
|||
|
|||
public event EventHandler ValueChanged; |
|||
|
|||
#region Constructor
|
|||
|
|||
public ValueChangeHelper(Action changeCallback) |
|||
{ |
|||
if( changeCallback == null ) |
|||
throw new ArgumentNullException( "changeCallback" ); |
|||
|
|||
this.ValueChanged += ( s, args ) => changeCallback(); |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region Methods
|
|||
|
|||
public void UpdateValueSource( object sourceItem, string path ) |
|||
{ |
|||
BindingBase binding = null; |
|||
if( sourceItem != null && path != null ) |
|||
{ |
|||
binding = new Binding( path ) { Source = sourceItem }; |
|||
} |
|||
|
|||
this.UpdateBinding( binding ); |
|||
} |
|||
|
|||
public void UpdateValueSource( IEnumerable sourceItems, string path ) |
|||
{ |
|||
BindingBase binding = null; |
|||
if( sourceItems != null && path != null ) |
|||
{ |
|||
MultiBinding multiBinding = new MultiBinding(); |
|||
multiBinding.Converter = new BlankMultiValueConverter(); |
|||
|
|||
foreach( var item in sourceItems ) |
|||
{ |
|||
multiBinding.Bindings.Add( new Binding( path ) { Source = item } ); |
|||
} |
|||
|
|||
binding = multiBinding; |
|||
} |
|||
|
|||
this.UpdateBinding( binding ); |
|||
} |
|||
|
|||
private void UpdateBinding( BindingBase binding ) |
|||
{ |
|||
if( binding != null ) |
|||
{ |
|||
BindingOperations.SetBinding( this, ValueChangeHelper.ValueProperty, binding ); |
|||
} |
|||
else |
|||
{ |
|||
this.ClearBinding(); |
|||
} |
|||
} |
|||
|
|||
private void ClearBinding() |
|||
{ |
|||
BindingOperations.ClearBinding( this, ValueChangeHelper.ValueProperty ); |
|||
} |
|||
|
|||
private void RaiseValueChanged() |
|||
{ |
|||
if( this.ValueChanged != null ) |
|||
{ |
|||
this.ValueChanged( this, EventArgs.Empty ); |
|||
} |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region BlankMultiValueConverter private class
|
|||
|
|||
private class BlankMultiValueConverter : IMultiValueConverter |
|||
{ |
|||
public object Convert( object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture ) |
|||
{ |
|||
// We will not use the result anyway. We just want the change notification to kick in.
|
|||
// Return a new object to have a different value.
|
|||
return new object(); |
|||
} |
|||
|
|||
public object[] ConvertBack( object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture ) |
|||
{ |
|||
throw new InvalidOperationException(); |
|||
} |
|||
} |
|||
|
|||
#endregion
|
|||
} |
|||
} |
|||
@ -0,0 +1,108 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using System.ComponentModel; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
public class AutoCompletingMaskEventArgs : CancelEventArgs |
|||
{ |
|||
public AutoCompletingMaskEventArgs( MaskedTextProvider maskedTextProvider, int startPosition, int selectionLength, string input ) |
|||
{ |
|||
m_autoCompleteStartPosition = -1; |
|||
|
|||
m_maskedTextProvider = maskedTextProvider; |
|||
m_startPosition = startPosition; |
|||
m_selectionLength = selectionLength; |
|||
m_input = input; |
|||
} |
|||
|
|||
#region MaskedTextProvider PROPERTY
|
|||
|
|||
private MaskedTextProvider m_maskedTextProvider; |
|||
|
|||
public MaskedTextProvider MaskedTextProvider |
|||
{ |
|||
get { return m_maskedTextProvider; } |
|||
} |
|||
|
|||
#endregion MaskedTextProvider PROPERTY
|
|||
|
|||
#region StartPosition PROPERTY
|
|||
|
|||
private int m_startPosition; |
|||
|
|||
public int StartPosition |
|||
{ |
|||
get { return m_startPosition; } |
|||
} |
|||
|
|||
#endregion StartPosition PROPERTY
|
|||
|
|||
#region SelectionLength PROPERTY
|
|||
|
|||
private int m_selectionLength; |
|||
|
|||
public int SelectionLength |
|||
{ |
|||
get { return m_selectionLength; } |
|||
} |
|||
|
|||
#endregion SelectionLength PROPERTY
|
|||
|
|||
#region Input PROPERTY
|
|||
|
|||
private string m_input; |
|||
|
|||
public string Input |
|||
{ |
|||
get { return m_input; } |
|||
} |
|||
|
|||
#endregion Input PROPERTY
|
|||
|
|||
|
|||
#region AutoCompleteStartPosition PROPERTY
|
|||
|
|||
private int m_autoCompleteStartPosition; |
|||
|
|||
public int AutoCompleteStartPosition |
|||
{ |
|||
get { return m_autoCompleteStartPosition; } |
|||
set { m_autoCompleteStartPosition = value; } |
|||
} |
|||
|
|||
#endregion AutoCompleteStartPosition PROPERTY
|
|||
|
|||
#region AutoCompleteText PROPERTY
|
|||
|
|||
private string m_autoCompleteText; |
|||
|
|||
public string AutoCompleteText |
|||
{ |
|||
get { return m_autoCompleteText; } |
|||
set { m_autoCompleteText = value; } |
|||
} |
|||
|
|||
#endregion AutoCompleteText PROPERTY
|
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
public enum InsertKeyMode |
|||
{ |
|||
Default = 0, |
|||
Insert = 1, |
|||
Overwrite = 2 |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
public enum MaskFormat |
|||
{ |
|||
ExcludePromptAndLiterals, |
|||
IncludeLiterals, |
|||
IncludePrompt, |
|||
IncludePromptAndLiterals |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,55 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Windows; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
public class ByteUpDown : CommonNumericUpDown<byte> |
|||
{ |
|||
#region Constructors
|
|||
|
|||
static ByteUpDown() |
|||
{ |
|||
UpdateMetadata( typeof( ByteUpDown ), default( byte ), ( byte )1, byte.MinValue, byte.MaxValue ); |
|||
} |
|||
|
|||
public ByteUpDown() |
|||
: base( Byte.Parse, Decimal.ToByte ) |
|||
{ |
|||
} |
|||
|
|||
#endregion //Constructors
|
|||
|
|||
#region Base Class Overrides
|
|||
|
|||
protected override byte IncrementValue( byte value, byte increment ) |
|||
{ |
|||
return ( byte )( value + increment ); |
|||
} |
|||
|
|||
protected override byte DecrementValue( byte value, byte increment ) |
|||
{ |
|||
return ( byte )( value - increment ); |
|||
} |
|||
|
|||
#endregion //Base Class Overrides
|
|||
} |
|||
} |
|||
@ -0,0 +1,184 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Windows; |
|||
using System.Globalization; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
public abstract class CommonNumericUpDown<T> : NumericUpDown<T?> where T : struct, IFormattable, IComparable<T> |
|||
{ |
|||
protected delegate T FromText( string s, NumberStyles style, IFormatProvider provider ); |
|||
protected delegate T FromDecimal( decimal d ); |
|||
|
|||
private FromText _fromText; |
|||
private FromDecimal _fromDecimal; |
|||
|
|||
protected CommonNumericUpDown( FromText fromText, FromDecimal fromDecimal ) |
|||
{ |
|||
if( fromText == null ) |
|||
throw new ArgumentNullException( "parseMethod" ); |
|||
|
|||
if( fromDecimal == null ) |
|||
throw new ArgumentNullException( "fromDecimal" ); |
|||
|
|||
_fromText = fromText; |
|||
_fromDecimal = fromDecimal; |
|||
} |
|||
|
|||
protected static void UpdateMetadata( Type type, T? defaultValue, T? increment, T? minValue, T? maxValue ) |
|||
{ |
|||
DefaultStyleKeyProperty.OverrideMetadata( type, new FrameworkPropertyMetadata( type ) ); |
|||
DefaultValueProperty.OverrideMetadata( type, new FrameworkPropertyMetadata( defaultValue ) ); |
|||
IncrementProperty.OverrideMetadata( type, new FrameworkPropertyMetadata( increment ) ); |
|||
MaximumProperty.OverrideMetadata( type, new FrameworkPropertyMetadata( maxValue ) ); |
|||
MinimumProperty.OverrideMetadata( type, new FrameworkPropertyMetadata( minValue ) ); |
|||
} |
|||
|
|||
private bool IsLowerThan( T? value1, T? value2 ) |
|||
{ |
|||
if( value1 == null || value2 == null ) |
|||
return false; |
|||
|
|||
return ( value1.Value.CompareTo( value2.Value ) < 0 ); |
|||
} |
|||
|
|||
private bool IsGreaterThan( T? value1, T? value2 ) |
|||
{ |
|||
if( value1 == null || value2 == null ) |
|||
return false; |
|||
|
|||
return ( value1.Value.CompareTo( value2.Value ) > 0 ); |
|||
} |
|||
|
|||
private bool HandleNullSpin() |
|||
{ |
|||
if( !Value.HasValue ) |
|||
{ |
|||
Value = DefaultValue; |
|||
return true; |
|||
} |
|||
else if( !Increment.HasValue ) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
private T? CoerceValue( T value ) |
|||
{ |
|||
if( IsLowerThan( value, Minimum ) ) |
|||
return Minimum; |
|||
else if( IsGreaterThan( value, Maximum ) ) |
|||
return Maximum; |
|||
else |
|||
return value; |
|||
} |
|||
|
|||
#region Base Class Overrides
|
|||
|
|||
|
|||
protected override object OnCoerceValue( object newValue ) |
|||
{ |
|||
ValidateMinMax( ( T? )newValue ); |
|||
|
|||
return newValue; |
|||
} |
|||
|
|||
|
|||
|
|||
protected override void OnIncrement() |
|||
{ |
|||
if( !HandleNullSpin() ) |
|||
{ |
|||
T result = IncrementValue( Value.Value, Increment.Value ); |
|||
Value = CoerceValue( result ); |
|||
} |
|||
} |
|||
|
|||
protected override void OnDecrement() |
|||
{ |
|||
if( !HandleNullSpin() ) |
|||
{ |
|||
T result = DecrementValue( Value.Value, Increment.Value ); |
|||
Value = CoerceValue( result ); |
|||
} |
|||
} |
|||
|
|||
protected override T? ConvertTextToValue( string text ) |
|||
{ |
|||
T? result = null; |
|||
|
|||
if( String.IsNullOrEmpty( text ) ) |
|||
return result; |
|||
|
|||
//don't know why someone would format a T as %, but just in case they do.
|
|||
result = FormatString.Contains( "P" ) |
|||
? _fromDecimal( ParsePercent( text, CultureInfo ) ) |
|||
: _fromText( text, NumberStyles.Any, CultureInfo ); |
|||
|
|||
ValidateMinMax( result ); |
|||
|
|||
return result; |
|||
} |
|||
|
|||
protected override string ConvertValueToText() |
|||
{ |
|||
if( Value == null ) |
|||
return string.Empty; |
|||
|
|||
return Value.Value.ToString( FormatString, CultureInfo ); |
|||
} |
|||
|
|||
protected override void SetValidSpinDirection() |
|||
{ |
|||
ValidSpinDirections validDirections = ValidSpinDirections.None; |
|||
|
|||
if( IsLowerThan( Value, Maximum ) || !Value.HasValue ) |
|||
validDirections = validDirections | ValidSpinDirections.Increase; |
|||
|
|||
if( IsGreaterThan( Value, Minimum ) || !Value.HasValue ) |
|||
validDirections = validDirections | ValidSpinDirections.Decrease; |
|||
|
|||
if( Spinner != null ) |
|||
Spinner.ValidSpinDirection = validDirections; |
|||
} |
|||
|
|||
private void ValidateMinMax( T? value ) |
|||
{ |
|||
if( IsLowerThan( value, Minimum ) ) |
|||
throw new ArgumentOutOfRangeException( "Minimum", String.Format( "Value must be greater than MinValue of {0}", Minimum ) ); |
|||
else if( IsGreaterThan( value, Maximum ) ) |
|||
throw new ArgumentOutOfRangeException( "Maximum", String.Format( "Value must be less than MaxValue of {0}", Maximum ) ); |
|||
} |
|||
|
|||
#endregion //Base Class Overrides
|
|||
|
|||
|
|||
#region Abstract Methods
|
|||
|
|||
protected abstract T IncrementValue( T value, T increment ); |
|||
|
|||
protected abstract T DecrementValue( T value, T increment ); |
|||
|
|||
#endregion
|
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Windows; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
public class LongUpDown : CommonNumericUpDown<long> |
|||
{ |
|||
#region Constructors
|
|||
|
|||
static LongUpDown() |
|||
{ |
|||
UpdateMetadata( typeof( LongUpDown ), default( long ), 1L, long.MinValue, long.MaxValue ); |
|||
} |
|||
|
|||
public LongUpDown() |
|||
: base( Int64.Parse, Decimal.ToInt64 ) |
|||
{ |
|||
} |
|||
|
|||
#endregion //Constructors
|
|||
|
|||
#region Base Class Overrides
|
|||
|
|||
protected override long IncrementValue( long value, long increment ) |
|||
{ |
|||
return value + increment; |
|||
} |
|||
|
|||
protected override long DecrementValue( long value, long increment ) |
|||
{ |
|||
return value - increment; |
|||
} |
|||
|
|||
#endregion //Base Class Overrides
|
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Windows; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
internal class SByteUpDown : CommonNumericUpDown<sbyte> |
|||
{ |
|||
#region Constructors
|
|||
|
|||
static SByteUpDown() |
|||
{ |
|||
UpdateMetadata( typeof( SByteUpDown ), default( sbyte ), ( sbyte )1, sbyte.MinValue, sbyte.MaxValue ); |
|||
} |
|||
|
|||
public SByteUpDown() |
|||
: base( sbyte.Parse, Decimal.ToSByte ) |
|||
{ |
|||
} |
|||
|
|||
#endregion //Constructors
|
|||
|
|||
#region Base Class Overrides
|
|||
|
|||
protected override sbyte IncrementValue( sbyte value, sbyte increment ) |
|||
{ |
|||
return ( sbyte )( value + increment ); |
|||
} |
|||
|
|||
protected override sbyte DecrementValue( sbyte value, sbyte increment ) |
|||
{ |
|||
return ( sbyte )( value - increment ); |
|||
} |
|||
|
|||
#endregion //Base Class Overrides
|
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Windows; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
public class ShortUpDown : CommonNumericUpDown<short> |
|||
{ |
|||
#region Constructors
|
|||
|
|||
static ShortUpDown() |
|||
{ |
|||
UpdateMetadata( typeof( ShortUpDown ), default( short ), ( short )1, short.MinValue, short.MaxValue ); |
|||
} |
|||
|
|||
public ShortUpDown() |
|||
: base( Int16.Parse, Decimal.ToInt16 ) |
|||
{ |
|||
} |
|||
|
|||
#endregion //Constructors
|
|||
|
|||
#region Base Class Overrides
|
|||
|
|||
protected override short IncrementValue( short value, short increment ) |
|||
{ |
|||
return ( short )( value + increment ); |
|||
} |
|||
|
|||
protected override short DecrementValue( short value, short increment ) |
|||
{ |
|||
return ( short )( value - increment ); |
|||
} |
|||
|
|||
#endregion //Base Class Overrides
|
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Windows; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
public class SingleUpDown : CommonNumericUpDown<float> |
|||
{ |
|||
#region Constructors
|
|||
|
|||
static SingleUpDown() |
|||
{ |
|||
UpdateMetadata( typeof( SingleUpDown ), default( float ), 1f, float.MinValue, float.MaxValue ); |
|||
} |
|||
|
|||
public SingleUpDown() |
|||
: base( Single.Parse, Decimal.ToSingle ) |
|||
{ |
|||
} |
|||
|
|||
#endregion //Constructors
|
|||
|
|||
#region Base Class Overrides
|
|||
|
|||
protected override float IncrementValue( float value, float increment ) |
|||
{ |
|||
return value + increment; |
|||
} |
|||
|
|||
protected override float DecrementValue( float value, float increment ) |
|||
{ |
|||
return value - increment; |
|||
} |
|||
|
|||
#endregion //Base Class Overrides
|
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Windows; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
internal class UIntegerUpDown : CommonNumericUpDown<uint> |
|||
{ |
|||
#region Constructors
|
|||
|
|||
static UIntegerUpDown() |
|||
{ |
|||
UpdateMetadata( typeof( UIntegerUpDown ), default( uint ), ( uint )1, uint.MinValue, uint.MaxValue ); |
|||
} |
|||
|
|||
public UIntegerUpDown() |
|||
: base( uint.Parse, Decimal.ToUInt32 ) |
|||
{ |
|||
} |
|||
|
|||
#endregion //Constructors
|
|||
|
|||
#region Base Class Overrides
|
|||
|
|||
protected override uint IncrementValue( uint value, uint increment ) |
|||
{ |
|||
return ( uint )( value + increment ); |
|||
} |
|||
|
|||
protected override uint DecrementValue( uint value, uint increment ) |
|||
{ |
|||
return ( uint )( value - increment ); |
|||
} |
|||
|
|||
#endregion //Base Class Overrides
|
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Windows; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
internal class ULongUpDown : CommonNumericUpDown<ulong> |
|||
{ |
|||
#region Constructors
|
|||
|
|||
static ULongUpDown() |
|||
{ |
|||
UpdateMetadata( typeof( ULongUpDown ), default( ulong ), ( ulong )1, ulong.MinValue, ulong.MaxValue ); |
|||
} |
|||
|
|||
public ULongUpDown() |
|||
: base( ulong.Parse, Decimal.ToUInt64 ) |
|||
{ |
|||
} |
|||
|
|||
#endregion //Constructors
|
|||
|
|||
#region Base Class Overrides
|
|||
|
|||
protected override ulong IncrementValue( ulong value, ulong increment ) |
|||
{ |
|||
return ( ulong )( value + increment ); |
|||
} |
|||
|
|||
protected override ulong DecrementValue( ulong value, ulong increment ) |
|||
{ |
|||
return ( ulong )( value - increment ); |
|||
} |
|||
|
|||
#endregion //Base Class Overrides
|
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Windows; |
|||
|
|||
namespace Xceed.Wpf.Toolkit |
|||
{ |
|||
internal class UShortUpDown : CommonNumericUpDown<ushort> |
|||
{ |
|||
#region Constructors
|
|||
|
|||
static UShortUpDown() |
|||
{ |
|||
UpdateMetadata( typeof( UShortUpDown ), default( ushort ), ( ushort )1, ushort.MinValue, ushort.MaxValue ); |
|||
} |
|||
|
|||
public UShortUpDown() |
|||
: base( ushort.Parse, Decimal.ToUInt16 ) |
|||
{ |
|||
} |
|||
|
|||
#endregion //Constructors
|
|||
|
|||
#region Base Class Overrides
|
|||
|
|||
protected override ushort IncrementValue( ushort value, ushort increment ) |
|||
{ |
|||
return ( ushort )( value + increment ); |
|||
} |
|||
|
|||
protected override ushort DecrementValue( ushort value, ushort increment ) |
|||
{ |
|||
return ( ushort )( value - increment ); |
|||
} |
|||
|
|||
#endregion //Base Class Overrides
|
|||
} |
|||
} |
|||
@ -0,0 +1,726 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.ComponentModel; |
|||
using System.Windows; |
|||
using System.Windows.Controls; |
|||
using System.Windows.Input; |
|||
|
|||
namespace Xceed.Wpf.Toolkit.Obselete |
|||
{ |
|||
[Obsolete("Legacy implementation of MaskedTextBox. Use Xceed.Wpf.Toolkit.MaskedTextBox instead", false)] |
|||
public class MaskedTextBox : TextBox |
|||
{ |
|||
#region Members
|
|||
|
|||
/// <summary>
|
|||
/// Flags if the Text and Value properties are in the process of being sync'd
|
|||
/// </summary>
|
|||
private bool _isSyncingTextAndValueProperties; |
|||
private bool _isInitialized; |
|||
private bool _convertExceptionOccurred = false; |
|||
|
|||
#endregion //Members
|
|||
|
|||
#region Properties
|
|||
|
|||
protected MaskedTextProvider MaskProvider |
|||
{ |
|||
get; |
|||
set; |
|||
} |
|||
|
|||
#region IncludePrompt
|
|||
|
|||
public static readonly DependencyProperty IncludePromptProperty = DependencyProperty.Register( "IncludePrompt", typeof( bool ), typeof( MaskedTextBox ), new UIPropertyMetadata( false, OnIncludePromptPropertyChanged ) ); |
|||
public bool IncludePrompt |
|||
{ |
|||
get |
|||
{ |
|||
return ( bool )GetValue( IncludePromptProperty ); |
|||
} |
|||
set |
|||
{ |
|||
SetValue( IncludePromptProperty, value ); |
|||
} |
|||
} |
|||
|
|||
private static void OnIncludePromptPropertyChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) |
|||
{ |
|||
MaskedTextBox maskedTextBox = o as MaskedTextBox; |
|||
if( maskedTextBox != null ) |
|||
maskedTextBox.OnIncludePromptChanged( ( bool )e.OldValue, ( bool )e.NewValue ); |
|||
} |
|||
|
|||
protected virtual void OnIncludePromptChanged( bool oldValue, bool newValue ) |
|||
{ |
|||
ResolveMaskProvider( Mask ); |
|||
} |
|||
|
|||
#endregion //IncludePrompt
|
|||
|
|||
#region IncludeLiterals
|
|||
|
|||
public static readonly DependencyProperty IncludeLiteralsProperty = DependencyProperty.Register( "IncludeLiterals", typeof( bool ), typeof( MaskedTextBox ), new UIPropertyMetadata( true, OnIncludeLiteralsPropertyChanged ) ); |
|||
public bool IncludeLiterals |
|||
{ |
|||
get |
|||
{ |
|||
return ( bool )GetValue( IncludeLiteralsProperty ); |
|||
} |
|||
set |
|||
{ |
|||
SetValue( IncludeLiteralsProperty, value ); |
|||
} |
|||
} |
|||
|
|||
private static void OnIncludeLiteralsPropertyChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) |
|||
{ |
|||
MaskedTextBox maskedTextBox = o as MaskedTextBox; |
|||
if( maskedTextBox != null ) |
|||
maskedTextBox.OnIncludeLiteralsChanged( ( bool )e.OldValue, ( bool )e.NewValue ); |
|||
} |
|||
|
|||
protected virtual void OnIncludeLiteralsChanged( bool oldValue, bool newValue ) |
|||
{ |
|||
ResolveMaskProvider( Mask ); |
|||
} |
|||
|
|||
#endregion //IncludeLiterals
|
|||
|
|||
#region Mask
|
|||
|
|||
public static readonly DependencyProperty MaskProperty = DependencyProperty.Register( "Mask", typeof( string ), typeof( MaskedTextBox ), new UIPropertyMetadata( "<>", OnMaskPropertyChanged ) ); |
|||
public string Mask |
|||
{ |
|||
get |
|||
{ |
|||
return ( string )GetValue( MaskProperty ); |
|||
} |
|||
set |
|||
{ |
|||
SetValue( MaskProperty, value ); |
|||
} |
|||
} |
|||
|
|||
private static void OnMaskPropertyChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) |
|||
{ |
|||
MaskedTextBox maskedTextBox = o as MaskedTextBox; |
|||
if( maskedTextBox != null ) |
|||
maskedTextBox.OnMaskChanged( ( string )e.OldValue, ( string )e.NewValue ); |
|||
} |
|||
|
|||
protected virtual void OnMaskChanged( string oldValue, string newValue ) |
|||
{ |
|||
ResolveMaskProvider( newValue ); |
|||
UpdateText( 0 ); |
|||
} |
|||
|
|||
#endregion //Mask
|
|||
|
|||
#region PromptChar
|
|||
|
|||
public static readonly DependencyProperty PromptCharProperty = DependencyProperty.Register( "PromptChar", typeof( char ), typeof( MaskedTextBox ), new UIPropertyMetadata( '_', OnPromptCharChanged ) ); |
|||
public char PromptChar |
|||
{ |
|||
get |
|||
{ |
|||
return ( char )GetValue( PromptCharProperty ); |
|||
} |
|||
set |
|||
{ |
|||
SetValue( PromptCharProperty, value ); |
|||
} |
|||
} |
|||
|
|||
private static void OnPromptCharChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) |
|||
{ |
|||
MaskedTextBox maskedTextBox = o as MaskedTextBox; |
|||
if( maskedTextBox != null ) |
|||
maskedTextBox.OnPromptCharChanged( ( char )e.OldValue, ( char )e.NewValue ); |
|||
} |
|||
|
|||
protected virtual void OnPromptCharChanged( char oldValue, char newValue ) |
|||
{ |
|||
ResolveMaskProvider( Mask ); |
|||
} |
|||
|
|||
#endregion //PromptChar
|
|||
|
|||
#region SelectAllOnGotFocus
|
|||
|
|||
public static readonly DependencyProperty SelectAllOnGotFocusProperty = DependencyProperty.Register( "SelectAllOnGotFocus", typeof( bool ), typeof( MaskedTextBox ), new PropertyMetadata( false ) ); |
|||
public bool SelectAllOnGotFocus |
|||
{ |
|||
get |
|||
{ |
|||
return ( bool )GetValue( SelectAllOnGotFocusProperty ); |
|||
} |
|||
set |
|||
{ |
|||
SetValue( SelectAllOnGotFocusProperty, value ); |
|||
} |
|||
} |
|||
|
|||
#endregion //SelectAllOnGotFocus
|
|||
|
|||
#region Text
|
|||
|
|||
private static void OnTextChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) |
|||
{ |
|||
MaskedTextBox inputBase = o as MaskedTextBox; |
|||
if( inputBase != null ) |
|||
inputBase.OnTextChanged( ( string )e.OldValue, ( string )e.NewValue ); |
|||
} |
|||
|
|||
protected virtual void OnTextChanged( string oldValue, string newValue ) |
|||
{ |
|||
if( _isInitialized ) |
|||
SyncTextAndValueProperties( MaskedTextBox.TextProperty, newValue ); |
|||
} |
|||
|
|||
#endregion //Text
|
|||
|
|||
#region Value
|
|||
|
|||
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register( "Value", typeof( object ), typeof( MaskedTextBox ), new FrameworkPropertyMetadata( null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValueChanged ) ); |
|||
public object Value |
|||
{ |
|||
get |
|||
{ |
|||
return ( object )GetValue( ValueProperty ); |
|||
} |
|||
set |
|||
{ |
|||
SetValue( ValueProperty, value ); |
|||
} |
|||
} |
|||
|
|||
private static void OnValueChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) |
|||
{ |
|||
MaskedTextBox maskedTextBox = o as MaskedTextBox; |
|||
if( maskedTextBox != null ) |
|||
maskedTextBox.OnValueChanged( ( object )e.OldValue, ( object )e.NewValue ); |
|||
} |
|||
|
|||
protected virtual void OnValueChanged( object oldValue, object newValue ) |
|||
{ |
|||
if( _isInitialized ) |
|||
SyncTextAndValueProperties( MaskedTextBox.ValueProperty, newValue ); |
|||
|
|||
RoutedPropertyChangedEventArgs<object> args = new RoutedPropertyChangedEventArgs<object>( oldValue, newValue ); |
|||
args.RoutedEvent = MaskedTextBox.ValueChangedEvent; |
|||
RaiseEvent( args ); |
|||
} |
|||
|
|||
#endregion //Value
|
|||
|
|||
#region ValueType
|
|||
|
|||
public static readonly DependencyProperty ValueTypeProperty = DependencyProperty.Register( "ValueType", typeof( Type ), typeof( MaskedTextBox ), new UIPropertyMetadata( typeof( String ), OnValueTypeChanged ) ); |
|||
public Type ValueType |
|||
{ |
|||
get |
|||
{ |
|||
return ( Type )GetValue( ValueTypeProperty ); |
|||
} |
|||
set |
|||
{ |
|||
SetValue( ValueTypeProperty, value ); |
|||
} |
|||
} |
|||
|
|||
private static void OnValueTypeChanged( DependencyObject o, DependencyPropertyChangedEventArgs e ) |
|||
{ |
|||
MaskedTextBox maskedTextBox = o as MaskedTextBox; |
|||
if( maskedTextBox != null ) |
|||
maskedTextBox.OnValueTypeChanged( ( Type )e.OldValue, ( Type )e.NewValue ); |
|||
} |
|||
|
|||
protected virtual void OnValueTypeChanged( Type oldValue, Type newValue ) |
|||
{ |
|||
if( _isInitialized ) |
|||
SyncTextAndValueProperties( MaskedTextBox.TextProperty, Text ); |
|||
} |
|||
|
|||
#endregion //ValueType
|
|||
|
|||
#endregion //Properties
|
|||
|
|||
#region Constructors
|
|||
|
|||
static MaskedTextBox() |
|||
{ |
|||
TextProperty.OverrideMetadata( typeof( MaskedTextBox ), new FrameworkPropertyMetadata( OnTextChanged ) ); |
|||
} |
|||
|
|||
public MaskedTextBox() |
|||
{ |
|||
CommandBindings.Add( new CommandBinding( ApplicationCommands.Paste, Paste ) ); //handle paste
|
|||
CommandBindings.Add( new CommandBinding( ApplicationCommands.Cut, null, CanCut ) ); //surpress cut
|
|||
} |
|||
|
|||
#endregion //Constructors
|
|||
|
|||
#region Base Class Overrides
|
|||
|
|||
public override void OnApplyTemplate() |
|||
{ |
|||
base.OnApplyTemplate(); |
|||
|
|||
ResolveMaskProvider( Mask ); |
|||
UpdateText( 0 ); |
|||
} |
|||
|
|||
protected override void OnInitialized( EventArgs e ) |
|||
{ |
|||
base.OnInitialized( e ); |
|||
|
|||
if( !_isInitialized ) |
|||
{ |
|||
_isInitialized = true; |
|||
SyncTextAndValueProperties( ValueProperty, Value ); |
|||
} |
|||
} |
|||
|
|||
protected override void OnGotKeyboardFocus( KeyboardFocusChangedEventArgs e ) |
|||
{ |
|||
if( SelectAllOnGotFocus ) |
|||
{ |
|||
SelectAll(); |
|||
} |
|||
|
|||
base.OnGotKeyboardFocus( e ); |
|||
} |
|||
|
|||
protected override void OnPreviewKeyDown( KeyEventArgs e ) |
|||
{ |
|||
if( !e.Handled ) |
|||
{ |
|||
HandlePreviewKeyDown( e ); |
|||
} |
|||
|
|||
base.OnPreviewKeyDown( e ); |
|||
} |
|||
|
|||
protected override void OnPreviewTextInput( TextCompositionEventArgs e ) |
|||
{ |
|||
if( !e.Handled ) |
|||
{ |
|||
HandlePreviewTextInput( e ); |
|||
} |
|||
|
|||
base.OnPreviewTextInput( e ); |
|||
} |
|||
|
|||
#endregion //Base Class Overrides
|
|||
|
|||
#region Events
|
|||
|
|||
public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent( "ValueChanged", RoutingStrategy.Bubble, typeof( RoutedPropertyChangedEventHandler<object> ), typeof( MaskedTextBox ) ); |
|||
public event RoutedPropertyChangedEventHandler<object> ValueChanged |
|||
{ |
|||
add |
|||
{ |
|||
AddHandler( ValueChangedEvent, value ); |
|||
} |
|||
remove |
|||
{ |
|||
RemoveHandler( ValueChangedEvent, value ); |
|||
} |
|||
} |
|||
|
|||
#endregion //Events
|
|||
|
|||
#region Methods
|
|||
|
|||
#region Private
|
|||
|
|||
private void UpdateText() |
|||
{ |
|||
UpdateText( SelectionStart ); |
|||
} |
|||
|
|||
private void UpdateText( int position ) |
|||
{ |
|||
MaskedTextProvider provider = MaskProvider; |
|||
if( provider == null ) |
|||
throw new InvalidOperationException(); |
|||
|
|||
Text = provider.ToDisplayString(); |
|||
SelectionLength = 0; |
|||
SelectionStart = position; |
|||
} |
|||
|
|||
private int GetNextCharacterPosition( int startPosition ) |
|||
{ |
|||
int position = MaskProvider.FindEditPositionFrom( startPosition, true ); |
|||
return position == -1 ? startPosition : position; |
|||
} |
|||
|
|||
private void ResolveMaskProvider( string mask ) |
|||
{ |
|||
//do not create a mask provider if the Mask is empty, which can occur if the IncludePrompt and IncludeLiterals properties
|
|||
//are set prior to the Mask.
|
|||
if( String.IsNullOrEmpty( mask ) ) |
|||
return; |
|||
|
|||
MaskProvider = new MaskedTextProvider( mask ) |
|||
{ |
|||
IncludePrompt = this.IncludePrompt, |
|||
IncludeLiterals = this.IncludeLiterals, |
|||
PromptChar = this.PromptChar, |
|||
ResetOnSpace = false //should make this a property
|
|||
}; |
|||
} |
|||
|
|||
private object ConvertTextToValue( string text ) |
|||
{ |
|||
object convertedValue = null; |
|||
|
|||
Type dataType = ValueType; |
|||
|
|||
string valueToConvert = MaskProvider.ToString().Trim(); |
|||
|
|||
try |
|||
{ |
|||
if( valueToConvert.GetType() == dataType || dataType.IsInstanceOfType( valueToConvert ) ) |
|||
{ |
|||
convertedValue = valueToConvert; |
|||
} |
|||
#if !VS2008
|
|||
else if( String.IsNullOrWhiteSpace( valueToConvert ) ) |
|||
{ |
|||
convertedValue = Activator.CreateInstance( dataType ); |
|||
} |
|||
#else
|
|||
else if ( String.IsNullOrEmpty( valueToConvert ) ) |
|||
{ |
|||
convertedValue = Activator.CreateInstance( dataType ); |
|||
} |
|||
#endif
|
|||
else if( null == convertedValue && valueToConvert is IConvertible ) |
|||
{ |
|||
convertedValue = Convert.ChangeType( valueToConvert, dataType ); |
|||
} |
|||
} |
|||
catch |
|||
{ |
|||
//if an excpetion occurs revert back to original value
|
|||
_convertExceptionOccurred = true; |
|||
return Value; |
|||
} |
|||
|
|||
return convertedValue; |
|||
} |
|||
|
|||
private string ConvertValueToText( object value ) |
|||
{ |
|||
if( value == null ) |
|||
value = string.Empty; |
|||
|
|||
if( _convertExceptionOccurred ) |
|||
{ |
|||
value = Value; |
|||
_convertExceptionOccurred = false; |
|||
} |
|||
|
|||
//I have only seen this occur while in Blend, but we need it here so the Blend designer doesn't crash.
|
|||
if( MaskProvider == null ) |
|||
return value.ToString(); |
|||
|
|||
MaskProvider.Set( value.ToString() ); |
|||
return MaskProvider.ToDisplayString(); |
|||
} |
|||
|
|||
private void SyncTextAndValueProperties( DependencyProperty p, object newValue ) |
|||
{ |
|||
//prevents recursive syncing properties
|
|||
if( _isSyncingTextAndValueProperties ) |
|||
return; |
|||
|
|||
_isSyncingTextAndValueProperties = true; |
|||
|
|||
//this only occures when the user typed in the value
|
|||
if( MaskedTextBox.TextProperty == p ) |
|||
{ |
|||
if( newValue != null ) |
|||
SetValue( MaskedTextBox.ValueProperty, ConvertTextToValue( newValue.ToString() ) ); |
|||
} |
|||
|
|||
SetValue( MaskedTextBox.TextProperty, ConvertValueToText( newValue ) ); |
|||
|
|||
_isSyncingTextAndValueProperties = false; |
|||
} |
|||
|
|||
private void HandlePreviewTextInput( TextCompositionEventArgs e ) |
|||
{ |
|||
if( !IsReadOnly ) |
|||
{ |
|||
this.InsertText( e.Text ); |
|||
} |
|||
|
|||
e.Handled = true; |
|||
} |
|||
|
|||
private void HandlePreviewKeyDown( KeyEventArgs e ) |
|||
{ |
|||
if( e.Key == Key.Delete ) |
|||
{ |
|||
e.Handled = IsReadOnly |
|||
|| HandleKeyDownDelete(); |
|||
} |
|||
else if( e.Key == Key.Back ) |
|||
{ |
|||
e.Handled = IsReadOnly |
|||
|| HandleKeyDownBack(); |
|||
} |
|||
else if( e.Key == Key.Space ) |
|||
{ |
|||
if( !IsReadOnly ) |
|||
{ |
|||
InsertText( " " ); |
|||
} |
|||
|
|||
e.Handled = true; |
|||
} |
|||
else if( e.Key == Key.Return || e.Key == Key.Enter ) |
|||
{ |
|||
if( !IsReadOnly && AcceptsReturn ) |
|||
{ |
|||
this.InsertText( "\r" ); |
|||
} |
|||
|
|||
// We don't want the OnPreviewTextInput to be triggered for the Return/Enter key
|
|||
// when it is not accepted.
|
|||
e.Handled = true; |
|||
} |
|||
else if( e.Key == Key.Escape ) |
|||
{ |
|||
// We don't want the OnPreviewTextInput to be triggered at all for the Escape key.
|
|||
e.Handled = true; |
|||
} |
|||
else if( e.Key == Key.Tab ) |
|||
{ |
|||
if( AcceptsTab ) |
|||
{ |
|||
if( !IsReadOnly ) |
|||
{ |
|||
this.InsertText( "\t" ); |
|||
} |
|||
|
|||
e.Handled = true; |
|||
} |
|||
} |
|||
} |
|||
|
|||
private bool HandleKeyDownDelete() |
|||
{ |
|||
ModifierKeys modifiers = Keyboard.Modifiers; |
|||
bool handled = true; |
|||
|
|||
if( modifiers == ModifierKeys.None ) |
|||
{ |
|||
if( !RemoveSelectedText() ) |
|||
{ |
|||
int position = SelectionStart; |
|||
|
|||
if( position < Text.Length ) |
|||
{ |
|||
RemoveText( position, 1 ); |
|||
UpdateText( position ); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
UpdateText(); |
|||
} |
|||
} |
|||
else if( modifiers == ModifierKeys.Control ) |
|||
{ |
|||
if( !RemoveSelectedText() ) |
|||
{ |
|||
int position = SelectionStart; |
|||
|
|||
RemoveTextToEnd( position ); |
|||
UpdateText( position ); |
|||
} |
|||
else |
|||
{ |
|||
UpdateText(); |
|||
} |
|||
} |
|||
else if( modifiers == ModifierKeys.Shift ) |
|||
{ |
|||
if( RemoveSelectedText() ) |
|||
{ |
|||
UpdateText(); |
|||
} |
|||
else |
|||
{ |
|||
handled = false; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
handled = false; |
|||
} |
|||
|
|||
return handled; |
|||
} |
|||
|
|||
private bool HandleKeyDownBack() |
|||
{ |
|||
ModifierKeys modifiers = Keyboard.Modifiers; |
|||
bool handled = true; |
|||
|
|||
if( modifiers == ModifierKeys.None || modifiers == ModifierKeys.Shift ) |
|||
{ |
|||
if( !RemoveSelectedText() ) |
|||
{ |
|||
int position = SelectionStart; |
|||
|
|||
if( position > 0 ) |
|||
{ |
|||
int newPosition = position - 1; |
|||
|
|||
RemoveText( newPosition, 1 ); |
|||
UpdateText( newPosition ); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
UpdateText(); |
|||
} |
|||
} |
|||
else if( modifiers == ModifierKeys.Control ) |
|||
{ |
|||
if( !RemoveSelectedText() ) |
|||
{ |
|||
RemoveTextFromStart( SelectionStart ); |
|||
UpdateText( 0 ); |
|||
} |
|||
else |
|||
{ |
|||
UpdateText(); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
handled = false; |
|||
} |
|||
|
|||
return handled; |
|||
} |
|||
|
|||
private void InsertText( string text ) |
|||
{ |
|||
int position = SelectionStart; |
|||
MaskedTextProvider provider = MaskProvider; |
|||
|
|||
bool textRemoved = this.RemoveSelectedText(); |
|||
|
|||
position = GetNextCharacterPosition( position ); |
|||
|
|||
if( !textRemoved && Keyboard.IsKeyToggled( Key.Insert ) ) |
|||
{ |
|||
if( provider.Replace( text, position ) ) |
|||
{ |
|||
position += text.Length; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if( provider.InsertAt( text, position ) ) |
|||
{ |
|||
position += text.Length; |
|||
} |
|||
} |
|||
|
|||
position = GetNextCharacterPosition( position ); |
|||
|
|||
this.UpdateText( position ); |
|||
} |
|||
|
|||
private void RemoveTextFromStart( int endPosition ) |
|||
{ |
|||
RemoveText( 0, endPosition ); |
|||
} |
|||
|
|||
private void RemoveTextToEnd( int startPosition ) |
|||
{ |
|||
RemoveText( startPosition, Text.Length - startPosition ); |
|||
} |
|||
|
|||
private void RemoveText( int position, int length ) |
|||
{ |
|||
if( length == 0 ) |
|||
return; |
|||
|
|||
MaskProvider.RemoveAt( position, position + length - 1 ); |
|||
} |
|||
|
|||
private bool RemoveSelectedText() |
|||
{ |
|||
int length = SelectionLength; |
|||
|
|||
if( length == 0 ) |
|||
return false; |
|||
|
|||
int position = SelectionStart; |
|||
|
|||
return MaskProvider.RemoveAt( position, position + length - 1 ); |
|||
} |
|||
|
|||
#endregion //Private
|
|||
|
|||
#endregion //Methods
|
|||
|
|||
#region Commands
|
|||
|
|||
private void Paste( object sender, RoutedEventArgs e ) |
|||
{ |
|||
if( IsReadOnly ) |
|||
return; |
|||
|
|||
object data = Clipboard.GetData( DataFormats.Text ); |
|||
if( data != null ) |
|||
{ |
|||
string text = data.ToString().Trim(); |
|||
if( text.Length > 0 ) |
|||
{ |
|||
int position = SelectionStart; |
|||
|
|||
MaskProvider.Set( text ); |
|||
|
|||
UpdateText( position ); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private void CanCut( object sender, CanExecuteRoutedEventArgs e ) |
|||
{ |
|||
e.CanExecute = false; |
|||
e.Handled = true; |
|||
} |
|||
|
|||
#endregion //Commands
|
|||
} |
|||
} |
|||
@ -0,0 +1,92 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
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'"; |
|||
#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 |
|||
{ |
|||
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(); |
|||
|
|||
DisplayNameAttribute displayNameAttribute = newType.GetCustomAttributes( false ).OfType<DisplayNameAttribute>().FirstOrDefault(); |
|||
|
|||
return (displayNameAttribute == null) |
|||
? newType.Name |
|||
: displayNameAttribute.DisplayName; |
|||
} |
|||
|
|||
public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture ) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
#endregion
|
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using Xceed.Wpf.Toolkit.Primitives; |
|||
using System; |
|||
namespace Xceed.Wpf.Toolkit.PropertyGrid.Editors |
|||
{ |
|||
public class UpDownEditor<TEditor, TType> : TypeEditor<TEditor> where TEditor : UpDownBase<TType>, new() |
|||
{ |
|||
protected override void SetControlProperties() |
|||
{ |
|||
Editor.BorderThickness = new System.Windows.Thickness( 0 ); |
|||
} |
|||
protected override void SetValueDependencyProperty() |
|||
{ |
|||
ValueProperty = UpDownBase<TType>.ValueProperty; |
|||
} |
|||
} |
|||
|
|||
public class ByteUpDownEditor : UpDownEditor<ByteUpDown, byte?> { } |
|||
|
|||
public class DecimalUpDownEditor : UpDownEditor<DecimalUpDown, decimal?> { } |
|||
|
|||
public class DoubleUpDownEditor : UpDownEditor<DoubleUpDown, double?> { } |
|||
|
|||
public class IntegerUpDownEditor : UpDownEditor<IntegerUpDown, int?> { } |
|||
|
|||
public class LongUpDownEditor : UpDownEditor<LongUpDown, long?> { } |
|||
|
|||
public class ShortUpDownEditor : UpDownEditor<ShortUpDown, short?> { } |
|||
|
|||
public class SingleUpDownEditor : UpDownEditor<SingleUpDown, float?> { } |
|||
|
|||
public class DateTimeUpDownEditor : UpDownEditor<DateTimeUpDown, DateTime?> { } |
|||
|
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
/************************************************************************ |
|||
|
|||
Extended WPF Toolkit |
|||
|
|||
Copyright (C) 2010-2012 Xceed Software Inc. |
|||
|
|||
This program is provided to you under the terms of the Microsoft Public |
|||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
|||
|
|||
This program can be provided to you by Xceed Software Inc. under a |
|||
proprietary commercial license agreement for use in non-Open Source |
|||
projects. The commercial version of Extended WPF Toolkit also includes |
|||
priority technical support, commercial updates, and many additional |
|||
useful WPF controls if you license Xceed Business Suite for WPF. |
|||
|
|||
Visit http://xceed.com and follow @datagrid on Twitter.
|
|||
|
|||
**********************************************************************/ |
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; |
|||
|
|||
namespace Xceed.Wpf.Toolkit.PropertyGrid |
|||
{ |
|||
internal interface IPropertyParent |
|||
{ |
|||
bool IsReadOnly { get; } |
|||
|
|||
object ValueInstance { get; } |
|||
|
|||
EditorDefinitionCollection EditorDefinitions { get; } |
|||
} |
|||
} |
|||
Loading…
Reference in new issue