5.4 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T04:35:48.144608+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | b05fe9322ad19457 |
Converters
DbTypeToVisibilityConverter.cs Documentation
1. Purpose
This module provides a WPF IMultiValueConverter implementation (DbTypeToVisibilityConverter) used to dynamically control the visibility of UI elements (e.g., menu items, buttons, or status bar controls) in the DatabaseStatusBarView, based on the current database configuration and connection state. It translates the combination of a DbType value and the current view context into a Visibility enum (Visible or Collapsed), enabling UI elements to be conditionally shown only when relevant to the active database mode (e.g., remote-only, local-only, or hybrid with/without remote connection).
2. Public Interface
DbTypeToVisibilityConverter-
Implements:
System.Windows.Data.IMultiValueConverter -
Namespace:
DatabaseServices.Converters -
Inherits:
object -
object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)- Signature:
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) - Behavior: Converts a two-element input array (
values) into aVisibilityvalue:values[0]: Anintrepresenting aDbTypeenum value (cast toDbType).values[1]: ADatabaseStatusBarViewinstance (used to access itsDataContext, expected to be aDatabaseStatusBarViewModel).- Returns
Visibility.Visibleif thedbTypematches the visibility rules for the currentvm.DatabaseTypeandvm.RemoteConnectedstate; otherwise returnsVisibility.Collapsed. - If
view.DataContextisnull, returnsVisibility.Collapsed. - Throws no exceptions explicitly, but may throw
InvalidCastExceptionif inputs are not of expected types.
- Signature:
-
object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)- Signature:
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) - Behavior: Always throws
NotImplementedException. This converter is one-way only.
- Signature:
-
3. Invariants
valuesarray must contain exactly two elements:- Element 0: An
intthat can be safely cast toDbType. - Element 1: A
DatabaseStatusBarViewinstance (non-null).
- Element 0: An
view.DataContextmust be non-null and assignable toDatabaseStatusBarViewModel; otherwise, the converter returnsVisibility.Collapsed.- Visibility logic is strictly governed by the
DatabaseStatusBarViewModel.DatabaseTypeandDatabaseStatusBarViewModel.RemoteConnectedproperties:- For
RemoteOnly: OnlyDbType.RemoteOnlyis visible. - For
LocalOnly: OnlyDbType.LocalOnlyis visible. - For
RemoteLocalHybrid:- If
RemoteConnected == true: OnlyDbType.RemoteOnlyis visible. - If
RemoteConnected == false: OnlyDbType.RemoteLocalHybridis visible.
- If
- Any other
DatabaseTypevalue results inVisibility.Collapsed.
- For
- The converter is not intended for two-way binding (
ConvertBackis unimplemented).
4. Dependencies
-
Imports/References:
System,System.Globalization,System.Windows,System.Windows.Data(WPF core)DTS.Common.Enums.Database(external library/namespace) — providesDbTypeand likelyDatabaseStatusBarView/DatabaseStatusBarViewModel.
-
Assumed Dependencies (from usage context):
DatabaseStatusBarView: A WPFUserControlorWindowused in the status bar.DatabaseStatusBarViewModel: View model with properties:DatabaseType(DbType)RemoteConnected(bool)
DbTypeenum (fromDTS.Common.Enums.Database) — expected to include at least:RemoteOnly,LocalOnly,RemoteLocalHybrid.
-
Depended upon by:
- XAML bindings in
DatabaseStatusBarView(or related views) whereMultiBindingis used with this converter to toggle visibility based on database type and connection state.
- XAML bindings in
5. Gotchas
- Type safety: Assumes
values[0]is anintthat maps to a validDbTypeenum value. Passing a non-integer or out-of-range value may causeInvalidCastExceptionat runtime. - Null safety: Relies on
view.DataContextbeing non-null; otherwise, silently returnsCollapsed. No logging or error handling is present. - Hybrid mode logic is conditional: In
RemoteLocalHybridmode, visibility depends onRemoteConnected, but the converter does not handle cases whereRemoteConnectedisfalseanddbType == DbType.RemoteOnly— such cases correctly collapse, but this may be counterintuitive if the UI expects hybrid elements to always show. - No support for
parameter: Theparameterargument (often used to customize converter behavior in XAML) is ignored. - One-way only:
ConvertBackthrowsNotImplementedException, so this converter cannot be used in two-way bindings. - No validation of
DbTypevalues: UnknownDbTypevalues (e.g., future enum additions) fall through todefault: return Visibility.Collapsed, which may hide UI elements unexpectedly.
None identified beyond these.