在此自定义内容查询 Web 部件中,以下代码有效。我能够更改 Web 部件标题和 ToolPart 标题:
public class CustomWebPart1 : ContentByQueryWebPart
{
public override ToolPart[] GetToolParts()
{
ToolPart[] toolPartArray = base.GetToolParts();
return new ToolPart[] { new CustomContentQueryWebPartToolPart(), toolPartArray[0], toolPartArray[1] };
}
}
public class CustomContentQueryWebPartToolPart : ToolPart
{
TextBox txt1;
CustomWebPart1 wp;
public CustomContentQueryWebPartToolPart()
{
this.Title = "My Custom Properties";
}
protected override void CreateChildControls()
{
txt1 = new TextBox();
this.Controls.Add(txt1);
base.CreateChildControls();
}
public override void ApplyChanges()
{
this.Title = "ToolPart Title: " + txt1.Text;
wp = this.WebPartToEdit as CustomWebPart1;
wp.Title = "WebPart Title: " + txt1.Text;
base.ApplyChanges();
}
}
但是,如果我更改数组中的位置(这是 Web 部件属性的显示顺序),更改 Web 部件标题就不再起作用了!
public override ToolPart[] GetToolParts()
{
ToolPart[] toolPartArray = base.GetToolParts();
return new ToolPart[] { toolPartArray[0], toolPartArray[1], new CustomContentQueryWebPartToolPart() };
}
这里有什么问题?这是一个错误吗?更改 ToolPart 标题仍然有效。