![](/img/trans.png)
[英]Custom control / UIView in Xamarin.iOS with design-time properties
[英]custom control design-time
我想用设计时支持创建我自己的TabControl类。
这是我的设计师:
public class TabListDesigner : ParentControlDesigner
{
protected TabList TabListControl { get { return this.Control as TabList; } }
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x7b: // WM_CONTEXTMENU
this.OnContextMenu(Cursor.Position.X, Cursor.Position.Y);
break;
default:
base.WndProc(ref m);
break;
}
}
protected override bool GetHitTest(Point point)
{
return this.TabListControl.HitTest(this.TabListControl.PointToClient(point)) != null;
}
protected override void OnPaintAdornments(PaintEventArgs pe)
{
base.OnPaintAdornments(pe);
ControlPaint.DrawFocusRectangle(pe.Graphics, this.Control.ClientRectangle);
}
public override void InitializeNewComponent(IDictionary defaultValues)
{
base.InitializeNewComponent(defaultValues);
this.AddTabListPage();
this.AddTabListPage();
}
protected virtual void AddTabListPage()
{
IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));
if (host != null)
{
using (DesignerTransaction transaction = host.CreateTransaction(string.Format("Add TabListPage to '{0}'", this.TabListControl.Name)))
{
try
{
TabListPage page = (TabListPage)host.CreateComponent(typeof(TabListPage));
MemberDescriptor controlsProperty = TypeDescriptor.GetProperties(this.TabListControl)["Controls"];
this.RaiseComponentChanging(controlsProperty);
this.TabListControl.Add(page);
this.TabListControl.Controls.Add(page);
this.RaiseComponentChanged(controlsProperty, null, null);
transaction.Commit();
}
catch
{
transaction.Cancel();
throw;
}
}
}
}
}
在设计器中,我将Tabcontrol添加到表单中,并且2 TabPages正确显示。 现在我测试项目,2个Tabpages消失了。 我回到设计师那里,Tabpages不再存在了。 为什么?
我曾经创建过一个控件设计器,而不是表单设计者使用的控件设计器,但更像是单个控件的实际表单设计器。 我不记得该项目,但我确实记得有同样的问题,我不得不提醒视觉工作室,我已经以某种方式改变了一个值。
保存设计器选项卡后,Visual Studio将继续并根据语言将更改转换为代码,并将其写入表单的设计器文件中。 您也可以使用codeDom编写自己的特定代码生成器,但这是非常先进的。
这不是你想要的,但我打赌这个问题是相关的,所以请耐心等待。 我能在这个领域找到的唯一例子是一个名为“Shape designer”的东西c#项目。 我是从浅蓝色的网站上得到的。 我做了一些搜索,但我找不到页面。 无论如何,代码都有很好的文档记录,他完全解释了你的问题。
我也有我的项目,这是一个标签,当你去另一个页面时,它会在页面之间激活。 它在vb.net中,没有详细记录,但你可能想要一瞥它。
这是项目 , 这里是设计师的图像 ,以及最终结果的动画GIF
编辑:
在我的项目中,在“DesignerControl.vb”文件中,在第187行:
' The controldesigner don't always save properties which are changed directly :/
Private Sub SetValue(itm As Item, pName$, val As Object)
Dim Prop As PropertyDescriptor = TypeDescriptor.GetProperties(itm.Page)(pName)
If Prop IsNot Nothing AndAlso Prop.PropertyType Is val.GetType Then Prop.SetValue(itm.Page, val)
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.