将图标添加到WPF窗口的工具栏 [英] Add icons to toolbar of the wpf window

查看:153
本文介绍了将图标添加到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


这篇关于将图标添加到WPF窗口的工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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