CgdataBase.WPF
12.1.0
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Framework 4.7.2
This package targets .NET Framework 4.7.2. The package is compatible with this framework or higher.
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" />
<PackageReference Include="CgdataBase.WPF" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=CgdataBase.WPF&version=12.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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:窗口显示信息(尺寸/位置/状态)加载与自动保存;提供EscToExit、ShowWindow等常用窗口行为。AutoStartController:写入/删除HKCU\Software\Microsoft\Windows\CurrentVersion\Run实现开机自启配置。ClipboardEx/ClipboardFormat:基于 Win32 API 的剪贴板增强操作与格式常量。ListViewController、RegistryController:ListView 与注册表相关的常用封装(见 Controllers)。
Controls(可复用控件)
TitleTextBox:带标题区域的 TextBox。ToggleButton:自定义 ToggleButton 样式/行为封装。VirtualizingWrapPanel:支持虚拟化的 WrapPanel(实现IScrollInfo),适合大量数据项的“平铺”场景。WpfChart:基于 Grid 的柱形图控件,支持ItemsSource绑定并带动画效果。
Converters(常用值转换器)
所有转换器都继承自 ConverterBase<T>,可在 XAML 中以 MarkupExtension 形式直接使用。
- 布尔相关:
BooleanToVisibilityConverter、BooleanReverseConverter、BooleanReverseToVisibilityConverter、BooleanToVisibleHiddenConverter、BooleanReverseToVisibleHiddenConverter - 枚举:
EnumToDescriptionConverter - 显示格式:
FileSizeConverter、NetworkSpeedConverter、MultiplyConverter、IndexConverter - 通用:
ObjectToJsonConverter、ObjectToBooleanConverter、ObjectToVisibilityConverter
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>
相关包
- CgdataBase.Core:通用基础能力(序列化、文件/网络工具、设置存取、扩展方法等)
- CgdataBase.WPF.Common:更偏“应用基建”的 WPF 能力(MVVM 基类、Dialog/事件/更新/Excel 等)
- CgdataBase.WPF.Metro、CgdataBase.WPF.Plus:更高层的 UI 组件与样式集合
文档
- API 参考(本仓库已生成静态站点):docs/_site
License
MIT
| Product | Versions 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.
-
.NETFramework 4.7.2
- CgdataBase.Core (>= 12.1.0)
-
net10.0-windows7.0
- CgdataBase.Core (>= 12.1.0)
-
net6.0-windows7.0
- CgdataBase.Core (>= 12.1.0)
-
net8.0-windows7.0
- CgdataBase.Core (>= 12.1.0)
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