将图标添加到WPF窗口的工具栏
我有一个WPF窗口,其windowStyle设置为"SingleBorderWindow",在右上角提供了一个关闭按钮
I have a WPF window with windowStyle set to "SingleBorderWindow" which provides a close button on the right top corner
WindowStyle="SingleBorderWindow"
我想在关闭按钮之前添加另一个按钮,例如帮助按钮,设置按钮等,
I would like to add another button before the close button, say help button, settings button etc.,
现有窗口如下所示
我需要一个类似于以下的窗口工具栏
I would need a window toolbar like the following
任何帮助实现这种行为的方法都将受到高度赞赏.
Any help to acheive this behaviour is highly appreciated.
谢谢.
我已经尝试了几种解决方案",发布在网络上,但从未真正起作用. 完成所需操作的唯一正确方法是将WindowStyle设置为None,然后根据需要创建标题栏,并使用尽可能多的按钮 想要和想要的格式.
I have tried several of the "solutions" posted on web but they never really worked. The only true way to accomplish what you want is to set the WindowStyle as None and then create the title bar as you want it, with as many buttons as you want and the format you want.
请注意,这将导致窗口的许多功能丢失,例如拖动和调整大小.
Please notice that this will cause the loss of many of the features of a window such as dragging and resizing.
请注意以下几点:
<Window x:Class="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:WinStyleNone"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" WindowStyle="None" MouseLeftButtonDown="Window_MouseLeftButtonDown">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition ></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="20"></ColumnDefinition>
<ColumnDefinition Width="20"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" HorizontalAlignment="Center" Text="{Binding Title, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"></TextBlock>
<Button Grid.Column="1">Y</Button>
<Button Grid.Column="2" Click="XClick">X</Button>
</Grid>
</Grid>
</Window>
和后面的代码:
Class MainWindow
Private Sub XClick(sender As Object, e As RoutedEventArgs)
Me.Close()
End Sub
Private Sub Window_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs)
DragMove()
End Sub
End Class