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 ByteEditBox ColorEditBox CornerRadiusEditBox DateTimeEditBox DoubleEditBox EnumEditBox GuidEditBox Int16EditBox Int32EditBox Int32RectEditBox Int64EditBox PointEditBox RectEditBox SingleEditBox SizeEditBox ThicknessEditBox TimeSpanEditBox VectorEditBox
Constructors
PartEditBoxBase()
Initializes an instance of the DateTimeEditBox
class.
protected PartEditBoxBase()
Properties
ActivePartIndex
Gets the index of the part that the caret is currently in.
public int ActivePartIndex { get; }
Property Value
- int:
The index of the part that the caret is currently in.
CommitTriggers
Gets or sets the triggers that will force this control to commit any changes.
public PartEditBoxCommitTriggers CommitTriggers { get; set; }
Property Value
- PartEditBoxCommitTriggers:
A PartEditBoxCommitTriggers indicating the triggers that will force this control to commit any changes. The default value is
PartEditBoxCommitTriggers.Default
.
CurrentSelectionLength
Gets the current text selection length.
protected int CurrentSelectionLength { get; }
Property Value
- int:
The current text selection length.
CurrentSelectionStartOffset
Gets the current text selection start offset.
protected int CurrentSelectionStartOffset { get; }
Property Value
- int:
The current text selection start offset.
CurrentText
Gets or sets the current text value in the TextBox
.
protected string CurrentText { get; set; }
Property Value
- string:
The current text value in the
TextBox
.
HasPopup
Gets or sets a value indicating whether the control has a popup available.
public bool HasPopup { get; set; }
Property Value
- bool:
true
if the control has a popup available; otherwisefalse
. The default value istrue
.
HasPopupButtonWhenReadOnly
Gets whether the control should display the popup button when the control is read-only.
protected virtual bool HasPopupButtonWhenReadOnly { get; }
Property Value
- bool:
true
if the control should display the popup button when the control is read-only; otherwise,false
.
Inlines
Gets or sets the collection of inline UI element placed within the control.
public PartEditBoxInlineCollection Inlines { get; set; }
Property Value
- PartEditBoxInlineCollection:
The collection of inline UI element placed within the control.
InputScopeNameValue
Gets or sets the InputScopeNameValue
to use for the editable text.
public InputScopeNameValue InputScopeNameValue { get; set; }
Property Value
- InputScopeNameValue:
The
InputScopeNameValue
to use for the editable text.
IntermediateValue
Gets the current value of the control, that stays in relative sync with the editable text representation.
public T IntermediateValue { get; }
Property Value
- T:
The current value of the control.
IsArrowKeyPartNavigationEnabled
Gets or sets a value indicating whether the left/right arrow keys can be used to move between and select editable parts.
public bool IsArrowKeyPartNavigationEnabled { get; set; }
Property Value
- bool:
true
if the left/right arrow keys can be used to move between and select editable parts; otherwisefalse
. The default value istrue
.
IsEditable
Gets or sets a value indicating whether the edit box's text area is editable.
public bool IsEditable { get; set; }
Property Value
- bool:
true
if the edit box's text area is editable; otherwisefalse
. The default value istrue
.
Remarks
When false
, the edit box behaves more like a ComboBox
.
IsNonDefaultUsageContext
Gets whether a non-default UsageContext is currently in effect.
public bool IsNonDefaultUsageContext { get; }
Property Value
- bool:
true
if a non-default UsageContext is currently in effect; otherwise,false
. The default value isfalse
.
IsNullAllowed
Gets or sets a value indicating whether null values are allowed to be entered by the user.
public bool IsNullAllowed { get; set; }
Property Value
- bool:
true
if null values are allowed to be entered by the user; otherwisefalse
. The default value isfalse
.
IsPopupButtonVisible
Gets whether the toggle popup button is visible.
public bool IsPopupButtonVisible { get; }
Property Value
- bool:
true
if 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
Gets or sets whether the popup is open.
public bool IsPopupOpen { get; set; }
Property Value
- bool:
true
if the popup is open; otherwise,false
.
IsReadOnly
Gets or sets a value indicating whether the edit box is read-only.
public bool IsReadOnly { get; set; }
Property Value
- bool:
true
if the edit box is read-only; otherwisefalse
. The default value isfalse
.
IsSpinnerVisible
Gets whether the spinner is visible.
public bool IsSpinnerVisible { get; }
Property Value
- bool:
true
if 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
Gets or sets whether undo/redo support is enabled for the text-editing portion of the control.
public bool IsUndoEnabled { get; set; }
Property Value
- bool:
true
if undo/redo support is enabled for the text-editing portion of the control. The default value istrue
.
Parts
Gets the collection of parts.
PlaceholderText
Gets or sets the text that is displayed in the control until the value is changed by a user action or some other operation.
public string PlaceholderText { get; set; }
Property Value
- string:
The text that is displayed in the control until the value is changed by a user action or some other operation.
PopupBackground
Gets or sets the Brush to use for the popup background.
public Brush PopupBackground { get; set; }
Property Value
PopupBorderBrush
Gets or sets the Brush to use for the popup border.
public Brush PopupBorderBrush { get; set; }
Property Value
PopupPickerStyle
Gets or sets the optional custom Style that can be applied to the picker within the popup.
public Style PopupPickerStyle { get; set; }
Property Value
ResetValueCommand
Gets the ICommand that resets the value to a default value.
public ICommand ResetValueCommand { get; }
Property Value
SmallDecrementValueCommand
Gets the ICommand that can be used to decrement the value by a small amount.
public ICommand SmallDecrementValueCommand { get; }
Property Value
SmallIncrementValueCommand
Gets the ICommand that can be used to increment the value by a small amount.
public ICommand SmallIncrementValueCommand { get; }
Property Value
SpinWrapping
Gets or sets 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 wrapping behavior used when spinning past a minimum or maximum value in the active part. The default value is
SpinWrapping.NoWrap
.
SpinnerVisibility
Gets or sets a value indicating 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
SpinnerVisibility.Collapsed
.
TextAlignment
Gets or sets the text alignment of the text editing area.
public TextAlignment TextAlignment { get; set; }
Property Value
- TextAlignment:
The text alignment of the text editing area. The default value is
TextAlignment.Left
.
UsageContext
Gets or sets the usage context of the control, which may alter its appearance.
public ControlUsageContext UsageContext { get; set; }
Property Value
- ControlUsageContext:
The usage context of the control, which may alter its appearance. The default value is
ControlUsageContext.Default
.
Value
Gets or sets the committed value of the control.
public T Value { get; set; }
Property Value
- T:
The committed value of the control.
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:
true
if 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()
IsValidValue(T)
Returns whether the specified value is valid.
protected abstract bool IsValidValue(T value)
Parameter | Type | Description |
---|---|---|
value | T | The value to examine. |
Returns
- bool:
true
if the value is valid; otherwise,false
.
OnApplyTemplate()
Invoked whenever application code or internal processes call ApplyTemplate
.
public override void OnApplyTemplate()
OnCreateAutomationPeer()
Returns an AutomationPeer object for this control instance.
protected override AutomationPeer OnCreateAutomationPeer()
Returns
- AutomationPeer:
An AutomationPeer instance.
OnGotFocus(RoutedEventArgs)
Occurs when the control gains focus.
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)
Reports that the IsKeyboardFocusWithin
property changed.
protected override void OnIsKeyboardFocusWithinChanged(DependencyPropertyChangedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | DependencyPropertyChangedEventArgs | A |
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)
Occurs when a key is pressed.
protected override void OnKeyDown(KeyEventArgs e)
Parameter | Type | Description |
---|---|---|
e | KeyEventArgs | The KeyEventArgs that contains the event data. |
OnLostFocus(RoutedEventArgs)
Occurs when the control loses focus.
protected override void OnLostFocus(RoutedEventArgs e)
Parameter | Type | Description |
---|---|---|
e | RoutedEventArgs | The RoutedEventArgs that contains the event data. |
OnLostMouseCapture(MouseEventArgs)
Occurs when mouse capture is lost.
protected override void OnLostMouseCapture(MouseEventArgs e)
Parameter | Type | Description |
---|---|---|
e | MouseEventArgs | The MouseEventArgs that contains the event data. |
OnMouseLeftButtonDown(MouseButtonEventArgs)
Occurs when a mouse button is pressed.
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
Parameter | Type | Description |
---|---|---|
e | MouseButtonEventArgs | The MouseButtonEventArgs that contains the event data. |
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)
Occurs when a mouse button is released.
protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
Parameter | Type | Description |
---|---|---|
e | MouseButtonEventArgs | The MouseButtonEventArgs that contains the event data. |
OnPreviewTextInput(TextCompositionEventArgs)
Occurs before text input is sent to the control.
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:
true
if the typed text was handled and should not be allowed to be entered; otherwise,false
.
RaiseValueChangedEvent()
Raises the ValueChanged
event.
protected abstract void RaiseValueChangedEvent()
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:
true
if 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:
true
if the CurrentText property was changed; otherwise,false
.
Fields
ActivePartIndexProperty
Identifies the ActivePartIndex dependency property. This field is read-only.
public static readonly DependencyProperty ActivePartIndexProperty
CommitTriggersProperty
Identifies the CommitTriggers dependency property. This field is read-only.
public static readonly DependencyProperty CommitTriggersProperty
HasPopupProperty
Identifies the HasPopup dependency property. This field is read-only.
public static readonly DependencyProperty HasPopupProperty
InlinesProperty
Identifies the Inlines dependency property. This field is read-only.
public static readonly DependencyProperty InlinesProperty
InputScopeNameValueProperty
Identifies the InputScopeNameValue dependency property. This field is read-only.
public static readonly DependencyProperty InputScopeNameValueProperty
IntermediateValueProperty
Identifies the IntermediateValue dependency property. This field is read-only.
public static readonly DependencyProperty IntermediateValueProperty
IsArrowKeyPartNavigationEnabledProperty
Identifies the IsArrowKeyPartNavigationEnabled dependency property. This field is read-only.
public static readonly DependencyProperty IsArrowKeyPartNavigationEnabledProperty
IsEditableProperty
Identifies the IsEditable dependency property. This field is read-only.
public static readonly DependencyProperty IsEditableProperty
IsNonDefaultUsageContextProperty
Identifies the IsNonDefaultUsageContext dependency property. This field is read-only.
public static readonly DependencyProperty IsNonDefaultUsageContextProperty
IsNullAllowedProperty
Identifies the IsNullAllowed dependency property. This field is read-only.
public static readonly DependencyProperty IsNullAllowedProperty
IsPopupButtonVisibleProperty
Identifies the IsPopupButtonVisible dependency property. This field is read-only.
public static readonly DependencyProperty IsPopupButtonVisibleProperty
IsPopupOpenProperty
Identifies the IsPopupOpen dependency property. This field is read-only.
public static readonly DependencyProperty IsPopupOpenProperty
IsReadOnlyProperty
Identifies the IsReadOnly dependency property. This field is read-only.
public static readonly DependencyProperty IsReadOnlyProperty
IsSpinnerVisibleProperty
Identifies the IsSpinnerVisible dependency property. This field is read-only.
public static readonly DependencyProperty IsSpinnerVisibleProperty
IsUndoEnabledProperty
Identifies the IsUndoEnabled dependency property. This field is read-only.
public static readonly DependencyProperty IsUndoEnabledProperty
PlaceholderTextProperty
Identifies the PlaceholderText dependency property. This field is read-only.
public static readonly DependencyProperty PlaceholderTextProperty
PopupBackgroundProperty
Identifies the PopupBackground dependency property. This field is read-only.
public static readonly DependencyProperty PopupBackgroundProperty
PopupBorderBrushProperty
Identifies the PopupBorderBrush dependency property. This field is read-only.
public static readonly DependencyProperty PopupBorderBrushProperty
PopupPickerStyleProperty
Identifies the PopupPickerStyle dependency property. This field is read-only.
public static readonly DependencyProperty PopupPickerStyleProperty
SpinWrappingProperty
Identifies the SpinWrapping dependency property. This field is read-only.
public static readonly DependencyProperty SpinWrappingProperty
SpinnerVisibilityProperty
Identifies the SpinnerVisibility dependency property. This field is read-only.
public static readonly DependencyProperty SpinnerVisibilityProperty
TextAlignmentProperty
Identifies the TextAlignment dependency property. This field is read-only.
public static readonly DependencyProperty TextAlignmentProperty
UsageContextProperty
Identifies the UsageContext dependency property. This field is read-only.
public static readonly DependencyProperty UsageContextProperty
ValueProperty
Identifies the Value dependency property. This field is read-only.
public static readonly DependencyProperty ValueProperty