CgdataBase.WPF 12.1.0

dotnet add package CgdataBase.WPF --version 12.1.0
                    
NuGet\Install-Package CgdataBase.WPF -Version 12.1.0
                    
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="CgdataBase.WPF" Version="12.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CgdataBase.WPF" Version="12.1.0" />
                    
Directory.Packages.props
<PackageReference Include="CgdataBase.WPF" />
                    
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 CgdataBase.WPF --version 12.1.0
                    
#r "nuget: CgdataBase.WPF, 12.1.0"
                    
#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.
#:package CgdataBase.WPF@12.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CgdataBase.WPF&version=12.1.0
                    
Install as a Cake Addin
#tool nuget:?package=CgdataBase.WPF&version=12.1.0
                    
Install as a Cake Tool

CgdataBase.WPF

一个轻量级的 WPF 基础库,基于 CgdataBase.Core 提供更贴近桌面端 UI 的能力:常用转换器、控件/行为、窗口与系统集成辅助,以及一套可直接复用的基础样式资源。

安装

Install-Package CgdataBase.WPF
dotnet add package CgdataBase.WPF

目标框架

  • net6.0-windows / net8.0-windows / net10.0-windows

包含内容

Behaviors / Helpers(附加属性与 UI 辅助)

  • FocusBehavior:提供 IsFocused 附加属性,用于在 XAML/MVVM 中触发控件聚焦,并支持 TextBox 光标定位到末尾。
  • UIElementHelper:常用 UI 相关的辅助方法(见 Helpers)。

Controllers(桌面端控制类)

  • AsyncObservableCollection<T>:支持跨线程更新的 ObservableCollection<T>(自动切回创建时的 SynchronizationContext),避免后台线程更新集合导致 UI 异常。
  • WindowController:窗口显示信息(尺寸/位置/状态)加载与自动保存;提供 EscToExitShowWindow 等常用窗口行为。
  • AutoStartController:写入/删除 HKCU\Software\Microsoft\Windows\CurrentVersion\Run 实现开机自启配置。
  • ClipboardEx / ClipboardFormat:基于 Win32 API 的剪贴板增强操作与格式常量。
  • ListViewControllerRegistryController:ListView 与注册表相关的常用封装(见 Controllers)。

Controls(可复用控件)

  • TitleTextBox:带标题区域的 TextBox。
  • ToggleButton:自定义 ToggleButton 样式/行为封装。
  • VirtualizingWrapPanel:支持虚拟化的 WrapPanel(实现 IScrollInfo),适合大量数据项的“平铺”场景。
  • WpfChart:基于 Grid 的柱形图控件,支持 ItemsSource 绑定并带动画效果。

Converters(常用值转换器)

所有转换器都继承自 ConverterBase<T>,可在 XAML 中以 MarkupExtension 形式直接使用。

  • 布尔相关:BooleanToVisibilityConverterBooleanReverseConverterBooleanReverseToVisibilityConverterBooleanToVisibleHiddenConverterBooleanReverseToVisibleHiddenConverter
  • 枚举:EnumToDescriptionConverter
  • 显示格式:FileSizeConverterNetworkSpeedConverterMultiplyConverterIndexConverter
  • 通用:ObjectToJsonConverterObjectToBooleanConverterObjectToVisibilityConverter

Styles(基础样式资源)

  • Styles/BaseStyle.xaml:基础控件样式集合(Button、TextBox、ListView、Window 等)。
  • Styles/Theme1.xaml:一套可选主题(覆盖部分控件样式)。
  • Styles/Margin*.xaml:常用 Margin 资源集合。

快速开始

1) 在 App.xaml 引入样式资源

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/CgdataBase.WPF;component/Styles/BaseStyle.xaml" />
            
            
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

2) 使用转换器(MarkupExtension 方式)

<Window
    xmlns:conv="clr-namespace:CgdataBase.WPF.Converters;assembly=CgdataBase.WPF">
    <Grid>
        <TextBlock Visibility="{Binding IsBusy, Converter={conv:BooleanToVisibilityConverter}}" />
    </Grid>
</Window>

3) 让集合支持后台线程更新

using CgdataBase.WPF.Controllers;

public AsyncObservableCollection<string> Items { get; } = new();

public async Task LoadAsync()
{
    await Task.Run(() =>
    {
        for (var i = 0; i < 100; i++)
        {
            Items.Add($"Item {i}");
        }
    });
}

4) 窗口尺寸/位置自动记忆

using CgdataBase.WPF.Controllers;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        WindowController.UpdateWindowConfig(this, typeof(MainWindow));
        WindowController.EscToExit(this);
    }
}

5) 在 ItemsControl 中使用 VirtualizingWrapPanel

<ItemsControl xmlns:cg="clr-namespace:CgdataBase;assembly=CgdataBase.WPF"
              ItemsSource="{Binding Items}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <cg:VirtualizingWrapPanel ItemWidth="120" ItemHeight="36" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

相关包

文档

  • API 参考(本仓库已生成静态站点):docs/_site

License

MIT

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed.  net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net10.0-windows was computed.  net10.0-windows7.0 is compatible. 
.NET Framework net472 is compatible.  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 (3)

Showing the top 3 NuGet packages that depend on CgdataBase.WPF:

Package Downloads
CgdataBase.WPF.Plus

Package Description

CgdataBase.WPF.Common

Package Description

CgdataBase.WPF.Metro

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
12.1.0 64 8/19/2026
12.0.13 119 7/31/2026
12.0.12 112 7/29/2026
12.0.11 114 7/29/2026
12.0.10 111 7/26/2026
12.0.9 135 7/22/2026
12.0.0 184 6/23/2026
1.9.34 131 6/15/2026
1.9.33 127 6/9/2026
1.9.32 126 6/3/2026
1.9.30 137 5/11/2026
1.9.29 130 5/2/2026
1.9.28 126 4/28/2026
1.9.26 124 4/27/2026
1.9.21 136 4/15/2026
1.9.19 130 4/8/2026
1.9.16 121 4/7/2026
1.9.12 131 4/3/2026
1.9.11 146 3/25/2026
1.9.8 128 3/23/2026
Loading failed