Skip to content

feat: add Tag option to control Expander header text orientation (Left/Right) - #253

Merged
ghost1372 merged 2 commits into
ghost1372:developfrom
lihongfang16:feat/expander-tag-header-orientation
Nov 13, 2026
Merged

ghost1372 merged 2 commits into
ghost1372:developfrom
lihongfang16:feat/expander-tag-header-orientation

Conversation

@lihongfang16

@lihongfang16 lihongfang16 commented Nov 13, 2026 •

Copy link
Copy Markdown

Problem

When Expander.ExpandDirection is Left or Right, the header is rotated -90° as a whole: the text is arranged vertically, but every glyph lies on its side (you have to tilt your head to read it), and there is no way to control the header text orientation.

Solution

Per review feedback, this uses an attached property instead of Tag: a new hc:ExpanderElement.HeaderTextOrientation (enum ExpanderHeaderTextOrientation: Default / Vertical / Horizontal), defined in Controls/Attach/ExpanderElement.cs following the existing BorderElement pattern. The Left/Right templates name the header ContentPresenter (HeaderText) and add template triggers on the attached property:

HeaderTextOrientation Header layout
unset (Default) identical to the current behavior (whole -90° rotation, default unchanged)
Vertical upright vertical: a +90° counter-rotation cancels the outer -90°, and an injected ContentTemplate makes the TextBlock wrap at one glyph width (FontSize), so characters stand upright and stack top-to-bottom
Horizontal upright horizontal: only the +90° counter-rotation, a single horizontal line

Notes:

  • The arrow (PathArrow) keeps its original -90° rotation and the outer layout geometry is unchanged;
  • ExpanderUpTemplate / ExpanderDownTemplate are untouched, so the Up/Down default behavior is unaffected;
  • It can be combined with HorizontalContentAlignment to control where the text sits relative to the arrow (Left = away from the arrow (default) / Center = centered / Right = next to the arrow).

Usage

xmlns:hc="clr-namespace:HandyControl.Controls;assembly=HandyControl"

<Expander ExpandDirection="Left" hc:ExpanderElement.HeaderTextOrientation="Vertical" Header="..." />
<Expander ExpandDirection="Left" hc:ExpanderElement.HeaderTextOrientation="Vertical" HorizontalContentAlignment="Center" Header="..." />
<Expander ExpandDirection="Right" hc:ExpanderElement.HeaderTextOrientation="Horizontal" Header="..." />

Verification

  • dotnet build src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj -f net8.0-windows: 0 warnings, 0 errors;
  • the generated combined dictionary Themes/Theme.xaml contains the new triggers;
  • verified in a WPF demo app: Left/Right direction × Default/Vertical/Horizontal (six states) plus the three HorizontalContentAlignment combinations all render as expected.

Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
@ghost1372

Copy link
Copy Markdown
Owner

@lihongfang16 cant we do this with Attached Properties?

… instead of Tag

Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
@lihongfang16

Copy link
Copy Markdown
Author

Thanks for the suggestion! Switched to an attached property: hc:ExpanderElement.HeaderTextOrientation (enum ExpanderHeaderTextOrientation: Default / Vertical / Horizontal), defined in Controls/Attach/ExpanderElement.cs following the existing BorderElement pattern. The Tag-based triggers are removed; the default value keeps the current rendering, and it still composes with HorizontalContentAlignment. Pushed as 2d6c4c3.

@ghost1372

Copy link
Copy Markdown
Owner

thank you

@ghost1372
ghost1372 merged commit 8b62a3a into ghost1372:develop Nov 13, 2026
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