【问题标题】:How can change the window title position xaml如何更改窗口标题位置xaml
【发布时间】:2015-11-25 06:23:33
【问题描述】:

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

【问题讨论】:

    标签: wpf xaml window title


    【解决方案1】:

    WindowChrome 也很有帮助。

    http://blogs.msdn.com/b/wpfsdk/archive/2010/08/25/experiments-with-windowchrome.aspx 有一些有用的信息。

    例如,这里是一个示例 MainWindow.xaml,您可以将其用作起点并进一步完善。

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

    您会看到一个如下所示的窗口:

    【讨论】:

      【解决方案2】:

      我假设您的问题是关于 WPF 的。 (因为这在 winrt 中是不可能的)

      基本上,您必须将 WindowStyle 设置为 None 并创建您自己的自定义窗口。

      您可以通过以下链接找到大量信息和示例:

      在自定义窗口中,您可以将标题放置在任意位置。

      【讨论】:

        猜你喜欢
        • 2014-01-16
        • 1970-01-01
        • 2012-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-09
        • 2019-04-26
        • 1970-01-01
        相关资源
        最近更新 更多