Home How to change the location of buttons?
Reply: 1

How to change the location of buttons?

UporotayaPanda
1#
UporotayaPanda Published in 2018-01-13 00:42:10Z

How to change the location of buttons for a window? Set them to the upper right corner, not centered. I want to arrange buttons for interacting with the window next to the rest to put other content there.

Now so:

<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>

Use MahApps.

punker76
2#
punker76 Reply to 2018-01-21 11:24:26Z

The min/max and close buttons can also be aligned in vertical direction like the other presenters.

<Controls:MetroWindow.WindowButtonCommands>
    <Controls:WindowButtonCommands VerticalAlignment="Top" Height="30" Style="{DynamicResource MahApps.Metro.Styles.WindowButtonCommands.Win10}" />
</Controls:MetroWindow.WindowButtonCommands>

<Controls:MetroWindow.LeftWindowCommands>
    <Controls:WindowCommands VerticalAlignment="Bottom" Height="30">
    </Controls:WindowCommands>
</Controls:MetroWindow.LeftWindowCommands>

<Controls:MetroWindow.RightWindowCommands>
    <Controls:WindowCommands VerticalAlignment="Top" Height="30">
    </Controls:WindowCommands>
</Controls:MetroWindow.RightWindowCommands>

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

I've added the height of 30 pixels for each presenters, cause these presenters calculates their inner content automatically.

Hope this helps!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.331797 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO