如何更改窗口标题位置 xaml [英] How can change the window title position xaml

查看:45
本文介绍了如何更改窗口标题位置 xaml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以更改窗口中标题的位置?默认情况下,它位于窗口标题栏的左侧.我想把它移到中心.

解决方案

WindowChrome 也很有帮助.

Is it possible to change the position of the title in the window? By default it is placed at the left side of the window title bar. I want to move it towards the center.

解决方案

WindowChrome is helpful as well.

http://blogs.msdn.com/b/wpfsdk/archive/2010/08/25/experiments-with-windowchrome.aspx has some useful information.

For e.g., here is a sample MainWindow.xaml that you can use as a starting point and refine further.

<Window x:Class="WindowChromeTest.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WindowChromeTest"
        mc:Ignorable="d"
        x:Name="_MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <WindowChrome.WindowChrome>
        <WindowChrome GlassFrameThickness="-1" ResizeBorderThickness="4" CaptionHeight="40"/>
    </WindowChrome.WindowChrome>
    <Window.Template>
        <ControlTemplate>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="1*"/>
                </Grid.RowDefinitions>

                <!-- Opacity of < 1.0 helps show the minimize, maximize and close buttons --> 
                <Border Grid.Row="0" Background="Wheat" Opacity="0.8">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="30" />
                            <ColumnDefinition Width="1*"/>
                        </Grid.ColumnDefinitions>

                        <!-- System Menu -->
                        <Button Grid.Column="0"
                                WindowChrome.IsHitTestVisibleInChrome="True"
                                Command="{x:Static SystemCommands.ShowSystemMenuCommand}"
                                CommandParameter="{Binding ElementName=_MainWindow}">
                            <!-- Make sure there is a resource with name Icon in MainWindow -->
                            <Image 
                                Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Icon}"
                                WindowChrome.IsHitTestVisibleInChrome="True"/>
                        </Button>

                        <!-- Window Title - Center Aligned -->
                        <TextBlock 
                            Grid.Column="1"
                            TextAlignment="Center" 
                            VerticalAlignment="Center"
                            Text="{Binding Title, RelativeSource={RelativeSource TemplatedParent}}" />

                    </Grid>
                </Border>

                <!-- This is the Window's main content area -->
                <!-- Top margin 44 = WindowChrome ResizeBorderThickness (4) + CaptionHeight(40) -->
                <!-- Bottom margin 1 is somewhat arbitrary -->
                <Border Grid.Row="1" Background="White" Opacity="0.5">
                    <ContentPresenter Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}"/>
                </Border>
            </Grid>
        </ControlTemplate>
    </Window.Template>
    <Grid>
        <TextBox/>
    </Grid>
</Window>

You'll see a window that looks like this:

这篇关于如何更改窗口标题位置 xaml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆