PartEditBoxBase<T> Class
Represents the abstract base class for a part-based edit box.
[TemplatePart(Name = "PART_InlinePanel", Type = typeof(PartEditBoxInlinePanel))]
[TemplatePart(Name = "PART_Popup", Type = typeof(Popup))]
[TemplatePart(Name = "PART_TextBox", Type = typeof(EmbeddedTextBox))]
[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]
[TemplateVisualState(Name = "PointerOver", GroupName = "CommonStates")]
[TemplateVisualState(Name = "Focused", GroupName = "CommonStates")]
[TemplateVisualState(Name = "FocusedNonEditable", GroupName = "CommonStates")]
[TemplateVisualState(Name = "FocusedPopup", GroupName = "CommonStates")]
[TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")]
public abstract class PartEditBoxBase<T> : Control
- Type Parameters:
-
T-The type of value being edited.
- Inheritance:
- object Visual UIElement FrameworkElement Control object
- Derived:
- BrushEditBox ColorEditBox CornerRadiusEditBox DateTimeEditBox EnumEditBox GuidEditBox Int32RectEditBox PointEditBox NumberPartEditBoxBase<T> RectEditBox SizeEditBox ThicknessEditBox TimeSpanEditBox VectorEditBox
Constructors
PartEditBoxBase()
Initializes an instance of the class.
protected PartEditBoxBase()
Properties
ActivePartIndex
The index of the part that the caret is currently in.
CommitTriggers
The triggers that will force this control to commit any changes.
public PartEditBoxCommitTriggers CommitTriggers { get; set; }
Property Value
- PartEditBoxCommitTriggers:
The default value is Default>.
CurrentSelectionLength
The current text selection length.
CurrentSelectionStartOffset
The current text selection start offset.
CurrentText
The current text value in the TextBox.
HasPopup
Indicates whether the control has a popup available.
public bool HasPopup { get; set; }
Property Value
- bool:
trueif the control has a popup available; otherwisefalse. The default value istrue.
HasPopupButtonWhenReadOnly
Indicates whether the control should display the popup button when the control is read-only.
protected virtual bool HasPopupButtonWhenReadOnly { get; }
Property Value
- bool:
trueif the control should display the popup button when the control is read-only; otherwise,false.
Inlines
The collection of inline UI element placed within the control.
public PartEditBoxInlineCollection? Inlines { get; set; }
Property Value
InputScopeNameValue
The InputScopeNameValue to use for the editable text.
IntermediateValue
The current value of the control, that stays in relative sync with the editable text representation.
public T? IntermediateValue { get; }
Property Value
- T
IsArrowKeyPartNavigationEnabled
Indicates whether the left/right arrow keys can be used to move between and select editable parts.
public bool IsArrowKeyPartNavigationEnabled { get; set; }
Property Value
- bool:
trueif the left/right arrow keys can be used to move between and select editable parts; otherwisefalse. The default value istrue.
IsEditable
Indicates whether the edit box's text area is editable.
public bool IsEditable { get; set; }
Property Value
- bool:
trueif the edit box's text area is editable; otherwisefalse. The default value istrue.
Remarks
When false, the edit box behaves more like a ComboBox.
IsInputFilteringEnabled
Indicates whether input filtering is enabled. When enabled, only allowed characters can be input into the edit box.
public bool IsInputFilteringEnabled { get; set; }
Property Value
- bool:
trueif only allowed characters can be input into the edit box; otherwise,falseto allow all characters to be input. The default value isfalse.
Remarks
This property has no effect if the edit box is not configured with allowable characters.
IsNonDefaultUsageContext
Indicates whether a non-default UsageContext is currently in effect.
public bool IsNonDefaultUsageContext { get; }
Property Value
- bool:
trueif a non-default UsageContext is currently in effect; otherwise,false. The default value isfalse.
IsNullAllowed
Indicates whether null values are allowed to be entered by the user.
public bool IsNullAllowed { get; set; }
Property Value
- bool:
trueif null values are allowed to be entered by the user; otherwisefalse. The default value isfalse.
IsPopupButtonVisible
Indicates whether the toggle popup button is visible.
public bool IsPopupButtonVisible { get; }
Property Value
- bool:
trueif the toggle popup button is visible; otherwisefalse. The default value isfalse.
Remarks
The HasPopup and HasPopupButtonWhenReadOnly properties, and other state-related info determines whether the toggle popup button is visible.
IsPopupOpen
Indicates whether the popup is open.
public bool IsPopupOpen { get; set; }
Property Value
- bool:
trueif the popup is open; otherwise,false.
IsReadOnly
Indicates whether the edit box is read-only.
public bool IsReadOnly { get; set; }
Property Value
- bool:
trueif the edit box is read-only; otherwisefalse. The default value isfalse.
IsSpinnerVisible
Indicates whether the spinner is visible.
public bool IsSpinnerVisible { get; }
Property Value
- bool:
trueif the spinner is visible; otherwisefalse. The default value isfalse.
Remarks
The SpinnerVisibility property and other state-related info determines whether the spinner is visible.
IsUndoEnabled
Indicates whether undo/redo support is enabled for the text-editing portion of the control.
public bool IsUndoEnabled { get; set; }
Property Value
- bool:
trueif undo/redo support is enabled for the text-editing portion of the control. The default value istrue.
Parts
The collection of parts.
PlaceholderText
The text that is displayed in the control until the value is changed by a user action or some other operation.
PopupBackground
The Brush to use for the popup background.
PopupBorderBrush
The Brush to use for the popup border.
PopupPickerStyle
The optional custom Style that can be applied to the picker within the popup.
ResetValueCommand
The ICommand that resets the value to a default value.
SmallDecrementValueCommand
The ICommand that can be used to decrement the value by a small amount.
SmallIncrementValueCommand
The ICommand that can be used to increment the value by a small amount.
SpinWrapping
The wrapping behavior used when spinning past a minimum or maximum value in the active part.
public SpinWrapping SpinWrapping { get; set; }
Property Value
- SpinWrapping:
The default value is NoWrap.
SpinnerVisibility
Indicates if and when the control has a spinner available.
public SpinnerVisibility SpinnerVisibility { get; set; }
Property Value
- SpinnerVisibility:
A value indicating if and when the control has a spinner available. The default value is Collapsed.
TextAlignment
The text alignment of the text editing area.
public TextAlignment TextAlignment { get; set; }
Property Value
- TextAlignment:
The default value is
TextAlignment.Left.
UsageContext
The usage context of the control, which may alter its appearance.
public ControlUsageContext UsageContext { get; set; }
Property Value
- ControlUsageContext:
The default value is Default.
Value
The committed value of the control.
public T? Value { get; set; }
Property Value
- T
Methods
CoerceValidValue(T?)
Coerces the value to be within range.
protected virtual T? CoerceValidValue(T? value)
| Parameter | Type | Description |
|---|---|---|
| value | T | The value to coerce. |
Returns
- T:
The coerced value.
Commit()
Commits any pending text updates and returns whether the Value has been updated.
Commit(bool)
Commits any pending text updates and returns whether the Value has been updated.
public bool Commit(bool allowTextUpdate)
| Parameter | Type | Description |
|---|---|---|
| allowTextUpdate | bool | Whether to allow the text to be updated if a valid value is parsed. |
Returns
- bool:
trueif the value has been updated; otherwise,false.
ConvertToString(T?)
Converts the specified value to a string representation.
protected abstract string? ConvertToString(T? valueToConvert)
| Parameter | Type | Description |
|---|---|---|
| valueToConvert | T | The value. |
Returns
- string:
The string representation of the specified value.
CreateIncrementalChangeRequest(IncrementalChangeRequestKind)
Creates an incremental change (spin) request.
protected abstract IncrementalChangeRequest<T>? CreateIncrementalChangeRequest(IncrementalChangeRequestKind kind)
| Parameter | Type | Description |
|---|---|---|
| kind | IncrementalChangeRequestKind | The kind of request. |
Returns
- IncrementalChangeRequest<T>:
The incremental change (spin) request that was created.
GenerateParts()
Generates the parts for the edit box.
protected abstract IList<IPart> GenerateParts()
Returns
InvalidateParts()
Invalidates the parts.
protected void InvalidateParts()
IsTextInputAllowed(string)
Indicates whether the input text is allowed if text input filtering is enabled.
protected virtual bool IsTextInputAllowed(string text)
| Parameter | Type | Description |
|---|---|---|
| text | string | The text to examine. |
Returns
- bool:
trueif the text input is allowed; otherwise,false.
See Also
IsValidValue(T?)
Tests whether the specified value is valid.
protected abstract bool IsValidValue(T? value)
| Parameter | Type | Description |
|---|---|---|
| value | T | The value to examine. |
Returns
- bool:
trueif the value is valid; otherwise,false.
OnApplyTemplate()
When overridden in a derived class, is invoked whenever application code or internal processes call ApplyTemplate().
public override void OnApplyTemplate()
OnCreateAutomationPeer()
Returns class-specific AutomationPeer implementations for the Windows Presentation Foundation (WPF) infrastructure.
protected override AutomationPeer OnCreateAutomationPeer()
Returns
- AutomationPeer:
The type-specific AutomationPeer implementation.
OnGotFocus(RoutedEventArgs)
Invoked whenever an unhandled GotFocus event reaches this element in its route.
protected override void OnGotFocus(RoutedEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | RoutedEventArgs | The RoutedEventArgs that contains the event data. |
OnIntermediateValueChanged(T?, T?)
Invoked when the value of the IntermediateValue property changes.
protected virtual void OnIntermediateValueChanged(T? oldValue, T? newValue)
| Parameter | Type | Description |
|---|---|---|
| oldValue | T | The old value of the property. |
| newValue | T | The new value of the property. |
OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs)
Invoked just before the IsKeyboardFocusWithinChanged event is raised by this element. Implement this method to add class handling for this event.
protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | DependencyPropertyChangedEventArgs | A System.Windows.DependencyPropertyChangedEventArgs that contains the event data. |
OnIsNullAllowedChanged(bool, bool)
Invoked when the value of the IsNullAllowed property changes.
protected virtual void OnIsNullAllowedChanged(bool oldValue, bool newValue)
| Parameter | Type | Description |
|---|---|---|
| oldValue | bool | The old value of the property. |
| newValue | bool | The new value of the property. |
OnKeyDown(KeyEventArgs)
Invoked when an unhandled System.Windows.Input.Keyboard.KeyDown attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
protected override void OnKeyDown(KeyEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | KeyEventArgs | The KeyEventArgs that contains the event data. |
OnLostFocus(RoutedEventArgs)
Raises the LostFocus routed event by using the event data that is provided.
protected override void OnLostFocus(RoutedEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | RoutedEventArgs | A RoutedEventArgs that contains event data. This event data must contain the identifier for the LostFocus event. |
OnLostMouseCapture(MouseEventArgs)
Invoked when an unhandled System.Windows.Input.Mouse.LostMouseCapture attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
protected override void OnLostMouseCapture(MouseEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseEventArgs | The MouseEventArgs that contains event data. |
OnMouseLeftButtonDown(MouseButtonEventArgs)
Invoked when an unhandled MouseLeftButtonDown routed event is raised on this element. Implement this method to add class handling for this event.
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseButtonEventArgs | The MouseButtonEventArgs that contains the event data. The event data reports that the left mouse button was pressed. |
OnPopupOpened()
Occurs when the popup is opened.
protected virtual void OnPopupOpened()
Remarks
The default method implementation focuses the first popup descendant control with a tab stop.
OnPreviewMouseUp(MouseButtonEventArgs)
Invoked when an unhandled System.Windows.Input.Mouse.PreviewMouseUp attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | MouseButtonEventArgs | The MouseButtonEventArgs that contains the event data. The event data reports that one or more mouse buttons were released. |
OnPreviewTextInput(TextCompositionEventArgs)
Invoked when an unhandled System.Windows.Input.TextCompositionManager.PreviewTextInput attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
protected override void OnPreviewTextInput(TextCompositionEventArgs e)
| Parameter | Type | Description |
|---|---|---|
| e | TextCompositionEventArgs | The TextCompositionEventArgs that contains the event data. |
OnValueChanged(T?, T?)
Invoked when the value of the Value property changes.
protected virtual void OnValueChanged(T? oldValue, T? newValue)
| Parameter | Type | Description |
|---|---|---|
| oldValue | T | The old value of the property. |
| newValue | T | The new value of the property. |
ProcessTextInput(string)
Processes typed text.
protected virtual bool ProcessTextInput(string text)
| Parameter | Type | Description |
|---|---|---|
| text | string | The typed text. |
Returns
- bool:
trueif the typed text was handled and should not be allowed to be entered; otherwise,false.
ResetValue()
Resets the value to a default value.
protected abstract void ResetValue()
SelectAll()
Selects all text in the edit box.
public void SelectAll()
TryConvertFromString(string?, bool, out T?)
Tries to convert the specified text to a value.
protected abstract bool TryConvertFromString(string? textToConvert, bool canCoerce, out T? value)
| Parameter | Type | Description |
|---|---|---|
| textToConvert | string | The text. |
| canCoerce | bool | Whether the returned value should be coerced to fall within the allowed value range. |
| value | T | Returns the value for the specified text. |
Returns
- bool:
trueif the text was converted to a value successfully; otherwise,false.
UpdateIntermediateValueAndTextFromValue()
Updates the IntermediateValue and CurrentText properties from the Value.
protected bool UpdateIntermediateValueAndTextFromValue()
Returns
- bool:
trueif the CurrentText property was changed; otherwise,false.
Events
ValueChanged
Occurs after the Value property value changes.
Fields
ActivePartIndexProperty
Defines the ActivePartIndex property.
public static readonly DependencyProperty ActivePartIndexProperty
CommitTriggersProperty
Defines the CommitTriggers property.
public static readonly DependencyProperty CommitTriggersProperty
HasPopupProperty
Defines the HasPopup property.
public static readonly DependencyProperty HasPopupProperty
InlinesProperty
Defines the Inlines property.
public static readonly DependencyProperty InlinesProperty
InputScopeNameValueProperty
Defines the InputScopeNameValue property.
public static readonly DependencyProperty InputScopeNameValueProperty
IntermediateValueProperty
Defines the IntermediateValue property.
public static readonly DependencyProperty IntermediateValueProperty
IsArrowKeyPartNavigationEnabledProperty
Defines the IsArrowKeyPartNavigationEnabled property.
public static readonly DependencyProperty IsArrowKeyPartNavigationEnabledProperty
IsEditableProperty
Defines the IsEditable property.
public static readonly DependencyProperty IsEditableProperty
IsInputFilteringEnabledProperty
Defines the IsInputFilteringEnabled property.
public static readonly DependencyProperty IsInputFilteringEnabledProperty
IsNonDefaultUsageContextProperty
Defines the IsNonDefaultUsageContext property.
public static readonly DependencyProperty IsNonDefaultUsageContextProperty
IsNullAllowedProperty
Defines the IsNullAllowed property.
public static readonly DependencyProperty IsNullAllowedProperty
IsPopupButtonVisibleProperty
Defines the IsPopupButtonVisible property.
public static readonly DependencyProperty IsPopupButtonVisibleProperty
IsPopupOpenProperty
Defines the IsPopupOpen property.
public static readonly DependencyProperty IsPopupOpenProperty
IsReadOnlyProperty
Defines the IsReadOnly property.
public static readonly DependencyProperty IsReadOnlyProperty
IsSpinnerVisibleProperty
Defines the IsSpinnerVisible property.
public static readonly DependencyProperty IsSpinnerVisibleProperty
IsUndoEnabledProperty
Defines the IsUndoEnabled property.
public static readonly DependencyProperty IsUndoEnabledProperty
PlaceholderTextProperty
Defines the PlaceholderText property.
public static readonly DependencyProperty PlaceholderTextProperty
PopupBackgroundProperty
Defines the PopupBackground property.
public static readonly DependencyProperty PopupBackgroundProperty
PopupBorderBrushProperty
Defines the PopupBorderBrush property.
public static readonly DependencyProperty PopupBorderBrushProperty
PopupPickerStyleProperty
Defines the PopupPickerStyle property.
public static readonly DependencyProperty PopupPickerStyleProperty
SpinWrappingProperty
Defines the SpinWrapping property.
public static readonly DependencyProperty SpinWrappingProperty
SpinnerVisibilityProperty
Defines the SpinnerVisibility property.
public static readonly DependencyProperty SpinnerVisibilityProperty
TextAlignmentProperty
Defines the TextAlignment property.
public static readonly DependencyProperty TextAlignmentProperty
UsageContextProperty
Defines the UsageContext property.
public static readonly DependencyProperty UsageContextProperty
ValueProperty
Defines the Value property.
public static readonly DependencyProperty ValueProperty