4.8 KiB
4.8 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||||
|---|---|---|---|---|---|---|---|---|---|
|
2026-04-17T15:36:03.026612+00:00 | zai-org/GLM-5-FP8 | 1 | 36e847a660d89b00 |
DTS.Common.Behaviors Namespace Documentation
1. Purpose
This module provides a collection of WPF behaviors and utilities for the DTS application. It includes: StringMetaDataAttr for attaching string metadata to enums and objects via reflection; TrimTextBoxBehavior for automatically trimming whitespace from TextBox input on focus loss; InteractivityTemplate and InteractivityItems for attaching behaviors and triggers via data templates (enabling MVVM-friendly dynamic interactivity); TextBoxPasteBehavior for intercepting paste operations and routing them through custom ICommand implementations; and MultiSelectionBehavior for two-way synchronization between a ListBox's selected items and a bound collection, with special optimizations for bulk operations on specific collection types.
2. Public Interface
StringMetaDataAttr
public class StringMetaDataAttr : Attribute
{
public string MetaData { get; }
internal StringMetaDataAttr(string attr);
public static string GetStringMetaData(object o);
}
MetaDataproperty: Read-only string containing the metadata value.StringMetaDataAttr(string attr): Constructor markedinternal; cannot be instantiated from outside the assembly.GetStringMetaData(object o): Static method that retrieves theMetaDatavalue from aStringMetaDataAttrapplied to the member represented byo. Returnsnullif the object is null, has no matching member, or lacks the attribute.
TrimTextBoxBehavior
public class TrimTextBoxBehavior : Behavior<TextBox>
{
protected override void OnAttached();
protected override void OnDetaching();
}
OnAttached(): Subscribes toAssociatedObject.LostFocus.OnDetaching(): Unsubscribes fromAssociatedObject.LostFocus.- Behavior trims whitespace from
AssociatedObject.Texton focus loss and callsUpdateSource()on theTextBox.TextPropertybinding expression if the text changed.
InteractivityTemplate
public class InteractivityTemplate : DataTemplate
{
}
- Empty class inheriting from
DataTemplate. Serves as a marker/template type for interactivity.
InteractivityItems
public class InteractivityItems : FrameworkElement
{
public List<TriggerBase> Triggers { get; }
public List<Behavior> Behaviors { get; }
public static InteractivityTemplate GetTemplate(DependencyObject obj);
public static void SetTemplate(DependencyObject obj, InteractivityTemplate value);
public static readonly DependencyProperty TemplateProperty;
}
Triggers: Lazily-initialized list ofTriggerBaseobjects.Behaviors: Lazily-initialized list ofBehaviorobjects.GetTemplate(DependencyObject obj): Gets the attachedInteractivityTemplate.SetTemplate(DependencyObject obj, InteractivityTemplate value): Sets the attachedInteractivityTemplate.TemplateProperty: Attached property. When changed, loads the template content, casts toInteractivityItems, and copies all behaviors and triggers to the target element viaInteraction.GetBehaviors()andInteraction.GetTriggers().
TextBoxPasteBehavior
public class TextBoxPasteBehavior
{
public static readonly DependencyProperty PasteCommandProperty;
public static ICommand GetPasteCommand(DependencyObject target);
public static void SetPasteCommand(DependencyObject target, ICommand value);
}
PasteCommandProperty: Attached property of typeICommand.GetPasteCommand(DependencyObject target): Returns the attachedICommand.SetPasteCommand(DependencyObject target, ICommand value): Sets the attachedICommand. When set, registers or unregisters a handler forCommandManager.ExecutedEventon the target.- Internal handler
CommandExecutedchecks if the command isApplicationCommands.Pasteor aRoutedUICommandwith name "Paste". If so, retrieves clipboard text viaClipboard.GetText(), executes the attached command (passing the TextBox as parameter), and marks the event handled.
MultiSelectionBehavior
public class MultiSelectionBehavior : Behavior<ListBox>
{
public IList SelectedItems { get; set; }
public static readonly DependencyProperty SelectedItemsProperty;
protected override void OnAttached();
}
SelectedItems: Dependency property of typeIList.