Files
DP44/enriched-qwen3-coder-next/DataPRO/CustomWindow.md
2026-04-17 14:55:32 -04:00

7.5 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DataPRO/CustomWindow/WindowMaximizeButton.cs
DataPRO/CustomWindow/WindowRestoreButton.cs
DataPRO/CustomWindow/WindowCloseButton.cs
DataPRO/CustomWindow/WindowMinimizeButton.cs
DataPRO/CustomWindow/Others.cs
DataPRO/CustomWindow/WindowButton.xaml.cs
2026-04-16T03:48:20.453815+00:00 Qwen/Qwen3-Coder-Next-FP8 1 606b672d4fe748f9

CustomWindow Module Documentation

1. Purpose

This module provides specialized button controls for window caption/title bar operations (minimize, maximize/restore, close) in a WPF custom window implementation. It extends the standard Button class to support state-dependent iconography (normal vs. disabled states) and integrates with external XAML resources for visual assets. The module enables consistent, reusable UI components for non-standard window chrome, particularly in applications like DataPRO where standard window borders are replaced with custom-drawn title bars.

2. Public Interface

Classes (all public, non-abstract, inherit from System.Windows.Controls.Button):

  • WindowButton
    Base class for all window caption buttons.

    • public new object Content { get; set; }
      Overrides Button.Content; sets the icon displayed when the button is enabled. Triggers RefreshContent() on change.
    • public object ContentDisabled { get; set; }
      Sets the icon displayed when the button is disabled. Triggers RefreshContent() on change.
    • public CornerRadius CornerRadius { get; set; }
      Gets/sets the corner radius of the button (default: new CornerRadius()).
    • public object ActiveContent { get; set; }
      Gets/sets the current content displayed (resolved from Content or ContentDisabled based on IsEnabled).
    • public virtual Brush BackgroundDefaultValue { get; }
      Returns the default background brush (resolved via FindResource("DefaultBackgroundBrush")).
    • protected void RefreshContent()
      Updates ActiveContent to Content if IsEnabled is true, otherwise to ContentDisabled. Automatically invoked on IsEnabledChanged.
  • WindowMinimizeButton
    Button for window minimize functionality.

    • public WindowMinimizeButton()
      Constructor. Loads WindowButtonMinimizeIcon and WindowButtonMinimizeIconDisabled from ButtonIcons.xaml into Content and ContentDisabled, respectively.
  • WindowMaximizeButton
    Button for window maximize functionality.

    • public WindowMaximizeButton()
      Constructor. Loads WindowButtonMaximizeIcon and WindowButtonMaximizeIconDisabled from ButtonIcons.xaml into Content and ContentDisabled, respectively.
  • WindowRestoreButton
    Button for window restore functionality (when maximized).

    • public WindowRestoreButton()
      Constructor. Loads WindowButtonRestoreIcon and WindowButtonRestoreIconDisabled from ButtonIcons.xaml into Content and ContentDisabled, respectively.
  • WindowCloseButton
    Button for window close functionality.

    • public WindowCloseButton()
      Constructor. Loads WindowButtonCloseIcon and WindowButtonCloseIconDisabled from ButtonIcons.xaml into Content and ContentDisabled, respectively.

Structs/Enums:

  • WindowButtonState
    public enum WindowButtonState { Normal, Disabled, None }
    Defines possible states for window buttons. Note: This enum is declared but not used in the provided source files.

Type Converters:

  • TypeConverterStringToUIElement
    Converts string values to TextBlock for XAML property assignment.
    • public override bool CanConvertFrom(...)
      Returns true only if sourceType == typeof(string).
    • public override object ConvertFrom(...)
      Converts a string to a TextBlock with Text = value, VerticalAlignment = Center, and Margin = new Thickness(3, 0, 0, 0). Used to enable Caption="string" syntax in XAML.

3. Invariants

  • Content Consistency: ActiveContent always equals Content when IsEnabled == true, and ContentDisabled when IsEnabled == false. This is enforced by RefreshContent() called on IsEnabledChanged and property setters.
  • Resource Loading: All button constructors must successfully load ButtonIcons.xaml from the pack://application:,,,/CustomWindow;component/ButtonIcons.xaml URI. Failure (e.g., missing resource) will cause a runtime exception.
  • Dependency Property Overrides: Content and ContentDisabled are new (not override) properties that wrap the base Button.Content dependency property. This hides the base property and enforces custom behavior.
  • State-Driven Content: ActiveContent is the only property directly bound to the visual content; Content/ContentDisabled are sources for ActiveContent.

4. Dependencies

Internal Dependencies:

  • ButtonIcons.xaml: Required XAML resource file containing ResourceDictionary entries for icons (e.g., "WindowButtonMinimizeIcon", "WindowButtonCloseIconDisabled").
  • WindowButton.xaml: XAML file defining the base WindowButton template (referenced via InitializeComponent() in the constructor).
  • CustomWindow namespace: All classes belong to this namespace; cross-references (e.g., WindowButton) are internal.

External Dependencies:

  • WPF Framework:
    • System.Windows (Application, Window, Button, ResourceDictionary, XamlReader, CornerRadius, Brush)
    • System.Windows.Controls (Button, TextBlock, VerticalAlignment)
    • System.Windows.Markup (XamlReader)
    • System.IO (Stream)
  • .NET Core/.NET Framework: Base libraries (System, System.ComponentModel, System.Globalization).

Inferred Usage:

  • WindowButton subclasses (WindowMinimizeButton, WindowMaximizeButton, WindowRestoreButton, WindowCloseButton) are likely used in a custom window template (e.g., CustomWindow class, not provided here).
  • TypeConverterStringToUIElement is likely applied to a Caption property in a custom window control (e.g., via [TypeConverter(typeof(TypeConverterStringToUIElement))]).

5. Gotchas

  • Hardcoded Resource URI: The pack://application:,,,/CustomWindow;component/ButtonIcons.xaml URI is hardcoded in all button constructors. If the resource is moved, renamed, or the assembly name changes, all buttons will fail at runtime.
  • No Fallback for Missing Resources: If ButtonIcons.xaml or its expected keys (e.g., "WindowButtonMaximizeIcon") are missing, XamlReader.Load() or dictionary access will throw an exception.
  • ActiveContent is Not a Dependency Property: While ActiveContent is a dependency property, it is not used for styling or data binding in the provided code. Its purpose is internal state management.
  • CornerRadius Not Applied in Subclasses: Subclasses (e.g., WindowMinimizeButton) have commented-out CornerRadius assignments. The current implementation relies on the base CornerRadius property, but no default is set in constructors.
  • BackgroundDefaultValue is Virtual: Subclasses could override BackgroundDefaultValue, but none do in the provided source.
  • TypeConverterStringToUIElement is Unused in Source: The converter is declared but not referenced in any property or class in the provided files. Its usage is inferred from comments but not verified.
  • No Error Handling: Resource loading and XAML parsing lack try/catch blocks. Failures will crash the constructor.