Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更改标题栏按钮WPF C#_C#_Wpf_Xaml_Titlebar - Fatal编程技术网

如何更改标题栏按钮WPF C#

如何更改标题栏按钮WPF C#,c#,wpf,xaml,titlebar,C#,Wpf,Xaml,Titlebar,我想做一个窗口标题栏中的关闭,最小化和最大化按钮自定义。在某些程序中,标题栏是不同的,但我不想更改完整的标题栏,只想更改按钮。有人能帮我一下吗?一般来说,窗口的标题栏属于窗口的所谓的非客户端区域。 这意味着你不能改变按钮的外观,不能添加自定义按钮等等 要做到这一点,您需要滚动您自己的窗口样式或使用一个为您这样做的库 一些有用的教程或起点可能是或本教程 要创建自己的窗样式,可以使用此简单样式作为基础: <Style x:Key="MyCustomWindowStyle" TargetType

我想做一个窗口标题栏中的关闭,最小化和最大化按钮自定义。在某些程序中,标题栏是不同的,但我不想更改完整的标题栏,只想更改按钮。有人能帮我一下吗?

一般来说,窗口的标题栏属于窗口的所谓的非客户端区域。 这意味着你不能改变按钮的外观,不能添加自定义按钮等等

要做到这一点,您需要滚动您自己的窗口样式或使用一个为您这样做的库

一些有用的教程或起点可能是或本教程

要创建自己的窗样式,可以使用此简单样式作为基础:

<Style x:Key="MyCustomWindowStyle" TargetType="{x:Type Window}"> 
    <Setter Property="WindowStyle" Value="None"/> 
    <Setter Property="AllowsTransparency" Value="True"/>
    <Setter Property="Background" Value="White"/> 
    <Setter Property="BorderBrush" Value="Blue"/> 
    <Setter Property="BorderThickness" Value="1"/>                        
    <Setter Property="Template">
        <Setter.Value>
           <ControlTemplate TargetType="{x:Type Window}">
                <Grid Background="{TemplateBinding Background}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>

                    <!-- this displays the window title -->
                    <TextBlock TextAlignment="Center"
                               Text="{TemplateBinding Title}"/>

                    <StackPanel Grid.Column="1"
                                Orientation="Horizontal"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Center">

                        <!-- the minimize button, using your own style -->
                        <Button Style="{StaticResource MyMinimizeButtonStyle}" 
                                Width="20" 
                                Height="20" />

                        <!-- the close button, using your own style -->
                        <Button Style="{StaticResource MyCloseButtonStyle}"
                                Width="20"
                                Height="20" />
                    </StackPanel>

                    <!-- this displays the actual window content -->
                    <ContentPresenter Grid.Row="1"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

您可以使用windowchrome自定义windows的chrome。

您可以使用它来完全重新设置窗口的模板。 请注意,自编写以下内容以来,该类已移动。


这可能会产生奇怪的副作用,例如在win10中最大化窗口时。

您可以使用WindowChrome自定义窗口样式:


此样式不使用SystemParameters2类,因为它在.net 4.5中不存在。

更改它的外观,或者在按下时它的功能?我有一个问题。我无法移动窗户:/