WPF自定义系统按钮

本文介绍了如何在WPF应用中自定义无边框窗口的系统按钮,通过使用图片按钮替换原有样式,实现美观的最小化、最大化和关闭按钮效果。详细展示了App.xaml、窗口XAML及后台.cs代码的实现过程。
摘要由CSDN通过智能技术生成
  1. 概述:

因为我要做的是无边框,且系统按钮与图标文字在同一水平背景上,原有的系统按钮太丑了,所以我重新自定义了最小化、最大化、关闭这三个系统按钮,用图片按钮切换来代替原有的:

效果如下图:

App.xaml页面代码:

<Application x:Class="WPF_Client.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:WPF_Client"
             StartupUri="LoginWindow.xaml">
    <Application.Resources>
        <!--自定义系统最小化button-->
        <Style x:Key="Minbtn" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid Cursor="Hand">
                            <Border x:Name="_Border" BorderBrush="Transparent" CornerRadius="5" BorderThickness="0">
                                <Border.Background>
                                    <ImageBrush ImageSource="Images/最小化.png"/>
                                </Border.Background>
                            </Border>
                            <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值