7.8 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||||
|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T12:05:40.425898+00:00 | zai-org/GLM-5-FP8 | 1 | c0e1c8bd7f1a18f4 |
RibbonControl Module Documentation
1. Purpose
This module provides Prism region adapter infrastructure for integrating WPF Ribbon controls with the Prism navigation and region system. It enables dynamic addition and removal of RibbonTab and RibbonApplicationMenu items, synchronizes tab selection between document/workspace views and the Ribbon, and publishes selection change events through the Prism event aggregator for loose coupling between UI components.
2. Public Interface
RibbonControlSelectionChanged
Kind: Event class
Signature: public class RibbonControlSelectionChanged : CompositePresentationEvent<RibbonControlSelectionEventArgs>
Behavior: A Prism event used to broadcast when a Ribbon's selection has changed. Carries RibbonControlSelectionEventArgs payload indicating whether an item was added or removed.
RibbonControlOperation
Kind: Enumeration
Values:
AddedItem— Indicates an item was added to the controlRemovedItem— Indicates an item was removed from the control
Behavior: Used within RibbonControlSelectionEventArgs to describe the type of selection operation.
RibbonControlSelectionEventArgs
Kind: Event arguments class
Constructor: public RibbonControlSelectionEventArgs(RibbonControlOperation operation, object item)
Properties:
| Property | Type | Access |
|---|---|---|
Operation |
RibbonControlOperation |
get; (set via constructor) |
Item |
object |
get; (set via constructor) |
Behavior: Immutable payload carrying the operation type and the affected item for ribbon selection changes.
RibbonControlSelectionChangeBehavior
Kind: WPF Behavior (System.Windows.Interactivity.Behavior<Ribbon>)
Attached Property: public static readonly DependencyProperty TargetRibbonProperty
Properties:
| Property | Type | Access |
|---|---|---|
TargetRibbonControl |
Ribbon |
get; set; |
Methods:
protected override void OnAttached()— Subscribes toAssociatedObject.SelectionChanged; resolvesIEventAggregatorviaServiceLocator.Currentprotected override void OnDetaching()— Unsubscribes fromAssociatedObject.SelectionChangedvoid Ribbon_SelectionChanged(object sender, SelectionChangedEventArgs e)— PublishesRibbonControlSelectionChangedevents for each added/removed item
Behavior: When attached to a Ribbon, intercepts selection changes and publishes RibbonControlSelectionChanged events. Publishes separate events for added items (first item from AddedItems) and removed items (first item from RemovedItems).
RibbonRegionAdapter
Kind: Prism RegionAdapter (RegionAdapterBase<Ribbon>, IDisposable)
Constructor: public RibbonRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory, IRegionManager regionManager, IEventAggregator eventAggregator)
Methods:
| Method | Visibility | Description |
|---|---|---|
Adapt(IRegion region, Ribbon regionTarget) |
protected override |
Wires up ActiveViews.CollectionChanged to add/remove RibbonTab and RibbonApplicationMenu items |
CreateRegion() |
protected override |
Returns new AllActiveRegion instance |
OnTabControlSelectionChanged(TabControlSelectionEventArgs e) |
private |
Handles TabControlSelectionChanged events to sync Ribbon tab selection |
Dispose() |
public |
Unsubscribes from TabControlSelectionChanged event |
Behavior: Adapts a Ribbon control to a Prism region. Handles RibbonTab additions (with auto-generated Uid, TabIndex sorting, and optional default selection via config), RibbonApplicationMenu additions, and RibbonTab removals. Listens to TabControlSelectionChanged events to activate corresponding Ribbon tabs when views implementing IRibbonTabInfoProvider are activated.
3. Invariants
- Null Region Target:
Adapt()throwsArgumentNullExceptionifregionTargetis null. - Region Type:
CreateRegion()always returns a newAllActiveRegioninstance. - Uid Generation: If a
RibbonTaborRibbonApplicationMenuhas a null or emptyUid, one is auto-generated usingGuid.NewGuid().GetHashCode().ToString(CultureInfo.InvariantCulture). - Tab Sorting: All
RibbonTabitems added to the region are sorted byTabIndexin ascending order. - Single Item Publication:
RibbonControlSelectionChangeBehavior.Ribbon_SelectionChangedpublishes at most one event for added items (index 0) and one for removed items (index 0), regardless of how many items are in the collections. - Event Subscription Lifecycle:
RibbonRegionAdapterunsubscribes fromTabControlSelectionChangedon disposal.
4. Dependencies
This module depends on:
Microsoft.Practices.Prism.Events—CompositePresentationEvent,IEventAggregatorMicrosoft.Practices.Prism.Regions—RegionAdapterBase<T>,IRegion,IRegionBehaviorFactory,IRegionManager,AllActiveRegionMicrosoft.Practices.ServiceLocation—ServiceLocatorMicrosoft.Windows.Controls.Ribbon—Ribbon,RibbonTab,RibbonApplicationMenuSystem.Windows.Interactivity—Behavior<T>System.Configuration—ConfigurationManagerDTS.Common.Classes—IRibbonTabInfoProvider(referenced but not in source)DTS.Common.Enums—TabControlOperation(referenced but not in source)DTS.Common.Events—TabControlSelectionChangedevent class (referenced but not in source)DTS.Common.Base—IBaseViewinterface (referenced but not in source)
What depends on this module:
- Cannot be determined from source alone; consumers would reference
RibbonRegionAdapterin Prism bootstrapping/configuration and useRibbonControlSelectionChangedevent for cross-component communication.
5. Gotchas
-
Naming Inconsistency: The XML documentation comment in
RibbonControlSelectionEventArgs.csreferences "TabControlSelectionChanged" while the actual class isRibbonControlSelectionChanged. This may cause confusion. -
ServiceLocator vs Constructor Injection:
RibbonControlSelectionChangeBehaviorresolvesIEventAggregatorviaServiceLocator.Current.GetInstance<IEventAggregator>()(service locator pattern), whileRibbonRegionAdapterreceives it via constructor injection. This inconsistency may cause issues in testing or if service locator is not configured. -
Partial Lock Coverage:
AddRibbonTabToRegion()uses a lock object for thread safety when modifyingregionTarget.Items, butRemoveRibbonTabFromRibbonRegion()does not. This could lead to race conditions in multi-threaded scenarios. -
Case-Insensitive Comparison via ToLower(): The
DefaultRibbonTabconfiguration comparison usesToLower()on both sides rather than usingStringComparison.OrdinalIgnoreCase, which is the preferred .NET idiom. -
Only First Item Published: The behavior only publishes events for
e.AddedItems[0]ande.RemovedItems[0]. If multiple items are added/removed in a single selection change, subsequent items are silently ignored. -
External Interface Dependencies:
RibbonRegionAdapter.OnTabControlSelectionChanged()depends onIRibbonTabInfoProvider,IBaseView,TabControlSelectionChanged, andTabControlOperationwhich are not included in the provided source files. Their contracts are inferred but not documented here.