7.4 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T03:24:21.475189+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 09c91cf175024b99 |
ViewModel
Documentation: RibbonViewModel<TModel>
1. Purpose
RibbonViewModel<TModel> is a base view model class for ribbon-based UI views in a Prism-based WPF application. It provides standardized initialization, cleanup, and command infrastructure (e.g., CloseCommand, ConfirmationRequest) for ribbon UI components, while integrating with Prism’s event aggregation (IEventAggregator), region management (IRegionManager), and dependency injection (IUnityContainer). It is designed to be subclassed to implement specific ribbon functionality, enforcing consistent lifecycle management (e.g., Initialize, Cleanup) and status reporting via the ShowStatus event.
2. Public Interface
Constructor
RibbonViewModel(IRibbonView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
Protected constructor; initializes dependencies and callsCreateCommands(). Not intended for direct instantiation—used by DI container to construct subclasses.
Properties
TModel Model { get; set; }
The data model associated with this view model. Set externally (e.g., via navigation parameters or dependency injection).IRibbonView View { get; }
Reference to the associated view (typically set by Prism’s view-first navigation).
Commands
InteractionRequest<Confirmation> ConfirmationRequest { get; }
Exposes an interaction request for displaying confirmation dialogs (e.g., “Are you sure?”). Subclasses raise this to prompt user confirmation.DelegateCommand<object> CloseCommand { get; }
Command to close the view/model. Execution triggersCloseMethod(), which callsCleanupAtClose()→Cleanup().
Virtual Methods
void Activated()
Called after the view model is activated (e.g., via Prism’sINavigationAware). Default implementation is a no-op; override for activation logic.void Initialize()
Publishes aShowStatusevent withStatusState.Busyand message"Loading"(fromStrings.Strings.Loading). Intended for synchronous initialization.void Initialize(object parameter)
Same asInitialize(), but accepts a parameter (currently unused beyond publishing the same busy status).void Initialize(object parameter, object model)
Empty implementation; no behavior defined.Task InitializeAsync()
Async version ofInitialize(); dispatches theShowStatusevent on the UI thread viaDispatcher.CurrentDispatcher.InvokeAsync.Task InitializeAsync(object parameter)
Async version ofInitialize(object parameter); same behavior as above.void Cleanup()
SetsModel = default(TModel). Override to perform additional cleanup (e.g., unsubscribe from events).Task CleanupAsync()
ReturnsTask.CompletedTask; no-op. Override for async cleanup logic.
Properties (Public)
bool IsMenuIncluded { get; set; }
Controls visibility of the menu section in the ribbon UI. Default:true. RaisesPropertyChangedon change.bool IsNavigationIncluded { get; set; }
Controls visibility of the navigation section in the ribbon UI. Default:false. RaisesPropertyChangedon change.int Percentage { get; set; }
Likely used for progress indication (no usage in source; no binding context defined).string IsBusyMessage { get; set; }
Stores a custom busy message (no usage in source; likely intended for UI binding).bool IsBusy { get; set; }
Indicates busy state (no usage in source; likely intended for UI binding).bool IsDirty { get; set; }
Indicates whether the model has unsaved changes (no usage in source; likely intended for UI binding).
Note
:
IsBusy,IsBusyMessage,Percentage, andIsDirtyare defined but not used in this class. Their purpose is inferred from naming but not implemented beyond storage.
3. Invariants
Modelmay benull(e.g., before initialization or afterCleanup()).Viewis set once during construction and never modified.ConfirmationRequestandCloseCommandare initialized inCreateCommands()and never reassigned.IsMenuIncludeddefaults totrue;IsNavigationIncludeddefaults tofalse.ShowStatusevents published duringInitialize*methods always useStatusState.Busyand"Loading"message.CloseCommandexecution always triggersCleanup()(synchronously), butCleanup()does not automatically close the view (no view reference is used to trigger closing).
4. Dependencies
Dependencies of RibbonViewModel<TModel>
- Prism Libraries:
Prism.Events.IEventAggregator(forShowStatusevent)Prism.Commands.DelegateCommand<T>(forCloseCommand)Prism.Regions.IRegionManager(dependency injection, not used directly in this class)Prism.Interactivity.InteractionRequest<Confirmation>(forConfirmationRequest)
- Unity Container:
IUnityContainer(for DI, not used directly in this class). - Custom Dependencies:
DTS.Common.Base.BasePropertyChanged(base class forINotifyPropertyChangedsupport)DTS.Common.Events.ShowStatus(event type for status updates)DTS.Common.Interactivity.Confirmation(type for confirmation dialogs)DTS.Common.RibbonControl.IRibbonView(view interface)DTS.Common.Strings.Strings(source of"Loading"string)
- System:
System.Threading.Tasks.Task,System.Windows.Threading.Dispatcher.
Dependencies on RibbonViewModel<TModel>
- Subclasses (e.g.,
RibbonViewModel<SomeModel>) are expected to be registered with Unity and used in Prism navigation. IRibbonViewimplementations likely depend on this view model via data context binding.
5. Gotchas
Initialize(object parameter, object model)is empty — no logic is implemented despite the signature suggesting model injection. Subclasses must override to handle model assignment.IsBusy,IsBusyMessage,Percentage, andIsDirtyare unused — they exist as properties but are never read/written by this class. Their purpose is unclear without downstream UI bindings.CloseCommanddoes not close the view — it only callsCleanup(). View closing must be handled externally (e.g., via Prism’sINavigationAware.OnNavigatedFrom()or view-specific logic).Dispatcher.CurrentDispatchermay be unsafe —InitializeAsyncusesDispatcher.CurrentDispatcher, which may not be the UI thread dispatcher in non-UI contexts (e.g., background tasks). PreferApplication.Current.Dispatcherif UI thread is guaranteed.- No validation on
Modelassignment —Modelcan be set to anyTModel(includingnull) without checks. Cleanup()is synchronous only —CleanupAsync()is a no-op stub. Async cleanup logic must be explicitly overridden.- No handling of
parameterinInitialize(object parameter)— the parameter is ignored despite being passed. Activated()is not called automatically — subclasses must ensure it is invoked (e.g., via Prism’sINavigationAware).
None identified beyond the above.