WPF自定义控件库之Window窗口

news2024/9/19 11:04:04

在WPF开发中,默认控件的样式常常无法满足实际的应用需求,我们通常都会采用引入第三方控件库的方式来美化UI,使得应用软件的设计风格更加统一。常用的WPF的UI控件库主要有以下几种,如:Modern UI for WPFMaterialDesignInXamlToolkit,PanuonUI,Newbeecoder.UI,WPF UI ,AduSkinPanuon.UI.SilverHandyControlMahApps.Metro,Kino.Toolkit.Wpf,Xceed Extended WPF Toolkit™,Kino.Toolkit.Wpf,PP.Wpf,Adonis-ui,CC.WPFTools,CookPopularControl ,PropertyTools,RRQMSkin,Layui-WPF,Arthas-WPFUI,fruit-vent-design,Fluent.Ribbon,DMSkin WPF,EASkins_WPF,Rubyer-WPF,WPFDevelopers.Minimal ,WPFDevelopers,DevExpress WPF UI Library,ReactiveUI,Telerik UI for WPF等等,面对如此之多的WPF 第三方UI控件库,可谓各有特色,不一而同,对于具有选择综合症的开发人员来说,真的很难抉择。在实际工作中,软件经过统一的UI设计以后,和具体的业务紧密相连,往往这些通用的UI框架很难百分之百的契合,这时候,就需要我们自己去实现自定义控件【Custom Control】来解决。本文以自定义窗口为例,简述如何通过自定义控件来扩展功能和样式,仅供学习分享使用,如有不足之处,还请指正。

自定义控件

自定义控件Custom Control,通过集成现有控件(如:Button , Window等)进行扩展,或者继承Control基类两种方式,和用户控件【User Control不太相同】,具体差异如下所示:

  • 用户控件UserControl
    1. 注重复合控件的使用,也就是多个现有控件组成一个可复用的控件组
    2. XAML和后台代码组成,绑定紧密
    3. 不支持模板重写
    4. 继承自UserControl
  • 自定义控件CustomControl
    1. 完全自己实现一个控件,如继承现有控件进行功能扩展,并添加新功能
    2. 后台代码和Generic.xaml进行组合
    3. 在使用时支持模板重写
    4. 继承自Control

本文所讲解的侧重点为自定义控件,所以用户控件不再过多阐述。

WPF实现自定义控件步骤

1. 创建控件库

首先在解决方案中,创建一个WPF类库项目【SmallSixUI.Templates】,作为控件库,后续所有自定义控件,都可以在此项目中开发。并创建Controls,Styles,Themes,Utils等文件夹,分别存放控件类,样式,主题,帮助类等内容,作为控件库的基础结构,如下所示:

2. 创建自定义控件

在Controls目录中,创建自定义窗口AiWindow,继承自Window类,即此类具有窗口的一切功能,并具有扩展出来的自定义功能。在此自定义窗口中,我们可以自定义窗口标题的字体颜色HeaderForeground,背景色HeaderBackground,是否显示标题IsShowHeader,标题高度HeaderHeight,窗口动画类型Type等内容,具体如下所示:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Automation.Text;
using System.Windows;
using SmallSixUI.Templates.Utils;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shell;
 
namespace SmallSixUI.Templates.Controls
{
    [TemplatePart(Name = "PART_CloseWindowButton", Type = typeof(Button))]
    [TemplatePart(Name = "PART_MaxWindowButton", Type = typeof(Button))]
    [TemplatePart(Name = "PART_MinWindowButton", Type = typeof(Button))]
    public class AiWindow : Window
    {
        /// <summary>
        /// 关闭窗体
        /// </summary>
        private Button PART_CloseWindowButton = null;
        /// <summary>
        /// 窗体缩放
        /// </summary>
        private Button PART_MaxWindowButton = null;
        /// <summary>
        /// 最小化窗体
        /// </summary>
        private Button PART_MinWindowButton = null;
 
        /// <summary>
        /// 设置重写默认样式
        /// </summary>
        static AiWindow()
        {
            StyleProperty.OverrideMetadata(typeof(AiWindow), new FrameworkPropertyMetadata(AiResourceHelper.GetStyle(nameof(AiWindow) + "Style")));
        }
 
 
        /// <summary>
        /// 顶部内容
        /// </summary>
        [Bindable(true)]
        public object HeaderContent
        {
            get { return (object)GetValue(HeaderContentProperty); }
            set { SetValue(HeaderContentProperty, value); }
        }
 
        // Using a DependencyProperty as the backing store for HeaderContent.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HeaderContentProperty =
            DependencyProperty.Register("HeaderContent", typeof(object), typeof(AiWindow));
 
 
        /// <summary>
        /// 头部标题栏文字颜色
        /// </summary>
        [Bindable(true)]
        public Brush HeaderForeground
        {
            get { return (Brush)GetValue(HeaderForegroundProperty); }
            set { SetValue(HeaderForegroundProperty, value); }
        }
 
        // Using a DependencyProperty as the backing store for HeaderForeground.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HeaderForegroundProperty =
            DependencyProperty.Register("HeaderForeground", typeof(Brush), typeof(AiWindow), new PropertyMetadata(Brushes.White));
 
 
        /// <summary>
        /// 头部标题栏背景色
        /// </summary>
        [Bindable(true)]
        public Brush HeaderBackground
        {
            get { return (Brush)GetValue(HeaderBackgroundProperty); }
            set { SetValue(HeaderBackgroundProperty, value); }
        }
 
        // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HeaderBackgroundProperty =
            DependencyProperty.Register("HeaderBackground", typeof(Brush), typeof(AiWindow));
        /// <summary>
        /// 是否显示头部标题栏
        /// </summary>
        [Bindable(true)]
        public bool IsShowHeader
        {
            get { return (bool)GetValue(IsShowHeaderProperty); }
            set { SetValue(IsShowHeaderProperty, value); }
        }
 
        // Using a DependencyProperty as the backing store for IsShowHeader.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsShowHeaderProperty =
            DependencyProperty.Register("IsShowHeader", typeof(bool), typeof(AiWindow), new PropertyMetadata(false));
 
        /// <summary>
        /// 动画类型
        /// </summary>
        [Bindable(true)]
        public AnimationType Type
        {
            get { return (AnimationType)GetValue(TypeProperty); }
            set { SetValue(TypeProperty, value); }
        }
 
        // Using a DependencyProperty as the backing store for Type.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TypeProperty =
            DependencyProperty.Register("Type", typeof(AnimationType), typeof(AiWindow), new PropertyMetadata(AnimationType.Default));
 
 
 
        /// <summary>
        /// 头部高度
        /// </summary>
        public int HeaderHeight
        {
            get { return (int)GetValue(HeaderHeightProperty); }
            set { SetValue(HeaderHeightProperty, value); }
        }
 
        // Using a DependencyProperty as the backing store for HeaderHeight.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HeaderHeightProperty =
            DependencyProperty.Register("HeaderHeight", typeof(int), typeof(AiWindow), new PropertyMetadata(50));
 
 
 
 
 
 
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            PART_CloseWindowButton = GetTemplateChild("PART_CloseWindowButton") as Button;
            PART_MaxWindowButton = GetTemplateChild("PART_MaxWindowButton") as Button;
            PART_MinWindowButton = GetTemplateChild("PART_MinWindowButton") as Button;
            if (PART_MaxWindowButton != null && PART_MinWindowButton != null && PART_CloseWindowButton != null)
            {
                PART_MaxWindowButton.Click -= PART_MaxWindowButton_Click;
                PART_MinWindowButton.Click -= PART_MinWindowButton_Click;
                PART_CloseWindowButton.Click -= PART_CloseWindowButton_Click;
                PART_MaxWindowButton.Click += PART_MaxWindowButton_Click;
                PART_MinWindowButton.Click += PART_MinWindowButton_Click;
                PART_CloseWindowButton.Click += PART_CloseWindowButton_Click;
            }
        }
 
        private void PART_CloseWindowButton_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
 
        private void PART_MinWindowButton_Click(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Minimized;
        }
 
        private void PART_MaxWindowButton_Click(object sender, RoutedEventArgs e)
        {
            if (WindowState == WindowState.Normal)
            {
                WindowState = WindowState.Maximized;
            }
            else
            {
                WindowState = WindowState.Normal;
            }
        }
 
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);
            if (SizeToContent == SizeToContent.WidthAndHeight && WindowChrome.GetWindowChrome(this) != null)
            {
                InvalidateMeasure();
            }
        }
    }
}

注意:在自定义控件中,设置窗口标题的属性要在样式中进行绑定,所以需要定义为依赖属性。在此控件中用到的通用的类,则存放在Utils中。

3. 创建自定义控件样式

在Styles文件夹中,创建样式资源文件【AiWindowStyle.xaml】,并将样式的TargentType指定为Cotrols中创建的自定义类AiWindow。然后修改控件的Template属性,为其定义新的的ControlTemplate,来改变控件的样式。如下所示:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Ai="clr-namespace:SmallSixUI.Templates.Controls">
    <WindowChrome
        x:Key="LayWindowChromeStyle"
        CaptionHeight="56"
        CornerRadius="0"
        GlassFrameThickness="1"
        NonClientFrameEdges="None"
        ResizeBorderThickness="4"
        UseAeroCaptionButtons="False" />
    <Style x:Key="AiWindowStyle" TargetType="Ai:AiWindow">
        <Setter Property="Background" Value="White" />
        <Setter Property="HeaderBackground" Value="#23262E" />
        <Setter Property="WindowChrome.WindowChrome">
            <Setter.Value>
                <WindowChrome
                    CaptionHeight="50"
                    CornerRadius="0"
                    GlassFrameThickness="1"
                    NonClientFrameEdges="None"
                    ResizeBorderThickness="4"
                    UseAeroCaptionButtons="False" />
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Ai:AiWindow">
                    <Border
                        Height="{TemplateBinding HeaderHeight}"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        ClipToBounds="True">
                        <Border.Style>
                            <Style TargetType="Border">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Ai:AiWindow}, Path=WindowState}" Value="Maximized">
                                        <Setter Property="Padding" Value="7" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Border.Style>
                        <Ai:AiTransition Style="{DynamicResource LayTransitionStyle}" Type="{TemplateBinding Type}">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="auto" />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <Grid
                                    x:Name="PART_Header"
                                    Background="{TemplateBinding HeaderBackground}">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto" />
                                        <ColumnDefinition Width="auto" />
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="auto" />
                                    </Grid.ColumnDefinitions>
                                    <Image
                                        x:Name="Icon"
                                        Width="32"
                                        Height="32"
                                        Margin="5"
                                        Source="{TemplateBinding Icon}"
                                        Stretch="Fill" />
                                    <TextBlock
                                        x:Name="HeaderText"
                                        Grid.Column="1"
                                        Margin="5,0"
                                        FontSize="13"
                                        VerticalAlignment="Center"
                                        Foreground="{TemplateBinding HeaderForeground}"
                                        Text="{TemplateBinding Title}" />
                                    <ContentPresenter
                                        Grid.Column="2"
                                        ContentSource="HeaderContent"
                                        WindowChrome.IsHitTestVisibleInChrome="true" />
                                    <StackPanel Grid.Column="3" Orientation="Horizontal">
                                        <StackPanel.Resources>
                                            <ControlTemplate x:Key="WindowButtonTemplate" TargetType="Button">
                                                <Grid x:Name="body" Background="Transparent">
                                                    <Border
                                                        Margin="3"
                                                        Background="Transparent"
                                                        WindowChrome.IsHitTestVisibleInChrome="True" />
                                                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                                </Grid>
                                                <ControlTemplate.Triggers>
                                                    <Trigger Property="IsMouseOver" Value="True">
                                                        <Setter TargetName="body" Property="Background">
                                                            <Setter.Value>
                                                                <SolidColorBrush Opacity="0.1" Color="Black" />
                                                            </Setter.Value>
                                                        </Setter>
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </StackPanel.Resources>
                                        <Button
                                            x:Name="PART_MinWindowButton"
                                            Width="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ActualHeight}"
                                            Cursor="Hand"
                                            Template="{DynamicResource WindowButtonTemplate}">
                                            <Path
                                                Width="15"
                                                Height="2"
                                                Data="M772.963422 533.491105l-528.06716 0c-12.38297 0-22.514491-10.131521-22.514491-22.514491l0 0c0-12.38297 10.131521-22.514491 22.514491-22.514491l528.06716 0c12.38297 0 22.514491 10.131521 22.514491 22.514491l0 0C795.477913 523.359584 785.346392 533.491105 772.963422 533.491105z"
                                                Fill="{TemplateBinding HeaderForeground}"
                                                IsHitTestVisible="false"
                                                Stretch="Fill" />
                                        </Button>
                                        <Button
                                            x:Name="PART_MaxWindowButton"
                                            Width="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ActualHeight}"
                                            Cursor="Hand"
                                            Template="{DynamicResource WindowButtonTemplate}">
                                            <Path
                                                x:Name="winCnangePath"
                                                Width="15"
                                                Height="15"
                                                Data="M10.62,72a9.92,9.92,0,0,1-4-.86A11.15,11.15,0,0,1,.86,65.43,9.92,9.92,0,0,1,0,61.38V25A9.86,9.86,0,0,1,.86,21,11.32,11.32,0,0,1,3.18,17.6a11,11,0,0,1,3.38-2.32,9.68,9.68,0,0,1,4.06-.87H47a9.84,9.84,0,0,1,4.08.87A11,11,0,0,1,56.72,21,9.84,9.84,0,0,1,57.59,25V61.38a9.68,9.68,0,0,1-.87,4.06,11,11,0,0,1-2.32,3.38A11.32,11.32,0,0,1,51,71.14,9.86,9.86,0,0,1,47,72Zm36.17-7.21a3.39,3.39,0,0,0,1.39-.28,3.79,3.79,0,0,0,1.16-.77,3.47,3.47,0,0,0,1.07-2.53v-36a3.55,3.55,0,0,0-.28-1.41,3.51,3.51,0,0,0-.77-1.16,3.67,3.67,0,0,0-1.16-.77,3.55,3.55,0,0,0-1.41-.28h-36a3.45,3.45,0,0,0-1.39.28,3.59,3.59,0,0,0-1.14.79,3.79,3.79,0,0,0-.77,1.16,3.39,3.39,0,0,0-.28,1.39v36a3.45,3.45,0,0,0,.28,1.39A3.62,3.62,0,0,0,9.4,64.51a3.45,3.45,0,0,0,1.39.28Zm18-43.45a13.14,13.14,0,0,0-1.16-5.5,14.41,14.41,0,0,0-3.14-4.5,15,15,0,0,0-4.61-3,14.14,14.14,0,0,0-5.5-1.1H15A10.73,10.73,0,0,1,21.88.51,10.93,10.93,0,0,1,25.21,0H50.38a20.82,20.82,0,0,1,8.4,1.71A21.72,21.72,0,0,1,70.29,13.18,20.91,20.91,0,0,1,72,21.59v25.2a10.93,10.93,0,0,1-.51,3.33A10.71,10.71,0,0,1,70,53.05a10.84,10.84,0,0,1-2.28,2.36,10.66,10.66,0,0,1-3,1.58Z"
                                                Fill="{TemplateBinding HeaderForeground}"
                                                IsHitTestVisible="false"
                                                Stretch="Fill" />
                                        </Button>
                                        <Button
                                            x:Name="PART_CloseWindowButton"
                                            Width="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ActualHeight}"
                                            Cursor="Hand"
                                            Template="{DynamicResource WindowButtonTemplate}">
                                            <Path
                                                Width="15"
                                                Height="15"
                                                Data="M550.848 502.496l308.64-308.896a31.968 31.968 0 1 0-45.248-45.248l-308.608 308.896-308.64-308.928a31.968 31.968 0 1 0-45.248 45.248l308.64 308.896-308.64 308.896a31.968 31.968 0 1 0 45.248 45.248l308.64-308.896 308.608 308.896a31.968 31.968 0 1 0 45.248-45.248l-308.64-308.864z"
                                                Fill="{TemplateBinding HeaderForeground}"
                                                IsHitTestVisible="false"
                                                Stretch="Fill" />
                                        </Button>
                                    </StackPanel>
                                </Grid>
                                <Grid Grid.Row="1" ClipToBounds="True">
                                    <ContentPresenter />
                                </Grid>
                            </Grid>
                        </Ai:AiTransition>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="WindowState" Value="Normal">
                            <Setter TargetName="winCnangePath" Property="Data" Value="M10.62,72a9.92,9.92,0,0,1-4-.86A11.15,11.15,0,0,1,.86,65.43,9.92,9.92,0,0,1,0,61.38V10.62a9.92,9.92,0,0,1,.86-4A11.15,11.15,0,0,1,6.57.86a9.92,9.92,0,0,1,4-.86H61.38a9.92,9.92,0,0,1,4.05.86,11.15,11.15,0,0,1,5.71,5.71,9.92,9.92,0,0,1,.86,4V61.38a9.92,9.92,0,0,1-.86,4.05,11.15,11.15,0,0,1-5.71,5.71,9.92,9.92,0,0,1-4.05.86Zm50.59-7.21a3.45,3.45,0,0,0,1.39-.28,3.62,3.62,0,0,0,1.91-1.91,3.45,3.45,0,0,0,.28-1.39V10.79a3.45,3.45,0,0,0-.28-1.39A3.62,3.62,0,0,0,62.6,7.49a3.45,3.45,0,0,0-1.39-.28H10.79a3.45,3.45,0,0,0-1.39.28A3.62,3.62,0,0,0,7.49,9.4a3.45,3.45,0,0,0-.28,1.39V61.21a3.45,3.45,0,0,0,.28,1.39A3.62,3.62,0,0,0,9.4,64.51a3.45,3.45,0,0,0,1.39.28Z" />
                        </Trigger>
                        <Trigger Property="IsShowHeader" Value="false">
                            <Setter TargetName="PART_Header" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="ResizeMode" Value="NoResize">
                            <Setter TargetName="PART_MaxWindowButton" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="Icon" Value="{x:Null}">
                            <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger SourceName="HeaderText" Property="Text" Value="">
                            <Setter TargetName="HeaderText" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger SourceName="HeaderText" Property="Text" Value="{x:Null}">
                            <Setter TargetName="HeaderText" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

4. 创建默认主题

在Themes文件夹中,创建主题资源文件【Generic.xaml】,并在主题资源文件中,引用上述创建的样式资源,如下所示:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/SmallSixUI.Templates;component/Styles/AiWindowStyle.xaml"></ResourceDictionary>
        <ResourceDictionary Source="pack://application:,,,/SmallSixUI.Templates;component/Styles/AiTransitionStyle.xaml"></ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

主题:主题资源文件,是为了整合一组资源样式,来形成一套主题。同一主题之内,风格统一;不同主题之间相互独立,风格迥异

应用自定义控件库

1. 创建应用程序

在解决方案中,创建WPF应用程序【SmallSixUI.App】,并引用控件库【SmallSixUI.Templates】,如下所示:

2. 引入主题资源

在应用程序的启动类App.xaml中,引入主题资源文件,如下所示:

<Application x:Class="SmallSixUI.App.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:SmallSixUI.App"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/SmallSixUI.Templates;component/Themes/Generic.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

3. 创建测试窗口

在应用程序中,创建测试窗口【SmallSixWindow.xaml】,添加控件库命名控件【Ai】,并修改窗口的继承类为【AiWindow】,然后设置窗口的背景色,logo,标题等,如下所示:

SmallSixWindow.xaml文件中,如下所示:

<Ai:AiWindow x:Class="SmallSixUI.App.SmallSixWindow"
        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:Ai="clr-namespace:SmallSixUI.Templates.Controls;assembly=SmallSixUI.Templates"
        xmlns:local="clr-namespace:SmallSixUI.App"
        mc:Ignorable="d"
        IsShowHeader="True"
        HeaderBackground="#446180"
        HeaderHeight="80"
        Icon="logo.png" 
        Title="小六公子的UI设计窗口" Height="450" Width="800">
    <Grid>
        
    </Grid>
</Ai:AiWindow>

 SmallSixWindow.xaml.cs中修改继承类,如下所示:

using SmallSixUI.Templates.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
 
namespace SmallSixUI.App
{
    /// <summary>
    /// XWindow.xaml 的交互逻辑
    /// </summary>
    public partial class SmallSixWindow : AiWindow
    {
        public SmallSixWindow()
        {
            InitializeComponent();
        }
    }
}

运行程序

通过Visual Studio运行程序,如下所示:

普通默认窗口,如下所示:

自定义窗口

应用自定义样式的窗口,如下所示:

以上就是WPF自定义控件库之窗口的全部内容。希望可以抛砖引玉,一起学习,共同进步。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1153867.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

IDEA配置类、方法注释模板

一、打开 IDEA 的 Settings&#xff0c;点击 Editor–>File and Code Templates&#xff0c;点击右边 File 选项卡下面的 Class&#xff0c;在其中添加图中红框内的内容&#xff1a; /** * author li-kun * date ${YEAR}年${MONTH}月${DAY}日 ${TIME} */当你创建一个新的类…

考试成绩这样分发

老师们&#xff0c;还在为每次繁琐的成绩查询而头痛&#xff1f;今天我就要给大家带来一个超级实用的教程&#xff0c;让你轻松解决这个问题&#xff01; 我来介绍一下这个神秘的“成绩查询页面”。别以为它很复杂&#xff0c;其实它就是一个简单的网页&#xff0c;上面会有每个…

深入探索 C++ 多态 ① - 虚函数调用链路

前言 最近翻阅侯捷先生的两本书&#xff1a;&#xff08;翻译&#xff09;《深度探索 C 对象模型》 和 《C 虚拟与多态》&#xff0c;获益良多。 要理解多态的工作原理&#xff0c;得理解这几个知识点的关系&#xff1a;虚函数、虚函数表、虚函数指针、以及对象的 内存布局。…

【骑行贝丘渔场】一场与海的邂逅,一段难忘的旅程

在这个渐凉的秋日&#xff0c;我们校长骑行队一行人骑着自行车&#xff0c;从大观公园门口出发&#xff0c;开始了一段别开生面的海滩之旅。沿途穿越草海隧道湿地公园、迎海路、海埂公园西门&#xff08;第二集合点&#xff09;、宝丰湿地公园、斗南湿地公园、蓝光城&#xff0…

代理模式代理模式

目录 1、使用场景 2、静态代理 3、动态代理 JDK动态代理 CGlib 动态代理实现 1、使用场景 使用代理模式主要有两个目的&#xff1a;一是保护目标对象&#xff0c;二是增强目标对象。 2、静态代理 NO.1 抽象接口&#xff1a;定义视频播放器接口Player public interface P…

大数据之路-日志采集

数据采集作为大数据体系中的第一环节&#xff0c;对如何全面、高性能、规范完成海量数据的采集&#xff0c;并将其传输到大数据平台。 1.浏览器的页面日志采集 1.1 页面浏览日志采集流程 页面浏览日志是最基础的互联网日志&#xff0c;其中页面浏览量&#xff08;PageView&am…

短期经济波动:均衡国民收入决定理论(一)

宏观经济学讲义 10 短期经济波动&#xff1a;均衡国民收入决定理论(一) 文章目录 10 短期经济波动&#xff1a;均衡国民收入决定理论(一)[toc]1 均衡国民收入决定1.1 均衡国民收入决定的不同理论1.2 两部门经济&#xff1a;有效需求原理和框架1.2.1 模型假设1.2.2 模型推导1.2…

【零基础抓包】Fiddler超详细教学(一)

​Fiddler 1、什么是 Fiddler? Fiddler 是一个 HTTP 协议调试代理工具&#xff0c;它能够记录并检查所有你的电脑和互联网之间的 HTTP 通讯。Fiddler 提供了电脑端、移动端的抓包、包括 http 协议和 https 协议都可以捕获到报文并进行分析&#xff1b;可以设置断点调试、截取…

期中成绩发布一对一查询

亲爱的老师们&#xff01;我知道您在期中考试后忙碌而又紧张&#xff0c;不仅要准备试卷分析&#xff0c;还要面对学生和家长的询问。现在&#xff0c;我为您带来了一款一对一成绩查询系统&#xff0c;让您的工作变得更简单、更高效&#xff01; 什么是成绩查询系统&#xff1f…

一个小妙招从Prompt菜鸟秒变专家!加州大学提出PromptAgent,帮你高效使用ChatGPT!

夕小瑶科技说 原创 作者 | 谢年年、王二狗 有了ChatGPT、GPT4之后&#xff0c;我们的工作学习效率得到大大提升&#xff08;特别在凑字数方面୧(๑•̀◡•́๑)૭&#xff09;。 作为一个工具&#xff0c;有人觉得好用&#xff0c;自然也有人觉得难用。 要把大模型用得6&am…

518抽奖软件,为什么说比别的抽奖软件更美观精美?

518抽奖软件简介 518抽奖软件&#xff0c;518我要发&#xff0c;超好用的年会抽奖软件&#xff0c;简约设计风格。 包含文字号码抽奖、照片抽奖两种模式&#xff0c;支持姓名抽奖、号码抽奖、数字抽奖、照片抽奖。(www.518cj.net) 精致美观功能 字体平滑无锯齿图片放大后清晰…

SCADA在污水和供水系统解决方案

1. 引言 随着城市化的不断发展&#xff0c;污水和供水系统的管理变得越来越重要。为了提高运营效率和监控系统状态&#xff0c;许多污水处理厂开始使用SCADA系统。 SCADA系统具有实时数据采集、监控和控制功能&#xff0c;可以帮助污水处理厂运营人员实时了解系统的运行情况&…

Google Play优化之如何增强应用的吸引力

视觉元素&#xff0c;在增强应用在Google Play上的吸引力方面发挥着巨大作用。应用程序的图标、屏幕截图和宣传视频&#xff0c;构成了应用程序商店优化过程的关键部分。 1、图标是用户遇到的第一个视觉元素。 精心设计的图标可以有效地代表应用程序的用途&#xff0c;可以显著…

LeetCode | 26. 删除有序数组中的重复项

LeetCode | 26. 删除有序数组中的重复项 OJ链接 这里的非递增是什么意思&#xff1f; 就是反过来的&#xff0c;递减&#xff0c;不能说是乱序~~也就是后一个比前一个小也就是和非递减等价&#xff0c;后一个比前一个大~~ 所以非递增和非严格递增是不一样的~~ 这里本质上的…

亚马逊云科技为奇点云打造全面、安全、可扩展的数据分析解决方案

刘莹奇点云联合创始人、COO&#xff1a;伴随云计算的发展&#xff0c;数据技术也在快速迭代&#xff0c;成为客户迈入DT时代、实现高质量发展的关键引擎。我们很高兴能和云计算领域的领跑者亚马逊云科技一同&#xff0c;不断为客户提供安全可靠的产品与专业的服务。 超过1500家…

外汇天眼:GOMAX──假网友热心教投资,高返利活动骗入金

在通讯科技如此发达的今日&#xff0c;人们愈来愈习惯透过网路交友&#xff0c;寻找志同道合的伙伴&#xff0c;甚至发展一段亲密关系。 然而&#xff0c;近年来假交友诈骗十分猖獗&#xff0c;至今已造成许多民众极大的财务损失&#xff0c;成为无法忽视的社会问题。 不久前&a…

kubectl资源管理命令---声明式

目录 一、yaml和json介绍 1、yuml语言介绍 2、k8s支持的文件格式 二、声明式对象管理 1、deployment.yaml文件详解 2、Pod yaml文件详解 3、Service yaml文件详解 三、编写资源配置清单 1、 编写yaml文件 2、 创建并查看pod资源 3、创建service服务对外提供访问并测试…

从零开始学习Java:如何成为一名Java开发者并找到工作

文章目录 &#x1f31f; JavaSE&#x1f31f; JavaWeb&#x1f31f; 多线程&#x1f31f; 主流框架&#x1f31f; Redis缓存&#x1f31f; 消息中间件&#x1f31f; 全文搜索&#x1f31f; MySQL&#x1f31f; Mongodb&#x1f31f; 开发工具&#x1f31f; 模板引擎&#x1f31…

2023年是5G-A标准制定关键年 华为实现5G-A重大突破

5G商用四年&#xff0c;2023年5G应用项目已经达到10万个&#xff0c;5G向千行百业渗透的同时&#xff0c;也在向5G-Advanced&#xff08;下简称5G-A&#xff09;演进。 10月20日&#xff0c;在工业和信息化部主办的2023年中国5G发展大会上&#xff0c;由IMT-2020&#xff08;5G…

Yusi技术资讯博客wordpress模板

Yusi技术资讯博客wordpress模板&#xff0c;从第一感觉看上去&#xff0c;两栏结构直接将网站的内容展现&#xff0c;以红白灰色调搭配&#xff0c;一种低调协调的风格&#xff0c;喜欢该wordpress主题的朋友可以下载试试。 下载地址&#xff1a;https://bbs.csdn.net/topics/…