如何更改按钮的位置?

时间:2018-01-13 00:42:11

标签: .net wpf mahapps.metro

如何更改窗口按钮的位置? 将它们设置在右上角,而不是居中。 我想安排按钮与其他窗口旁边的窗口进行交互,以便将其他内容放在那里。

现在如此:

enter image description here

<Controls:MetroWindow x:Class="JRGrace.MainWindow"
                  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                  xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                  xmlns:sys="clr-namespace:System;assembly=mscorlib"
                  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                  xmlns:local="clr-namespace:JRGrace"
                  Title="MainWindow" 
                  Height="350" Width="525"
                  TitlebarHeight="100">

<Controls:MetroWindow.TitleTemplate>
    <DataTemplate>
        <TextBlock Text="{TemplateBinding Content}"
               TextTrimming="CharacterEllipsis"
               VerticalAlignment="Bottom"
               Margin="8 -1 8 0"
               FontWeight="Light"
               FontSize="{DynamicResource WindowTitleFontSize}"
               FontFamily="{DynamicResource HeaderFontFamily}" />
    </DataTemplate>
</Controls:MetroWindow.TitleTemplate>

<Controls:MetroWindow.RightWindowCommands>
    <Controls:WindowCommands VerticalAlignment="Top">
        <Button Content="settings" />
        <Button>
            <StackPanel Orientation="Horizontal">
                <Rectangle Width="20"
               Height="20"
               Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
                    <Rectangle.OpacityMask>
                        <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_cupcake}" />
                    </Rectangle.OpacityMask>
                </Rectangle>
                <TextBlock Margin="4 0 0 0"
               VerticalAlignment="Center"
               Text="deploy cupcakes" />
            </StackPanel>
        </Button>
    </Controls:WindowCommands>
</Controls:MetroWindow.RightWindowCommands>

<Grid>

</Grid>

使用MahApps。

1 个答案:

答案 0 :(得分:2)

最小/最大和关闭按钮也可以像其他演示者一样在垂直方向上对齐。

UIView

我为每位演示者添加了30像素的高度,因为这些演示者会自动计算其内部内容。

enter image description here

希望这有帮助!