9.5 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||||
|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T12:04:47.328170+00:00 | zai-org/GLM-5-FP8 | 1 | c2b7aea8fc779731 |
DTS.Common.Behaviors Namespace Documentation
1. Purpose
This module provides a collection of WPF behaviors, attached properties, and utility attributes for the DTS CommonCore library. It enables declarative UI interactions through System.Windows.Interactivity, including text trimming on focus loss, multi-selection synchronization for ListBox controls, paste command handling for TextBox derivatives, and a mechanism for applying behaviors/triggers via data templates. It also provides a reflection-based attribute system for attaching string metadata to enum values and objects.
2. Public Interface
StringMetaDataAttr
Kind: Class (inherits Attribute)
Purpose: Stores string metadata on objects or enum members.
| Member | Signature | Description |
|---|---|---|
MetaData |
public string MetaData { get; } |
Read-only property containing the stored metadata string. |
GetStringMetaData |
public static string GetStringMetaData(object o) |
Retrieves the MetaData value from a StringMetaDataAttr applied to the object's member (typically enum values). Returns null if no attribute is found or if the object is null. |
Constructor: internal StringMetaDataAttr(string attr) — Internal constructor; attributes must be applied declaratively.
TrimTextBoxBehavior
Kind: Class (inherits Behavior<TextBox>)
Purpose: Automatically trims whitespace from a TextBox when it loses focus.
| Member | Signature | Description |
|---|---|---|
OnAttached |
protected override void OnAttached() |
Subscribes to AssociatedObject.LostFocus. |
OnDetaching |
protected override void OnDetaching() |
Unsubscribes from AssociatedObject.LostFocus. |
Behavior: On LostFocus, trims AssociatedObject.Text. If the trimmed value differs, updates the text and calls UpdateSource() on the TextBox.TextProperty binding expression.
InteractivityTemplate
Kind: Class (inherits DataTemplate)
Purpose: Marker class for defining interactivity templates in XAML resources. Contains no additional members.
InteractivityItems
Kind: Class (inherits FrameworkElement)
Purpose: Container for behaviors and triggers that can be loaded from an InteractivityTemplate.
| Member | Signature | Description |
|---|---|---|
Triggers |
public new List<TriggerBase> Triggers { get; } |
Lazy-initialized list of triggers. Hides inherited Triggers property. |
Behaviors |
public List<Behavior> Behaviors { get; } |
Lazy-initialized list of behaviors. |
TemplateProperty |
public static readonly DependencyProperty TemplateProperty |
Attached property for assigning an InteractivityTemplate to a DependencyObject. |
GetTemplate |
public static InteractivityTemplate GetTemplate(DependencyObject obj) |
Gets the attached Template property value. |
SetTemplate |
public static void SetTemplate(DependencyObject obj, InteractivityTemplate value) |
Sets the attached Template property value. |
Behavior: When TemplateProperty changes, loads InteractivityTemplate content, casts to InteractivityItems, and adds all behaviors/triggers to the target via Interaction.GetBehaviors() and Interaction.GetTriggers().
TextBoxPasteBehavior
Kind: Static class (attached property host)
Purpose: Enables handling paste operations via an ICommand binding on TextBox and custom controls.
| Member | Signature | Description |
|---|---|---|
PasteCommandProperty |
public static readonly DependencyProperty PasteCommandProperty |
Attached property of type ICommand. |
GetPasteCommand |
public static ICommand GetPasteCommand(DependencyObject target) |
Gets the attached PasteCommand. |
SetPasteCommand |
public static void SetPasteCommand(DependencyObject target, ICommand value) |
Sets the attached PasteCommand. |
Behavior: When PasteCommand is set, registers a handler for CommandManager.ExecutedEvent on the target TextBox. When a paste command (ApplicationCommands.Paste or a RoutedUICommand with Name == "Paste") is executed, retrieves clipboard text, splits by newlines, and executes the bound command with the TextBox as parameter. Errors are published via PageErrorEvent.
Special handling: Supports ChannelCodeBuilder and ChannelNameBuilder controls by extracting their MainEditBox property.
MultiSelectionBehavior
Kind: Class (inherits Behavior<ListBox>)
Purpose: Synchronizes a ListBox's SelectedItems collection with a bound IList source.
| Member | Signature | Description |
|---|---|---|
SelectedItems |
public IList SelectedItems { get; set; } |
Dependency property for binding the source collection. |
SelectedItemsProperty |
public static readonly DependencyProperty SelectedItemsProperty |
Backing field for SelectedItems. |
OnAttached |
protected override void OnAttached() |
Initializes AssociatedObject.SelectedItems from bound collection. |
Behavior:
- Two-way sync between
ListBox.SelectedItemsand boundIList. - Listens to
INotifyCollectionChanged.CollectionChangedon source. - Listens to
ListBox.SelectionChangedfor UI-driven changes. - Uses
SelectedItemsStatus.SetUpdating()to suppress notifications during bulk operations. - Type-checks added items against
selectedItems.GetType().GenericTypeArguments[0].
3. Invariants
-
StringMetaDataAttr: The
GetStringMetaDatamethod always returnsnullfor null objects or when no attribute is found. It assumeso.ToString()returns a valid member name. -
TrimTextBoxBehavior: Only updates the binding source when trimming actually changes the text (
trim != AssociatedObject.Text). -
InteractivityItems: The
TemplatePropertychange handler does nothing ife.NewValueisnull. -
TextBoxPasteBehavior:
- The paste handler only executes if
command.CanExecute(null)returnstrue. - The command receives the
TextBoxas its parameter, not the clipboard text. - Clipboard text is split by
Environment.NewLinebut the resultinglinesarray is not passed to the command.
- The paste handler only executes if
-
MultiSelectionBehavior:
- Uses
_isUpdatingTargetand_isUpdatingSourceflags to prevent recursive update loops. - Items are only added to
SelectedItemsif they passtype.IsAssignableFrom(item.GetType()). SelectedItemsStatus.SetUpdating(SelectedItems, false)is called before adding the last item in bulk additions.
- Uses
4. Dependencies
This module depends on:
System.Windows.Interactivity— Base classes for behaviors (Behavior<T>,TriggerBase,Interaction)System.Windows— WPF core types (DependencyObject,DependencyProperty,FrameworkElement,RoutedEventArgs)System.Windows.Controls—TextBox,ListBox,SelectionChangedEventArgsSystem.Windows.Input—ICommand,CommandManager,ApplicationCommands,ExecutedRoutedEventArgsDTS.Common.Controls—ChannelCodeBuilder,ChannelNameBuilder(referenced inTextBoxPasteBehavior)DTS.Common.Events—PageErrorEvent,PageErrorArg(used for error publishing)DTS.Common.Enums— Referenced inMultiSelectionBehavior(likely containsSelectedItemsStatus)DTS.Common.Utilities.Logging—APILogger.Log()for exception loggingMicrosoft.Practices.Prism.Events—IEventAggregatorMicrosoft.Practices.ServiceLocation—ServiceLocator
What depends on this module:
- Cannot be determined from source alone. Consumers would be XAML views or other modules applying these behaviors.
5. Gotchas
-
StringMetaDataAttr constructor is internal: You cannot instantiate this attribute programmatically; it must be applied declaratively at compile time.
-
TextBoxPasteBehavior clipboard handling: The clipboard text is retrieved and split into lines, but the
linesarray is never used—the command is executed with theTextBoxas the parameter. The split operation appears to be dead code. -
TextBoxPasteBehavior null check bug: In
CommandExecuted, the lineif (null == sender && sender is ChannelCodeBuilder ccb)is logically incorrect—it checks ifsenderis null AND is a specific type, which can never be true. This appears to be a copy-paste error; the intended check was likelyif (sender is ChannelCodeBuilder ccb). -
TextBoxPasteBehavior dependency on ServiceLocator: Uses service locator pattern to resolve
IEventAggregator, which is an anti-pattern and makes testing harder. -
MultiSelectionBehavior type checking: Assumes
SelectedItemsis a genericIList<T>when accessingGenericTypeArguments[0]. Will throwIndexOutOfRangeExceptionif bound to a non-genericIList. -
InteractivityItems.Triggers hides inherited member: The
newkeyword onTriggershidesFrameworkElement.Triggers. This could cause confusion if the property is accessed via aFrameworkElementreference. -
MultiSelectionBehavior Reset handling: When
NotifyCollectionChangedAction.Resetis received, clearsAssociatedObject.SelectedItemsbut does not re-populate from the source collection.