Skip to content

Simplify ColorPicker and ColorView via shared abstract base class#2

Draft
Copilot wants to merge 3 commits into
masterfrom
copilot/simplify-colorpicker-colorview
Draft

Simplify ColorPicker and ColorView via shared abstract base class#2
Copilot wants to merge 3 commits into
masterfrom
copilot/simplify-colorpicker-colorview

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 6, 2026

ColorPicker inherited from ColorView and its template was a ~500-line verbatim copy of the ColorView template embedded in a flyout — with a comment literally saying "It MUST always be kept in sync with the ColorView".

Changes

New ColorPickerBase abstract class

  • Extracts all ~25 shared StyledProperty definitions (Color, HsvColor, Palette, PaletteColors, SelectedIndex, all Is*Visible flags, etc.) into ColorPickerBase.Properties.cs
  • Moves ColorChanged event, OnColorChanged, and all shared property-sync logic (Color↔HsvColor, Palette→PaletteColors, alpha coercion) into ColorPickerBase.cs

ColorView → extends ColorPickerBase

  • Retains only template-specific code: PART_HexTextBox, PART_TabControl, ValidateSelection, hex input handlers
  • ColorView.Properties.cs emptied (all properties now in base class)

ColorPicker → extends ColorPickerBase (no longer ColorView)

  • Retains only Content, ContentTemplate, HorizontalContentAlignment, VerticalContentAlignment
  • Adds [TemplatePart("PART_ColorView", typeof(ColorView))]

Simplified ColorPicker templates (both Simple and Fluent)

~500 lines of duplicated XAML reduced to ~99 lines using <ColorView> as the inner flyout element with bindings:

<ColorView x:Name="PART_ColorView"
           Color="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
           SelectedIndex="{Binding SelectedIndex, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
           ColorModel="{TemplateBinding ColorModel}"
           IsAlphaEnabled="{TemplateBinding IsAlphaEnabled}"
           Palette="{TemplateBinding Palette}"
           ...>
  <ColorView.Resources>
    <CornerRadius x:Key="ColorViewTabBackgroundCornerRadius">0,0,0,0</CornerRadius>
  </ColorView.Resources>
</ColorView>

Color and SelectedIndex are TwoWay so user interactions propagate back to the ColorPicker. All configuration properties use one-way TemplateBinding. The ColorViewTabBackgroundCornerRadius resource is overridden locally per-theme to maintain flyout-appropriate styling.

Copilot AI and others added 2 commits April 6, 2026 19:01
…r to share base class, simplify ColorPicker templates

Agent-Logs-Url: https://github.com/irihitech/Avalonia/sessions/b3aced6b-b243-485a-8949-c94bc7b8724c

Co-authored-by: rabbitism <14807942+rabbitism@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor ColorPicker and ColorView for shared base class Simplify ColorPicker and ColorView via shared abstract base class Apr 6, 2026
Copilot AI requested a review from rabbitism April 6, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants