MinimalisticWPF.Controls 2.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package MinimalisticWPF.Controls --version 2.0.3
                    
NuGet\Install-Package MinimalisticWPF.Controls -Version 2.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MinimalisticWPF.Controls" Version="2.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MinimalisticWPF.Controls" Version="2.0.3" />
                    
Directory.Packages.props
<PackageReference Include="MinimalisticWPF.Controls" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MinimalisticWPF.Controls --version 2.0.3
                    
#r "nuget: MinimalisticWPF.Controls, 2.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=MinimalisticWPF.Controls&version=2.0.3
                    
Install as a Cake Addin
#tool nuget:?package=MinimalisticWPF.Controls&version=2.0.3
                    
Install as a Cake Tool

MinimalisticWPF.Controls

此项目仅演示如何使用MinimalisticWPF设计用户控件

GitHub
NuGet

( 注意 : 这仅演示局部功能,完整功能见MinimalisticWPF的文档 )

( 注意 : 若安装此项目,则MinimalisticWPF也将作为可传递包被安装 )


特点 ✨

只需要为类标记一些特性,就可以自动实现下述功能

  • 主题切换动画&行为实现
  • 悬停交互动画&行为实现
  • 帧循环驱动的行为
  • 构造器自动化

用户控件 🚀

添加如下引用以使用这些用户控件

xmlns:views="clr-namespace:MinimalisticWPF.Controls;assembly=MinimalisticWPF.Controls"

这些控件支持主题切换,下述代码演示了如何手动切换主题跟随系统主题

1.是/否跟随系统主题

public partial class App : Application
{
   public App()
   {
      DynamicTheme.FollowSystem(typeof(Dark)); // 跟随系统,若系统主题读取失败,则使用Dark主题

      DynamicTheme.StartWith(typeof(Dark)); // 手动指定,不跟随系统,选择此项后,请手动切换主题
   }
}

2.手动切换主题

DynamicTheme.Apply(typeof(Light));

Button ✨

按钮很常见,并且具备比较多的交互行为,本项目探索了一种简约而美观的Button实现方案。例如,Data属性可以自动解析路径或文本作为按钮的内容;鼠标悬停时,可以让按钮的内容转动起来。

1.按钮样式

特性被标记后,这些依赖属性就会自动生成,修改它们能直接影响按钮的外观。你还可在特性中直接传入参数用以构造这些依赖属性的初始值而不再需要全部在Style中声明。当然,这里为了完全展现MinimalisticWPF的源生成功能,我将所有自动产生的依赖属性都写进Style了。

        <Style TargetType="views:Button" x:Key="nicebutton">
            
            
            <Setter Property="DarkHoveredBackground" Value="#1e1e1e"/>
            <Setter Property="DarkHoveredForeground" Value="Red"/>
            <Setter Property="DarkHoveredBorderBrush" Value="White"/>
            
            <Setter Property="DarkNoHoveredBackground" Value="#1e1e1e"/>
            <Setter Property="DarkNoHoveredForeground" Value="White"/>
            <Setter Property="DarkNoHoveredBorderBrush" Value="White"/>
            
            
            
            <Setter Property="LightHoveredBackground" Value="White"/>
            <Setter Property="LightHoveredForeground" Value="Cyan"/>
            <Setter Property="LightHoveredBorderBrush" Value="#1e1e1e"/>
            
            <Setter Property="LightNoHoveredBackground" Value="White"/>
            <Setter Property="LightNoHoveredForeground" Value="#1e1e1e"/>
            <Setter Property="LightNoHoveredBorderBrush" Value="#1e1e1e"/>
            
            
            
            <Setter Property="HoveredBorderThickness" Value="1"/>
            <Setter Property="HoveredCornerRadius" Value="5"/>
            
            <Setter Property="NoHoveredBorderThickness" Value="1"/>
            <Setter Property="NoHoveredCornerRadius" Value="0"/>
        </Style>

2.使用按钮

  • AllowHoverRotate : 允许按钮在悬停时旋转
  • Data : 使用文本路径数据作为按钮内容 ( 尝试解析为Path失败后会直接使用文本 )
  • ContentScale : 按钮内容缩放比例 ( 内容大小按此比例自动计算 )
<views:Button Style="{StaticResource nicebutton}" 
              Width="100" Height="100" 
              AllowHoverRotate="True" 
              ContentScale="1"
              Data="M15.75 21.495c0 .41.34.75.75.75l-.01.01c.98 0 1.47 0 1.93-.09a4.73 4.73 0 0 0 3.73-3.73c.09-.46.09-.95.09-1.93c0-.41-.34-.75-.75-.75s-.75.34-.75.75c0 .88 0 1.32-.06 1.63a3.24 3.24 0 0 1-2.55 2.55c-.31.06-.75.06-1.63.06c-.41 0-.75.34-.75.75m-8.25.75l-.01-.01c.41 0 .75-.34.75-.75s-.34-.75-.75-.75c-.87 0-1.32 0-1.63-.06a3.24 3.24 0 0 1-2.55-2.55c-.06-.31-.06-.75-.06-1.63c0-.41-.34-.75-.75-.75s-.75.34-.75.75c0 .98 0 1.47.09 1.93a4.74 4.74 0 0 0 3.73 3.73c.46.09.95.09 1.93.09m13.25-14.75c0 .41.34.75.75.75l.01.01c.41 0 .75-.34.75-.75c0-.98 0-1.47-.09-1.93a4.74 4.74 0 0 0-3.73-3.73c-.46-.09-.95-.09-1.93-.09c-.41 0-.75.34-.75.75s.34.75.75.75c.87 0 1.32 0 1.63.06c1.29.25 2.29 1.26 2.55 2.55c.06.31.06.75.06 1.63m-19 0c0 .41.34.75.75.75l.01-.01c.41 0 .75-.34.75-.75c0-.88 0-1.32.06-1.63a3.24 3.24 0 0 1 2.55-2.55c.31-.06.75-.06 1.63-.06c.41 0 .75-.34.75-.75s-.34-.75-.75-.75c-.98 0-1.47 0-1.93.09a4.73 4.73 0 0 0-3.73 3.73c-.09.46-.09.95-.09 1.93m9.25 9.75h2c2.02 0 3.14 0 3.94-.81c.81-.8.81-1.92.81-3.94s-.01-3.13-.81-3.94s-1.92-.81-3.94-.81h-.25v-1.25c0-.41-.34-.75-.75-.75s-.75.34-.75.75v1.25H11c-2.02 0-3.14 0-3.94.81c-.81.8-.81 1.92-.81 3.94s.01 3.13.81 3.94s1.92.81 3.94.81m-2.88-7.63c.35-.36 1.13-.37 2.88-.37h2c1.74 0 2.53.02 2.88.37c.36.35.37 1.14.37 2.88s-.02 2.53-.37 2.88c-.35.36-1.13.37-2.88.37h-2c-1.74 0-2.53-.02-2.88-.37c-.36-.35-.37-1.14-.37-2.88s.02-2.53.37-2.88m5.13 2.38c0 .41.34.75.75.75s.75-.34.75-.75v-.5c0-.41-.34-.75-.75-.75s-.75.34-.75.75zm-4 0c0 .41.34.75.75.75s.75-.34.75-.75v-.5c0-.41-.34-.75-.75-.75s-.75.34-.75.75z"/>

NotificationBox ✨

现代化风格的通知框

设计这个控件时,我在特性中已经将效果参数声明完毕,所以完全不需要写Style

Loaded += (s, e) => NotificationBox.Choose("确定要继续吗?");
Loaded += (s, e) => NotificationBox.Confirm("操作已成功执行!");

HotKeyBox ✨

在做一些快捷方式的设置界面时,我们可能需要一个用于接收用户输入的控件,并且用户输入完毕后,自动注册/注销快捷方式

1.快捷方式管理器样式

这里与Button的样式类似,假设Key为nicehotkeybox,细节省略…

2.使用快捷方式管理器

  • HotKeyInvoked : 快捷方式被触发时的事件
  • TextScale : 快捷方式文本缩放比例 ( 文本大小按此比例自动计算 )
  • 自动确保快捷方式的唯一性
        <views:HotKeyBox Style="{StaticResource nicehotkeybox}"
                         Width="340" Height="100"
                         TextScale="0.618"
                         HotKeyInvoked="HotKeyBox_HotKeyInvoked"/>
        private void HotKeyBox_HotKeyInvoked(object? sender, HotKeyEventArgs e)
        {
            // 处理快捷键触发事件
            MessageBox.Show("快捷方式被触发!");

            // 全局快捷键的sender为null
            // 局部快捷键的sender不为null
            // e传递了快捷键的信息
        }
Product Compatible and additional computed target framework versions.
.NET net5.0-windows7.0 is compatible.  net6.0-windows was computed.  net7.0-windows was computed.  net8.0-windows was computed.  net9.0-windows was computed.  net10.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.0 138 6/3/2025
2.1.0 144 5/27/2025
2.0.6 145 5/21/2025
2.0.5 94 5/17/2025
2.0.4 98 5/17/2025
2.0.3 220 5/15/2025
2.0.2 126 5/11/2025
2.0.1 64 5/10/2025
2.0.0 68 5/3/2025