Files
DP44/enriched-qwen3-coder-next/DataPRO/Modules/Database/DatabaseServices/Converters.md
2026-04-17 14:55:32 -04:00

5.4 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DataPRO/Modules/Database/DatabaseServices/Converters/DbTypeToVisibilityConverter.cs
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 a Visibility value:
        • values[0]: An int representing a DbType enum value (cast to DbType).
        • values[1]: A DatabaseStatusBarView instance (used to access its DataContext, expected to be a DatabaseStatusBarViewModel).
        • Returns Visibility.Visible if the dbType matches the visibility rules for the current vm.DatabaseType and vm.RemoteConnected state; otherwise returns Visibility.Collapsed.
        • If view.DataContext is null, returns Visibility.Collapsed.
        • Throws no exceptions explicitly, but may throw InvalidCastException if inputs are not of expected types.
    • 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.

3. Invariants

  • values array must contain exactly two elements:
    • Element 0: An int that can be safely cast to DbType.
    • Element 1: A DatabaseStatusBarView instance (non-null).
  • view.DataContext must be non-null and assignable to DatabaseStatusBarViewModel; otherwise, the converter returns Visibility.Collapsed.
  • Visibility logic is strictly governed by the DatabaseStatusBarViewModel.DatabaseType and DatabaseStatusBarViewModel.RemoteConnected properties:
    • For RemoteOnly: Only DbType.RemoteOnly is visible.
    • For LocalOnly: Only DbType.LocalOnly is visible.
    • For RemoteLocalHybrid:
      • If RemoteConnected == true: Only DbType.RemoteOnly is visible.
      • If RemoteConnected == false: Only DbType.RemoteLocalHybrid is visible.
    • Any other DatabaseType value results in Visibility.Collapsed.
  • The converter is not intended for two-way binding (ConvertBack is unimplemented).

4. Dependencies

  • Imports/References:

    • System, System.Globalization, System.Windows, System.Windows.Data (WPF core)
    • DTS.Common.Enums.Database (external library/namespace) — provides DbType and likely DatabaseStatusBarView/DatabaseStatusBarViewModel.
  • Assumed Dependencies (from usage context):

    • DatabaseStatusBarView: A WPF UserControl or Window used in the status bar.
    • DatabaseStatusBarViewModel: View model with properties:
      • DatabaseType (DbType)
      • RemoteConnected (bool)
    • DbType enum (from DTS.Common.Enums.Database) — expected to include at least: RemoteOnly, LocalOnly, RemoteLocalHybrid.
  • Depended upon by:

    • XAML bindings in DatabaseStatusBarView (or related views) where MultiBinding is used with this converter to toggle visibility based on database type and connection state.

5. Gotchas

  • Type safety: Assumes values[0] is an int that maps to a valid DbType enum value. Passing a non-integer or out-of-range value may cause InvalidCastException at runtime.
  • Null safety: Relies on view.DataContext being non-null; otherwise, silently returns Collapsed. No logging or error handling is present.
  • Hybrid mode logic is conditional: In RemoteLocalHybrid mode, visibility depends on RemoteConnected, but the converter does not handle cases where RemoteConnected is false and dbType == DbType.RemoteOnly — such cases correctly collapse, but this may be counterintuitive if the UI expects hybrid elements to always show.
  • No support for parameter: The parameter argument (often used to customize converter behavior in XAML) is ignored.
  • One-way only: ConvertBack throws NotImplementedException, so this converter cannot be used in two-way bindings.
  • No validation of DbType values: Unknown DbType values (e.g., future enum additions) fall through to default: return Visibility.Collapsed, which may hide UI elements unexpectedly.

None identified beyond these.