wpfui icon indicating copy to clipboard operation
wpfui copied to clipboard

Add support for setting content in place of the title in a TitleBar

Open jonlipsky opened this issue 10 months ago • 14 comments

Pull request type

Please check the type of change your PR introduces:

  • [ ] Update
  • [ ] Bugfix
  • [x] Feature
  • [ ] Code style update (formatting, renaming)
  • [ ] Refactoring (no functional changes, no api changes)
  • [ ] Build related changes
  • [ ] Documentation content changes

What is the current behavior?

Currently there is no way to set content in a TitleBar that is left justified and/or use content other than the default TextBlock for the title content.

Issue Number: [#775] [#1025]

What is the new behavior?

This PR adds support for (optionally) specifying content to be displayed as a replacement for the TextBlock which displays the title. The following changes have been made:

  • Added a LeftHeader property that can be optionally set to specify the view to be presented in place of the default TextBlock that displays the title (when set).
  • A TextBlock is initialized in the TitleBar constructor and assigned to the LeftHeader property so that setting the title is still the default behavior.
  • Renamed Header to RightHeader to make the API more self-documenting as to the purpose of the property.
  • Updated the sandbox window example to demonstrate this new functionality.
image

Other information

  • This change is a breaking change from the previous version since Header has been renamed to RightHeader. One remedy would be to add a new property called Header, which would delegate to RightHeader and be marked as deprecated to give users time to update their code.

  • One additional enhancement that may be nice to have would be the ability to vertically align the Minimize, Maximize and Close buttons of the window. It may be more aesthetically pleasing to have them center aligned depending on the content in the RightHeader. As an example, JetBrains Rider does this in their custom titlebar:

image

jonlipsky avatar Mar 31 '24 20:03 jonlipsky

To prevent backward compatibility issues you could have kept Header and just have added LeftHeader.

Once there's a major version change that can break backwards compatibility then a name change from Header to RightHeader could be considered without issue

537mfb avatar Apr 01 '24 15:04 537mfb

@537mfb Yes, I'd be happy to submit an update to the pull request to change the naming of RightHeader back to Header. I renamed that property because the original behavior was not obvious (in my personal opinion).

jonlipsky avatar Apr 01 '24 20:04 jonlipsky

Given that Header's behavior changed between 2.x and 3.x, and this would change it back, I would argue the rename makes sense. Giving it a new name makes it clear that the behavior has changed.

chucker avatar Apr 04 '24 15:04 chucker

I think you guys are forgetting that "left" and "right" should be swapped when the OS is using a right-to-left language. Better use something like "primary" and "secondary, or something like that.

Jay-o-Way avatar Apr 04 '24 16:04 Jay-o-Way

...the ability to vertically align the Minimize, Maximize and Close buttons

That would be setting the PreferredHeightOption to TitleBarHeightOption.Tall https://learn.microsoft.com/windows/apps/develop/title-bar#tall-title-bar-support-for-custom-title-bars

Jay-o-Way avatar Apr 04 '24 16:04 Jay-o-Way

@Jay-o-Way I initially called the renamed properties LeadingHeader and TrailingHeader; however it wasn't clear to me that the titlebar class was adaptive for right-to-left languages the way it is built, thus I renamed them. I agree that if it is adaptive, then they should have an alternate name.

jonlipsky avatar Apr 04 '24 16:04 jonlipsky

Not sure how easy this would be to achieve but how about having Header on the side of the system buttons (as is now) and make Title work like Content in other controls where if you give a string it works like a textblock but you can give it other arbitrary content.

Think of a Label - you can give it a string or a layout with several controls as content

537mfb avatar Apr 08 '24 08:04 537mfb

@537mfb That's essentially what my PR does right now. By default, it's a TextBlock, however if you set LeftHeader, that content becomes whatever you set it to.

jonlipsky avatar Apr 08 '24 15:04 jonlipsky

@jonlipsky my idea is slightly different.

you could have:

<iu:TitleBar Title="My App Name" ...

and it would work as it does now. But you could also do:

<iu:TitleBar ....>
    <iu:TitleBar.Title>
         <StackPanel Orientation="Horizontal">
             <ui:SymbolIcon Symbol="Fluent24"/>
             ....
         </StackPanel>
    </iu:TitleBar.Title>
</iu:TitleBar>

537mfb avatar Apr 08 '24 18:04 537mfb

To be honest, I'm not a fan of the division into HeaderLeft and HeaderRight. I would prefer one big Header as a whole Titlebar up to navigation buttons with default value - Icon and Application Name, similar to @537mfb's suggestion

pomianowski avatar Apr 14 '24 08:04 pomianowski

Any update?

Summpot avatar Aug 23 '24 01:08 Summpot

To be honest, I'm not a fan of the division into HeaderLeft and HeaderRight. I would prefer one big Header as a whole Titlebar up to navigation buttons with default value - Icon and Application Name, similar to @537mfb's suggestion

MAUI apparently now uses the notion of TrailingContent, which is roughly what HeaderRight is in this PR.

chucker avatar Aug 27 '24 13:08 chucker

If a project admin/leader lets me know their preference as to how they want it to work, I'd happily amend the PR to implement that. I took the initial approach I did because there were other issues/requests asking for it that way.

jonlipsky avatar Aug 27 '24 15:08 jonlipsky

If a project admin/leader lets me know their preference as to how they want it to work, I'd happily amend the PR to implement that. I took the initial approach I did because there were other issues/requests asking for it that way.

@pomianowski is the project owner, so I suppose this reply counts?

This PR is awesome though, thanks for creating it @jonlipsky.

SamKr avatar Sep 02 '24 12:09 SamKr