三亩地 三亩地SAN MU DI · CODE DIARY
ARTICLE DETAIL

日记详情

真实记录编程学习的某一天,欢迎挑你感兴趣的翻一翻。

如何写自己的控件模块

如何写自己的控件模块
HeBianGu.Control.MyControl ├─ MyControl.xaml ├─ MyControl.xaml.cs ├─ Themes │ └─ Generic.xaml ├─ Service.cs ├─ Extention.cs └─ AssemblyInfo.cs

20.1 控件本体

  • MyControl.xaml:写界面布局。
  • MyControl.xaml.cs:写依赖属性和交互逻辑。

20.2 默认样式

  • Themes/Generic.xaml:写控件默认样式。

20.3 服务注册

如果控件需要服务,就在Service.cs中定义服务,在Extention.cs中提供扩展注册方法。

示例:

publicstaticclassExtention{publicstaticvoidAddMyControl(thisIServiceCollectionservices){services.AddSingleton<IMyControlService,MyControlService>();}}

应用中调用:

services.AddMyControl();

这就是本项目大量模块的组织套路。

← 返回列表