需要实现IWorkItemControl接口,首先创建一个自定义控件的基类WitCustomControlBase,定义_workItem和_workItemFieldName字段,定义FlushToDatasource方法。
代码段如下:
publicclass WitCustomControlBase : UserControl, IWorkItemControl{
protected WorkItem_workItem = null;
protected string_workItemFieldName = null;
public virtual voidFlushToDatasource(){
}
}
新建类DemoControl继承自WitCustomControlBase,代码段如下:
publicpartial class DemoControl : WitCustomControlBase {
private TextBox txtDemo = newTextBox();
public DemoControl() {
InitializeComponent();
txtDemo.Width = 100;
txtDemo.Height = 25;
txtDemo.Text = "InitText";
this.Controls.Add(txtDemo);
}
private void UpdateData() {
this._workItem.Fields[_workItemFieldName].Value = txtDemo.Text;
}
public override voidFlushToDatasource() {
UpdateData();
}
}
新建DemoControl.wicc文件,内容如下:
<?xmlversion="1.0"?>
<CustomControlxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Assembly>CodePlex.WitCustomControls.dll</Assembly>
<FullClassName>CodePlex.WitCustomControls.Demo.DemoControl</FullClassName>
</CustomControl>
创建安装项目,安装以上内容所在的项目
![Machine generated alternative text: WCustomControlSebpE] Detected Dependen鰁sContent Files from WitCustomControls (Active)Primary output from WitCustomControls (Active)](http://hi.youkuaiyun.com/attachment/201108/26/0_1314342405bDeZ.gif)
安装之后在安装目录下可以找到以下内容

接下来修改TFS团队项目模板
通过Visual Studio中的Team Explorer下载Agile 5.0模板,打开WorkItemTracking下的TypeDefinitions,复制一份task.xml文件,重命名为Customtask.xml。打开Customtask.xml,将WORKITEMTYPE修改为CustomTask,添加
![]()
<FIELDname="DemoTitle" refname="Microsoft.VSTS.Common.DemoTitle"type="String" />
和
<ControlType="DemoControl"FieldName="Microsoft.VSTS.Common.DemoTitle"Label="DemoTitle:" LabelPosition="Left" />
![]()

打开WorkItem Tracking下面的workitems.xml,添加一个WORKITEMTYPES

上载修改过后的Agile 5.0模板,根据该模板新建TeamProject,添加CustomTask类型的WorkItem

![Machine generated alternative text: ]Jtle: IDemoTUeE-St5 ________Assigned To: IAdminisfrathrState: lActiveseason: INPlanningSta Rank: rPrior靦y: 12- Effort (Hours)Original estimate:I Remaining:Compieted:ClassificationArea:Iteration: IDemoconfrolActiviti: IIoemoconfrol zIz]I MyCustomTideDemoTitle:z]](http://hi.youkuaiyun.com/attachment/201108/26/0_1314342586vdRr.gif)
保存该WorkItem,查看DemoTitle在数据库中的存储
打开表dbo.WorkItemsLatest,找到刚才添加到DemoTitle项

Links:
Work Item Tracking Custom Controls
Pastedfrom <http://blogs.msdn.com/b/greggboer/archive/2010/03/30/work-item-tracking-custom-controls.aspx>
Createcustom work item control for TFS Web Access 2010 (TWA)
Pastedfrom <http://www.ewaldhofman.nl/post/2010/08/10/Create-custom-work-item-control-for-TFS-Web-Access-2010-(TWA).aspx>
Custom Controls for TFS Work Item Tracking
Pastedfrom <http://witcustomcontrols.codeplex.com/>

本文介绍如何创建自定义的TFS工作项控件,包括定义IWorkItemControl接口的基类WitCustomControlBase,及具体实现的DemoControl类,并详细说明了配置XML文件及修改TFS团队项目模板的过程。
627

被折叠的 条评论
为什么被折叠?



