Mahapps.metro: 1px to the left of the LeftWindowCommands

Created on 12 Apr 2018  路  2Comments  路  Source: MahApps/MahApps.Metro

Hi,

On the latest version (this definitely wasn't an issue in the past) there is a 1px margin to the left of the LeftWindowCommands which appears even if no icon is specified. Would it be possible to revert to the old behaviour and not have this 1px margin?

Cheers!

Bug

Most helpful comment

Thanks, so you mean in the future I should be able to set the margin directly and it should work?

<mahAppsControls:WindowCommands Margin="0">

All 2 comments

@SkinnySackboy This is caused by the inner Margin of the WindowCommandsItem. This exists since 1.5.0, before it was a 8 pixel gap.

https://github.com/MahApps/MahApps.Metro/blob/040ba4ea0129d34e1832c2e81422138d77e08cb1/src/MahApps.Metro/MahApps.Metro/Themes/WindowCommands.xaml#L122

The difference now is, that the Border of the Window is now correct interpreted (this was wrong in 1.5). So in 1.5 you didn't see an additional gap, cause the the inner Margin of the Items are also 1px like the Border. In 1.6 you see now the correct thing. You can override the ItemcontainerStyle for the WindowCommandsItem to remove the inner margin.

I will solve this in the future by using the Padding/Margin properties.

<Style TargetType="{x:Type Controls:WindowCommandsItem}">
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Controls:WindowCommandsItem}">
                <StackPanel HorizontalAlignment="{Binding HorizontalContentAlignment, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type Controls:WindowCommands}}}"
                            VerticalAlignment="{Binding VerticalContentAlignment, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type Controls:WindowCommands}}}"
                            Orientation="Horizontal">
                    <!-- set the Margin to 0 -->
                    <ContentPresenter x:Name="PART_ContentPresenter"
                                      Margin="0"
                                      Content="{TemplateBinding Content}"
                                      ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                      ContentTemplate="{TemplateBinding ContentTemplate}"
                                      ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    <Rectangle x:Name="PART_Separator"
                               Width="1"
                               Height="{Binding SeparatorHeight, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type Controls:WindowCommands}}}"
                               Fill="{Binding Foreground, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type Controls:WindowCommands}}}"
                               IsHitTestVisible="False"
                               Opacity="0.25"
                               SnapsToDevicePixels="True"
                               UseLayoutRounding="True" />
                </StackPanel>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsSeparatorVisible" Value="False">
                        <Setter TargetName="PART_Separator" Property="Visibility" Value="Collapsed" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Thanks, so you mean in the future I should be able to set the margin directly and it should work?

<mahAppsControls:WindowCommands Margin="0">

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Hikerakashiya picture Hikerakashiya  路  5Comments

punker76 picture punker76  路  4Comments

alan0428a picture alan0428a  路  4Comments

somil55 picture somil55  路  3Comments

punker76 picture punker76  路  3Comments