WPF编程,使用WindowChrome实现自定义窗口功能的一种方法。

效果:

1、安装:下载地址可网上找,也可从最后的地址

2、增加引用

3、增加命名空间

        xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell"

4、前台

   <Window.Template>
        <ControlTemplate TargetType="{x:Type Window}">
            <Border BorderThickness="1">
                <DockPanel>
                    <Grid x:Name="WindowHeader"
                          DockPanel.Dock="Top"
                          Height="25">
                        <TextBlock Text="{TemplateBinding Title}"
                                   Margin=" 25 0 0 0"
                                   VerticalAlignment="Center" />
                    </Grid>
                    <ContentPresenter Margin="10 0 10 10" />
                </DockPanel >
            </Border >
            <ControlTemplate.Triggers>
                <Trigger Property="WindowState"
                         Value="Maximized">
                    <Setter TargetName="WindowHeader"
                            Property="Margin"
                            Value="6" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Window.Template>

    <shell:WindowChrome.WindowChrome>
        <shell:WindowChrome  GlassFrameThickness="-1"
                            ResizeBorderThickness="10"
                            CaptionHeight="30"
                            NonClientFrameEdges="Left,Bottom,Right"
                            CornerRadius="5" />
    </shell:WindowChrome.WindowChrome>

    <Grid>
        <Button VerticalAlignment="Stretch"
                HorizontalAlignment="Stretch"
                Content=" 按钮" />
    </Grid>

 

资源下载:

https://download.csdn.net/download/qq_43307934/10988890

参考地址:

[WPF]使用WindowChrome自定义Window Style

https://www.cnblogs.com/dino623/p/CustomWindowStyle.html

WPF 使用 WindowChrome,在自定义窗口标题栏的同时最大程度保留原生窗口样式

https://blog.csdn.net/WPwalter/article/details/81121829

WPF中Ribbon控件的使用 - Yang-Fei - 博客园

http://www.cnblogs.com/yang-fei/p/6021300.html

WPF 创建自定义窗体 - Yang-Fei - 博客园

http://www.cnblogs.com/yang-fei/p/4737308.html

Ribbon For WPF的使用 - Arthars - 博客园
http://www.cnblogs.com/Angle-Louis/archive/2012/12/11/2805738.html

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现这个功能,你需要按照以下步骤进行操作: 1. 创建一个 WPF 应用程序。 2. 在主窗口中设计一个按钮。 3. 创建一个新的 WPF 窗口用来显示自定义窗口内容。 4. 在按钮的点击事件中,实例化自定义窗口并显示出来。 下面是详细的步骤: 1. 创建一个 WPF 应用程序。 打开 Visual Studio,选择“文件”>“新建”>“项目”,在“新建项目”对话框中选择“WPF 应用程序”。 2. 在主窗口中设计一个按钮。 打开 MainWindow.xaml 文件,在窗口上添加一个按钮: ``` <Button Content="打开自定义窗口" Click="Button_Click"/> ``` 3. 创建一个新的 WPF 窗口用来显示自定义窗口内容。 在“解决方案资源管理器”中右键单击项目,选择“添加”>“新建项”,在“添加新项”对话框中选择“WPF 窗口”,命名为“CustomWindow.xaml”。 在 CustomWindow.xaml 中添加一些内容,如一个文本框: ``` <Grid> <TextBox Text="这是自定义窗口"/> </Grid> ``` 4. 在按钮的点击事件中,实例化自定义窗口并显示出来。 在 MainWindow.xaml.cs 文件中,添加以下代码: ``` private void Button_Click(object sender, RoutedEventArgs e) { CustomWindow customWindow = new CustomWindow(); customWindow.ShowDialog(); } ``` 这个代码在按钮的点击事件中实例化 CustomWindow 窗口,并通过 ShowDialog() 方法显示出来。 现在,你可以运行应用程序并点击按钮,就会弹出自定义窗口了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值