【WPF】自定义Windows窗口样式


前言

WPF中的很多控件都可以直接修改其样式,但对于Window控件,无法通过简单的style来修改其样式,本文提供了一个实现任意风格window的方法。


一、程序文件结构

为了实现任意风格的Window,就需要重写Window的默认模板,首先是创建Window的派生类,并创建自定义style,重写DefaultStyleKey属性将样式和Window派生类结合到一起。这里创建了一个WPF应用程序来实现,文件结构如下。
文件结构

二、具体实现

本文实现了两种自定义窗口,普通窗口PageWindow和对话框窗口DialogWindow。

1.资源文件generic.xaml代码

创建一个Themes文件夹,添加资源文件generic.xaml,因为微软对此进行了硬编码,必须建立这样的文件夹和文件,才能将自定义控件和默认样式协同工作。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:customWindow="clr-namespace:CustomSystemWindow.CustomWindow">
    <DataTemplate x:Key="RestoreWhite">
        <Grid UseLayoutRounding="True">
            <Path Data="M1,3 L1,11 L9,11 L9,3 z M3,1 L3,2 L10,2 L10,9 L11,9 L11,1 z M2 ,0 L12,0 L12,10 L10,10 L10,12 L0,12 L0,2 L2 ,2 z"
                  Width="12" Height="12" UseLayoutRounding="True"
                  VerticalAlignment="Center" HorizontalAlignment="Center" Fill="White" />
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="CloseWhite">
        <Grid UseLayoutRounding="True">
            <Path Data="M1,0 L6,5 L11,0 L12,1 L7,6 L12,11 L11,12 L6,7 L1,12 L0,11 L5,6 L0,1 z"
                  Width="12" Height="12" UseLayoutRounding="True"
                  VerticalAlignment="Center" HorizontalAlignment="Center" Fill="White" />
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="MaximizeWhite">
        <Grid>
            <Path Data="M1,1  L1 ,11 L11,11 L11,1 z M0,0 L12,0 L12,12 L0,12 z"
                  Width="12" Height="12" UseLayoutRounding="True"
                  VerticalAlignment="Center" HorizontalAlignment="Center" Fill="White" />
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="MinimizeWhite">
        <Grid>
            <Path Data="M0,5 L12,5 L12,6 L0,6 z"
                  Width="12" Height="12" UseLayoutRounding="True"
                  VerticalAlignment="Center" HorizontalAlignment="Center" Fill="White" />
        </Grid>
    </DataTemplate>

    <Style x:Key="TitleBarButtonFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Rectangle Margin="2" SnapsToDevicePixels="True" Stroke="Transparent"
                    	StrokeDashArray="1 2" StrokeThickness="1" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="TitleBarButtonStyle"
           TargetType="{x:Type Button}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Background" Value="#15181C" />
        <Setter Property="Width" Value="36" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid x:Name="LayoutRoot"
                          Background="Transparent">
                        <Border x:Name="ButtonBackground"
                                BorderBrush="Gray" BorderThickness="1"
                                Opacity="0" Height="30" Width="30"/>
                        <Border x:Name="ButtonBorder"
                                SnapsToDevicePixels="true">
                            <ContentPresenter 
                            x:Name="TitleBarButtonContentPresenter" Focusable="False"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            Margin="{TemplateBinding Padding}" RecognizesAccessKey="True"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                        </Border>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Opacity" Value="1" TargetName="ButtonBackground" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Opacity" Value="0.6" TargetName="ButtonBackground" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="TitleBarButtonContentPresenter" Property="Opacity" Value=".5" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type customWindow:CustomWindow}">
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
        <Setter Property="Background" Value="#FFF1F1F1" />
        <Setter Property="BorderBrush" Value="#15181C" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="ResizeMode" Value="CanResizeWithGrip" />
        <Setter Property="UseLayoutRounding" Value="True" />
        <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
        <Setter Property="WindowStyle" Value="SingleBorderWindow" />
        <Setter Property="WindowChrome.WindowChrome">
            <Setter.Value>
                <WindowChrome CornerRadius="0" GlassFrameThickness="1"
                              UseAeroCaptionButtons="False" NonClientFrameEdges="None" />
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type customWindow:CustomWindow}">
                    <Border x:Name="WindowBorder">
                        <Grid Background="#FF15181C">
                            <Border VerticalAlignment="Top" Height="40">
                                <Border.Background>
                                    <LinearGradientBrush StartPoint="0.5,1" EndPoint="0.5,0">
                                        <GradientStop Color="#2B313B" Offset="1"/>
                                        <GradientStop Color="#181B21" Offset="0"/>
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                            <Grid x:Name="LayoutRoot" Margin="30,0,30,30" Background="{TemplateBinding Background}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <Grid x:Name="PART_WindowTitleGrid" Grid.Row="0" Height="40">
                                    <Grid.Background>
                                        <LinearGradientBrush StartPoint="0.5,1" EndPoint="0.5,0">
                                            <GradientStop Color="#2B313B" Offset="1"/>
                                            <GradientStop Color="#181B21" Offset="0"/>
                                        </LinearGradientBrush>
                                    </Grid.Background>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="36" />
                                    </Grid.ColumnDefinitions>
                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                        <Button VerticalAlignment="Center"
                                            Margin="7,0,5,0" Content="{TemplateBinding Icon}"
                                            Height="{x:Static SystemParameters.SmallIconHeight}"
                                            Width="{x:Static SystemParameters.SmallIconWidth}"
                                            WindowChrome.IsHitTestVisibleInChrome="True"
                                            IsTabStop="False">
                                            <Button.Template>
                                                <ControlTemplate TargetType="{x:Type Button}">
                                                    <Image Source="{TemplateBinding Content}" />
                                                </ControlTemplate>
                                            </Button.Template>
                                            <!--<i:Interaction.Triggers>
                                            <i:EventTrigger EventName="Click">
                                                <i:InvokeCommandAction Command="{x:Static SystemCommands.ShowSystemMenuCommand}" />
                                            </i:EventTrigger>
                                            <i:EventTrigger EventName="MouseDoubleClick">
                                                <i:InvokeCommandAction Command="{x:Static SystemCommands.CloseWindowCommand}" />
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>-->
                                        </Button>
                                        <ContentControl IsTabStop="False" Foreground="White"
                                                    HorizontalAlignment="Center" VerticalAlignment="Center"
                                                    HorizontalContentAlignment="Center" 
                                                    FontSize="16" FontFamily="Arial-BoldMT"
                                                    Content="{TemplateBinding Title}" />
                                    </StackPanel>
                                    <StackPanel x:Name="WindowCommandButtonsStackPanel"
                                            Grid.Column="1"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Stretch"
                                            Background="Transparent"
                                            Orientation="Horizontal"
                                            WindowChrome.IsHitTestVisibleInChrome="True"
                                            Margin="0,-1,-1,0">
                                        <Button x:Name="Minimize"
                                            ToolTip="Minimize"
                                            WindowChrome.IsHitTestVisibleInChrome="True"
                                            Command="{Binding Source={x:Static SystemCommands.MinimizeWindowCommand}}"
                                            ContentTemplate="{StaticResource MinimizeWhite}"
                                            Style="{StaticResource TitleBarButtonStyle}"
                                            IsTabStop="False" />
                                        <Grid Margin="1,0,1,0">
                                            <Button x:Name="Restore"
                                                ToolTip="Restore"
                                                WindowChrome.IsHitTestVisibleInChrome="True"
                                                Command="{Binding Source={x:Static SystemCommands.RestoreWindowCommand}}"
                                                ContentTemplate="{StaticResource RestoreWhite}"
                                                Style="{StaticResource TitleBarButtonStyle}"
                                                Visibility="Collapsed" IsTabStop="False" />
                                            <Button x:Name="Maximize" ToolTip="Maximize"
                                                WindowChrome.IsHitTestVisibleInChrome="True"
                                                Command="{Binding Source={x:Static SystemCommands.MaximizeWindowCommand}}"
                                                ContentTemplate="{StaticResource MaximizeWhite}"
                                                Style="{StaticResource TitleBarButtonStyle}"
                                                IsTabStop="False" />
                                        </Grid>
                                        <Button x:Name="Close"
                                            ToolTip="Close" Background="Red"
                                            WindowChrome.IsHitTestVisibleInChrome="True"
                                            Command="{Binding Source={x:Static SystemCommands.CloseWindowCommand}}"
                                            ContentTemplate="{StaticResource CloseWhite}"
                                            Style="{StaticResource TitleBarButtonStyle}"
                                            IsTabStop="False" />
                                    </StackPanel>
                                </Grid>
                                <AdornerDecorator Grid.Row="1" KeyboardNavigation.IsTabStop="False">
                                    <ContentControl Content="{TemplateBinding Content}" x:Name="MainContentPresenter"/>
                                </AdornerDecorator>
                                <ResizeGrip x:Name="ResizeGrip"
                                        HorizontalAlignment="Right" VerticalAlignment="Bottom"
                                        Grid.Row="1" IsTabStop="False" Visibility="Hidden"
                                        WindowChrome.ResizeGripDirection="BottomRight" />
                            </Grid>
                        </Grid>
                    </Border>

                    <ControlTemplate.Triggers>
                        <!--<Trigger Property="IsActive" Value="False">
                            <Setter Property="BorderBrush" Value="#FF6F7785" />
                        </Trigger>-->
                        <Trigger Property="WindowState" Value="Maximized">
                            <Setter TargetName="Maximize" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="Restore" Property="Visibility" Value="Visible" />
                            <Setter TargetName="LayoutRoot" Property="Margin" Value="7" />
                        </Trigger>
                        <Trigger Property="WindowState" Value="Normal">
                            <Setter TargetName="Maximize" Property="Visibility" Value="Visible" />
                            <Setter TargetName="Restore" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="ResizeMode" Value="NoResize">
                            <Setter TargetName="Minimize" Property="Visibility"  Value="Collapsed" />
                            <Setter TargetName="Maximize" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="Restore" Property="Visibility" Value="Collapsed" />
                        </Trigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="ResizeMode" Value="CanResizeWithGrip" />
                                <Condition Property="WindowState" Value="Normal" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ResizeGrip" Property="Visibility"  Value="Visible" />
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

2.Window派生类CustomWindow.cs

using System;
using System.Windows;
using System.Windows.Input;

namespace CustomSystemWindow.CustomWindow
{
    public class CustomWindow : Window
    {
        public CustomWindow()
        {
            DefaultStyleKey = typeof(CustomWindow);
            CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, CloseWindow));
            CommandBindings.Add(new CommandBinding(SystemCommands.MaximizeWindowCommand, MaximizeWindow, CanResizeWindow));
            CommandBindings.Add(new CommandBinding(SystemCommands.MinimizeWindowCommand, MinimizeWindow, CanMinimizeWindow));
            CommandBindings.Add(new CommandBinding(SystemCommands.RestoreWindowCommand, RestoreWindow, CanResizeWindow));
            CommandBindings.Add(new CommandBinding(SystemCommands.ShowSystemMenuCommand, ShowSystemMenu));
        }

        public event Action CloseWindowEvent;

        //protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        //{
        //    base.OnMouseLeftButtonDown(e);
        //    if (e.ButtonState == MouseButtonState.Pressed)
        //        DragMove();
        //}

        protected override void OnContentRendered(EventArgs e)
        {
            base.OnContentRendered(e);
            if (SizeToContent == SizeToContent.WidthAndHeight)
                InvalidateMeasure();
        }

        private void CanResizeWindow(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = ResizeMode == ResizeMode.CanResize || ResizeMode == ResizeMode.CanResizeWithGrip;
        }

        private void CanMinimizeWindow(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = ResizeMode != ResizeMode.NoResize;
        }

        private void CloseWindow(object sender, ExecutedRoutedEventArgs e)
        {
            if (null != CloseWindowEvent)
            {
                CloseWindowEvent();
            }
            this.Close();
        }

        private void MaximizeWindow(object sender, ExecutedRoutedEventArgs e)
        {
            SystemCommands.MaximizeWindow(this);
        }

        private void MinimizeWindow(object sender, ExecutedRoutedEventArgs e)
        {
            SystemCommands.MinimizeWindow(this);
        }

        private void RestoreWindow(object sender, ExecutedRoutedEventArgs e)
        {
            SystemCommands.RestoreWindow(this);
        }

        private void ShowSystemMenu(object sender, ExecutedRoutedEventArgs e)
        {
            var element = e.OriginalSource as FrameworkElement;
            if (element == null)
                return;

            var point = WindowState == WindowState.Maximized ? new Point(0, element.ActualHeight)
                : new Point(Left + BorderThickness.Left, element.ActualHeight + Top + BorderThickness.Top);
            point = element.TransformToAncestor(this).Transform(point);
            SystemCommands.ShowSystemMenu(this, point);
        }
    }
}

3、普通窗口

  1. 前端代码PageWindow.xaml
<local:CustomWindow x:Class="CustomSystemWindow.CustomWindow.PageWindow"
        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:CustomSystemWindow.CustomWindow"
        mc:Ignorable="d" Title="PageWindow" Height="300" Width="600">
</local:CustomWindow>
  1. 后端代码PageWindow.xaml.cs

4、对话框窗口

  1. 前端代码DialogWindow.xaml
<local:CustomWindow x:Class="CustomSystemWindow.CustomWindow.DialogWindow"
        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:CustomSystemWindow.CustomWindow"
        mc:Ignorable="d" Title="DialogWindow" Height="250" Width="460" >
    <Border Background="#15181C">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="120"></RowDefinition>
                <RowDefinition Height="90"></RowDefinition>
            </Grid.RowDefinitions>
            <TextBlock x:Name="MessageControl" Grid.Row="0" 
                       FontSize="14" Foreground="White" TextWrapping="Wrap"
                       VerticalAlignment="Center" HorizontalAlignment="Center"/>
            <Border Grid.Row="0" BorderBrush="#252A33" BorderThickness="1" 
                    VerticalAlignment="Bottom"></Border>
            <Grid Grid.Row="1" x:Name="YesNoControl" Visibility="Visible">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Button Grid.Column="0" HorizontalAlignment="Right" 
                        Height="30" Width="150" Content="" Foreground="White" 
                        Margin="0,0,10,0" Background="#434B59"
                        Click="OkButtonClick"/>
                <Button Grid.Column="1" HorizontalAlignment="Left"
                        Height="30" Width="150" Content="" Foreground="White" 
                        Margin="10,0,0,0" Background="#434B59"
                        Click="CancelButtonClick"/>
            </Grid>
            <Button Grid.Row="1" x:Name="OkControl" Visibility="Collapsed"
                    Height="30" Width="150" Content="确认" 
                    Foreground="White" Background="#434B59"
                    Click="ConfirmButtonClick"/>
        </Grid>
    </Border>
</local:CustomWindow>

  1. 后端代码DialogWindow.xaml.cs
using System.Windows;

namespace CustomSystemWindow.CustomWindow
{
    public partial class DialogWindow
    {
        public DialogWindow()
        {
            InitializeComponent();
        }

        public string Message
        {
            set { this.MessageControl.Text = value; }
            get { return this.MessageControl.Text; }
        }

        public static bool? Show(string title, string msg, MessageBoxButton category)
        {
            var msgBox = new DialogWindow();
            if (MessageBoxButton.OK == category)
            {
                msgBox.YesNoControl.Visibility = Visibility.Collapsed;
                msgBox.OkControl.Visibility = Visibility.Visible;
            }
            else if (MessageBoxButton.YesNo == category)
            {
                msgBox.YesNoControl.Visibility = Visibility.Visible;
                msgBox.OkControl.Visibility = Visibility.Collapsed;
            }

            msgBox.ResizeMode = ResizeMode.NoResize;
            msgBox.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            msgBox.Title = title;
            msgBox.Message = msg;

            return msgBox.ShowDialog();
        }

        private void OkButtonClick(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void CancelButtonClick(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        private void ConfirmButtonClick(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}

五、实现效果

  1. 普通窗口
    在这里插入图片描述

  2. 对话框窗口
    在这里插入图片描述
    代码路径:https://download.csdn.net/download/m0_38045338/14953045

    参考1:https://blog.csdn.net/gentle_wolf/article/details/5908340
    参考2:https://www.cnblogs.com/s0611163/p/9994529.html

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
自定义 WPF ComboBox 的样式,步骤如下: 1. 创建一个新的 WPF 项目。 2. 在项目中打开 MainWindow.xaml 文件。 3. 在窗口中添加一个 ComboBox 控件。 4. 在 ComboBox 控件中添加一些项。 ```xml <ComboBox> <ComboBoxItem>Item 1</ComboBoxItem> <ComboBoxItem>Item 2</ComboBoxItem> <ComboBoxItem>Item 3</ComboBoxItem> </ComboBox> ``` 5. 现在我们将使用模板来自定义 ComboBox 的样式。右键单击 ComboBox 控件,选择“编辑模板”->“编辑复制的模板”->“创建”。 6. 在“对象和时间线”窗口中,找到名为“ComboBox”的控件模板。 7. 在模板中找到“Border”元素,并添加以下属性: ```xml <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3"> ``` 8. 在“ToggleButton”元素中添加以下属性: ```xml <ToggleButton x:Name="toggleButton" Grid.Column="2" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Template="{StaticResource ComboBoxToggleButton}"/> ``` 这将在 ComboBox 上添加一个箭头按钮。 9. 在“Popup”元素中添加以下属性,以更改下拉列表的背景颜色: ```xml <Popup x:Name="popup" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide"> <Grid x:Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}"> <Border x:Name="DropDownBorder" Background="White" BorderThickness="1" BorderBrush="Black" CornerRadius="3"/> <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True"> <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained"/> </ScrollViewer> </Grid> </Popup> ``` 10. 最后,添加以下样式到项目中: ```xml <Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ToggleButton}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition Width="20"/> </Grid.ColumnDefinitions> <Border x:Name="Border" Grid.ColumnSpan="2" CornerRadius="3" BorderThickness="1,1,1,1" Background="White" BorderBrush="Black"/> <Border Grid.Column="0" CornerRadius="3" Margin="1" Background="{TemplateBinding Background}" BorderThickness="0,0,0,0"/> <Path x:Name="Arrow" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 4 4 L 8 0 Z" Fill="Black"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="ToggleButton.IsChecked" Value="True"> <Setter TargetName="Border" Property="Background" Value="#FFC1E0FF"/> <Setter TargetName="Border" Property="BorderBrush" Value="#FFA5CBE2"/> <Setter TargetName="Arrow" Property="Fill" Value="#FF000000"/> </Trigger> <Trigger Property="UIElement.IsEnabled" Value="False"> <Setter TargetName="Border" Property="Background" Value="#FFF4F4F4"/> <Setter TargetName="Border" Property="BorderBrush" Value="#FFADB2B5"/> <Setter TargetName="Arrow" Property="Fill" Value="#FF808080"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> ``` 11.运行程序,现在你将看到一个美丽的自定义 ComboBox 样式。 希望这能帮助到你!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

woniudaidai

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值