Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use a Menu in the window's titlebar ? #3447

Closed
GF-Huang opened this issue Feb 1, 2019 · 3 comments · Fixed by #3666
Closed

How can I use a Menu in the window's titlebar ? #3447

GF-Huang opened this issue Feb 1, 2019 · 3 comments · Fixed by #3666
Assignees
Milestone

Comments

@GF-Huang
Copy link

GF-Huang commented Feb 1, 2019

I want to put a Menu (because I need a single selection feature) into RightWindowCommands which has appearance like a default button inside RightWindowCommands.

I had try DropdownButton, MenuItem, Menu with MenuItem, but their appearance will be incompatible.

image

image

@GF-Huang GF-Huang changed the title How can I use a DropdownButton in the window's titlebar ? How can I use a Menu in the window's titlebar ? Feb 1, 2019
@GF-Huang
Copy link
Author

GF-Huang commented Feb 2, 2019

Solution left to those in need:

App.xaml:

<Style xmlns:options="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
       x:Key="ButtonWindowCommandsDropDownStyle"
       TargetType="Button"
       BasedOn="{StaticResource ButtonDropDownStyle}">
    <Style.Resources>
        <!-- override the dynamic resources -->
        <SolidColorBrush x:Key="GrayBrush8" options:Freeze="True" Color="Transparent" />
        <SolidColorBrush x:Key="GrayBrush5" options:Freeze="True" Color="Transparent" />
        <!-- for IsEnabled == False -->
        <SolidColorBrush x:Key="GrayBrush10" options:Freeze="True" Color="Transparent" />
    </Style.Resources>
</Style>

<Style x:Key="DropDownButtonWindowCommandsStyle"
       TargetType="controls:DropDownButton"
       BasedOn="{StaticResource {x:Type controls:DropDownButton}}">
    <Setter Property="Orientation" Value="Vertical" />
    <Setter Property="ArrowVisibility" Value="Collapsed" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="Opacity" Value="0.5" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="Foreground" Value="White" />
    <Setter Property="ButtonStyle" Value="{DynamicResource ButtonWindowCommandsDropDownStyle}" />

    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Opacity" Value="1" />
        </Trigger>
    </Style.Triggers>
</Style>

MainWindow.xaml:

<controls:MetroWindow.RightWindowCommands>
    <controls:WindowCommands ShowLastSeparator="False">
        <controls:DropDownButton Content="{iconPacks:Material Kind=Translate}"
                                 Style="{StaticResource DropDownButtonWindowCommandsStyle}">
            
        </controls:DropDownButton>
    </controls:WindowCommands>
</controls:MetroWindow.RightWindowCommands>

Effect:

mouse not over
image

mouse over
image

@lorinkundert
Copy link

Good fix for a fixed theme, but not so good for customers that demand personalized themes.

@GF-Huang
Copy link
Author

@lorinkundert For all the build-in themes, it doesn't seem to be a problem. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants