Skip to content

Hide buttons in AdonisWindow according to ResizeMode#38

Merged
benruehl merged 2 commits intobenruehl:masterfrom
alxnull:resizemode
Nov 16, 2019
Merged

Hide buttons in AdonisWindow according to ResizeMode#38
benruehl merged 2 commits intobenruehl:masterfrom
alxnull:resizemode

Conversation

@alxnull
Copy link
Copy Markdown
Contributor

@alxnull alxnull commented Oct 20, 2019

The default WPF window hides the minimize and maximize buttons if ResizeMode is set to NoResize. Also, the maximize button is disabled if it's set to CanMinimize [link].
This PR adds this behaviour for AdonisWindow.

PS: Thanks for your great work on this library!

Copy link
Copy Markdown
Owner

@benruehl benruehl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for adressing this issue!

I think the solution could be improved by moving the setter of the disabled foreground to the WindowButton style. It would work for all window buttons when they are disabled and not just for this specific case.

@benruehl
Copy link
Copy Markdown
Owner

We should also check if the window buttons are the only things that need to respect the ResizeMode. Maximizing can also be done using shortcuts, double-clicking the title bar and dragging the window to the top of the screen. Maybe these things need to be adressed as well. I will look into that soon.

@alxnull
Copy link
Copy Markdown
Contributor Author

alxnull commented Oct 27, 2019

@benruehl Thanks for your feedback.

I think the solution could be improved by moving the setter of the disabled foreground to the WindowButton style.

I did try this before, but somehow could not get it to work. It seems the triggers in the WindowButton style are overriden by the values of the control template. The current is the only solution I could think of.

Maximizing can also be done using shortcuts, double-clicking the title bar and dragging the window to the top of the screen.

Made a quick check for those and everything already seems to behave as expected. Looks like someone already thought about that :)

if (e.ClickCount == 2 &&
(ResizeMode == ResizeMode.CanResize || ResizeMode == ResizeMode.CanResizeWithGrip))
{
ToggleWindowState();
}

@benruehl
Copy link
Copy Markdown
Owner

You are right, I see what you mean, sorry!

The only alternative I can think of is a trigger in the WindowButton style which sets the foreground of an inner control in the template. That way the foreground is no longer overridden because the inheritance is cut off.
Something like this:

<ControlTemplate.Triggers>
    <Trigger Property="IsEnabled" Value="False">
        <Setter Property="TextElement.Foreground" TargetName="ContentPresenter" Value="{DynamicResource {x:Static adonisUi:Brushes.DisabledForegroundBrush}}"/>
    </Trigger>
</ControlTemplate.Triggers>

(Assuming the ContentPresenter in the WindowButton control template is named 'ContentPresenter')

This solution has the disadvantage that it is built directly into the template which means the behavior cannot be customized from the outside anymore.

What do you think? If you don't like the idea, we can use your current solution as well.

@alxnull
Copy link
Copy Markdown
Contributor Author

alxnull commented Nov 3, 2019

@benruehl You're alternative solution makes more sense to me as it is more generic. However, setting TextElement.Foreground on the ContentPresenter does not seem to have an effect on the window button icons as they are canvas elements which use the foreground color of the surrounding ContentControl. Have I overseen something important here?

@benruehl
Copy link
Copy Markdown
Owner

benruehl commented Nov 7, 2019

Seems like I forgot to mention that the button's Content needs to go into the ContentTemplate instead.

<Button x:Name="PART_MaximizeRestoreButton"
        Grid.Column="1"
        Style="{DynamicResource {x:Static adonisUi:Styles.WindowButton}}"
        Foreground="{TemplateBinding TitleBarForeground}"
        Background="{TemplateBinding WindowButtonHighlightBrush}">
    <Button.ContentTemplate>
        <DataTemplate>
            <ContentControl ContentTemplate="{DynamicResource {x:Static adonisUi:Icons.WindowMaximize}}"
                            Width="10"
                            Height="10"/>
        </DataTemplate>
    </Button.ContentTemplate>
</Button>

I am not sure why this changes the behavior though. Read about it in punker76's blog.

Does it work for you now?

@alxnull
Copy link
Copy Markdown
Contributor Author

alxnull commented Nov 8, 2019

Thanks, this does work for me now. I pushed the changes.

@benruehl
Copy link
Copy Markdown
Owner

Awesome. Again, thanks a lot for this contribution. Appreciate it.

@benruehl benruehl merged commit fddfd72 into benruehl:master Nov 16, 2019
@alxnull alxnull deleted the resizemode branch March 18, 2020 22:13
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