CgdataBase.WPF
1.9.29
dotnet add package CgdataBase.WPF --version 1.9.29
NuGet\Install-Package CgdataBase.WPF -Version 1.9.29
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="1.9.29" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CgdataBase.WPF" Version="1.9.29" />
<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 1.9.29
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CgdataBase.WPF, 1.9.29"
#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@1.9.29
#: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=1.9.29
#tool nuget:?package=CgdataBase.WPF&version=1.9.29
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0-windows7.0
- CgdataBase.Core (>= 1.9.29)
-
net6.0-windows7.0
- CgdataBase.Core (>= 1.9.29)
-
net8.0-windows7.0
- CgdataBase.Core (>= 1.9.29)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CgdataBase.WPF:
| Package | Downloads |
|---|---|
|
CgdataBase.WPF.Common
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.9.29 | 48 | 5/2/2026 |
| 1.9.28 | 87 | 4/28/2026 |
| 1.9.26 | 89 | 4/27/2026 |
| 1.9.21 | 101 | 4/15/2026 |
| 1.9.19 | 96 | 4/8/2026 |
| 1.9.16 | 89 | 4/7/2026 |
| 1.9.12 | 101 | 4/3/2026 |
| 1.9.11 | 112 | 3/25/2026 |
| 1.9.8 | 94 | 3/23/2026 |
| 1.9.7 | 92 | 3/23/2026 |
| 1.9.6 | 100 | 3/20/2026 |
| 1.9.5 | 101 | 3/19/2026 |
| 1.9.4 | 100 | 3/18/2026 |
| 1.9.3 | 141 | 1/6/2026 |
| 1.9.2 | 225 | 12/5/2025 |
| 1.9.1 | 285 | 11/22/2025 |
| 1.9.0 | 358 | 11/21/2025 |
| 1.8.3 | 441 | 11/20/2025 |
| 1.8.2 | 459 | 11/18/2025 |
| 1.8.1 | 435 | 11/18/2025 |
Loading failed