5.5 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T13:48:16.790928+00:00 | zai-org/GLM-5-FP8 | 1 | 001b39a3411ec3ba |
Documentation: VirtualToggleButton
1. Purpose
VirtualToggleButton is a static helper class that provides attached dependency properties to imbue any WPF element with toggle button behavior. Rather than requiring inheritance from ToggleButton, this module allows arbitrary DependencyObject instances (specifically those implementing IInputElement) to respond to mouse clicks and keyboard input (Space/Enter) by toggling between checked, unchecked, and optionally indeterminate states. This is used within the DTS.Viewer.GraphList module to create toggle-style interactions on elements that cannot directly inherit from ToggleButton.
2. Public Interface
Attached Properties
IsLockedProperty
- Type:
DependencyProperty(attached) - Value Type:
Nullable<bool> - Default Value:
false - Metadata Flags:
BindsTwoWayByDefault | Journal - Get Accessor:
Nullable<bool> GetIsLocked(DependencyObject d) - Set Accessor:
void SetIsLocked(DependencyObject d, Nullable<bool> value) - Behavior: Represents the toggle state. When changed, raises
ToggleButton.CheckedEvent(iftrue),ToggleButton.UncheckedEvent(iffalse), orToggleButton.IndeterminateEvent(ifnull).
IsThreeStateProperty
- Type:
DependencyProperty(attached) - Value Type:
bool - Default Value:
false - Get Accessor:
bool GetIsThreeState(DependencyObject d) - Set Accessor:
void SetIsThreeState(DependencyObject d, bool value) - Behavior: When
true, allowsIsLockedto cycle throughnull(indeterminate) state during toggle operations.
IsVirtualToggleButtonProperty
- Type:
DependencyProperty(attached) - Value Type:
bool - Default Value:
false - Get Accessor:
bool GetIsVirtualToggleButton(DependencyObject d) - Set Accessor:
void SetIsVirtualToggleButton(DependencyObject d, bool value) - Behavior: When set to
trueon anIInputElement, subscribesOnMouseLeftButtonDownandOnKeyDownhandlers. When set tofalse, unsubscribes them.
Internal Methods
RaiseCheckedEvent(UIElement target)
- Returns:
RoutedEventArgsornullif target is null - Behavior: Raises
ToggleButton.CheckedEventon the target element.
RaiseUncheckedEvent(UIElement target)
- Returns:
RoutedEventArgsornullif target is null - Behavior: Raises
ToggleButton.UncheckedEventon the target element.
RaiseIndeterminateEvent(UIElement target)
- Returns:
RoutedEventArgsornullif target is null - Behavior: Raises
ToggleButton.IndeterminateEventon the target element.
3. Invariants
-
Input Handler Attachment: Setting
IsVirtualToggleButtontotrueon a non-IInputElementhas no effect (handlers are not attached, no exception is thrown). -
Toggle State Cycling Logic (in
UpdateIsLocked):- If
IsLocked == true: Sets tofalse, ornullifIsThreeStateistrue. - If
IsLocked == falseornull: Sets totrue.
- If
-
Keyboard Handling:
Spacekey toggles the state, unlessAltmodifier is present (system menu invocation is preserved).Enterkey toggles the state only ifKeyboardNavigation.AcceptsReturnPropertyistrueon the sender.
-
Event Routing: Raised events use
ToggleButton.CheckedEvent,ToggleButton.UncheckedEvent, andToggleButton.IndeterminateEventas routed event identifiers.
4. Dependencies
This Module Depends On:
SystemSystem.Windows(DependencyObject,DependencyProperty,FrameworkPropertyMetadata,UIElement,ContentElement,RoutedEventArgs,IInputElement)System.Windows.Controls.Primitives(ToggleButton)System.Windows.Input(Key,KeyEventArgs,Keyboard,KeyboardNavigation,ModifierKeys,MouseButtonEventArgs)
Consumers:
- Unclear from source alone. The class is in
DTS.Viewer.GraphListnamespace, suggesting consumption by GraphList-related components.
5. Gotchas
-
Misleading XML Documentation: The XML comments for
IsLockedstate "indicates whether the toggle button is checked" — this appears to be copy-pasted from a standardIsCheckedproperty. The property nameIsLockedsuggests a different semantic meaning (possibly "locked/selected" in the context of graph items). -
Type Inconsistency in Event Raising: The private
RaiseEventmethod supports bothUIElementandContentElement, but the internalRaiseCheckedEvent,RaiseUncheckedEvent, andRaiseIndeterminateEventmethods only acceptUIElement. If aContentElementneeds these events raised, the internal methods cannot be used directly. -
Namespace Suppression: The file contains
// ReSharper disable CheckNamespace, indicating the namespaceDTS.Viewer.GraphListmay not match the project's default namespace structure. This could indicate a refactoring artifact or intentional namespace override. -
No Null Guard in
UpdateIsLocked: The method castssender as DependencyObjectwithout null-checking before callingGetIsLocked(d). If called with a non-DependencyObjectsender, this would pass null toGetIsLocked, which would throw aNullReferenceExceptioninsided.GetValue(). -
Event Handled Flag: Both
OnMouseLeftButtonDownandOnKeyDownmark events ase.Handled = true, which may prevent bubbling to parent handlers unexpectedly.