In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you the ASP.NET control design operation list and template editing example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
ASP.NET control design-time operation list and template editing one. Smart tag
Look at a picture first.
The small triangle on the right side of GridView can easily help us set common properties, such as starting paging below, enabling sorting, etc., in this way we can finish the work quickly. We call such task menus smart tags.
Let's take a look at how the ASP.NET control design-time action list and template editing are implemented.
1. Override the ActionLists property of ControlDesigner
You must override this property to return your custom collection of smart tags (that is, DesignerActionListCollection), which assumes that CustomControlActionList is custom intelligence.
Public class SampleControlDesigner: ControlDesigner {public SampleControlDesigner (): base () {} / / create a custom action list collection public override DesignerActionListCollection ActionLists {get {DesignerActionListCollection actionLists = new DesignerActionListCollection (); actionLists.Add (new CustomControlActionList (this)); return actionLists;}
2.CustomControlActionList Custom item list
2.1 item list classification
(1) title panel
(2) property panel
(3) method panel
The class diagram is as follows
Look at an effect picture and you'll see what's going on.
2.2 implementation
(1) inherit the DesignerActionList class and override the GetSortedActionItems method to add a custom item panel collection, that is, the three items panel of 2.1s.
Public override DesignerActionItemCollection GetSortedActionItems () {if (items = = null) {items = new DesignerActionItemCollection (); / / add title panel items.Add (new DesignerActionHeaderItem ("Quick setup Panel Test:"); / / add attribute related panel items.Add (new DesignerActionPropertyItem ("Visible", "Show")) Items.Add (new DesignerActionPropertyItem ("Width", "set width"); items.Add (new DesignerActionPropertyItem ("Height", "set height")); / / add method related panel items.Add (new DesignerActionMethodItem (this, "FormatBlue", "define background blue", true) Items.Add (new DesignerActionMethodItem (this, "FormatRed", "define the background as red", true); items.Add (new DesignerActionMethodItem (this, "FormatWhite", "define the background as white", true));} return items;}
(2) implementation of property and method item panel
If you set the property, you must define the property in CustomControlActionList, the method is the same, the code is as follows
# region custom method public void FormatBlue () {SampleControl ctrl = (SampleControl) _ parent.Component; TransactedChangeCallback toCall = new TransactedChangeCallback (DoFormat); ControlDesigner.InvokeTransactedChange (ctrl, toCall, "FormatBlue", "FormatBlue");} public void FormatRed () {SampleControl ctrl = (SampleControl) _ parent.Component TransactedChangeCallback toCall = new TransactedChangeCallback (DoFormat); ControlDesigner.InvokeTransactedChange (ctrl, toCall, "FormatRed", "FormatRed");} public void FormatWhite () {SampleControl ctrl = (SampleControl) _ parent.Component; / / definition delegate TransactedChangeCallback toCall = new TransactedChangeCallback (DoFormat) ControlDesigner.InvokeTransactedChange (ctrl, toCall, "FormatWhite", "FormatWhite");} # endregion#region Custom attribute public bool Visible {get {SampleControl ctrl = (SampleControl) _ parent.Component; return ctrl.Visible } set {PropertyDescriptor propDesc = TypeDescriptor.GetProperties (_ parent.Component) ["Visible"]; propDesc.SetValue (_ parent.Component, value) }} public Unit Width {get {SampleControl ctrl = (SampleControl) _ parent.Component; return ctrl.Width;} set {PropertyDescriptor propDesc = TypeDescriptor.GetProperties (_ parent.Component) ["Width"] PropDesc.SetValue (_ parent.Component, value);}} public Unit Height {get {SampleControl ctrl = (SampleControl) _ parent.Component; return ctrl.Height } set {PropertyDescriptor propDesc = TypeDescriptor.GetProperties (_ parent.Component) ["Height"]; propDesc.SetValue (_ parent.Component, value);}} # endregion public bool DoFormat (object arg) {SampleControl ctl = (SampleControl) _ parent.Component String fmt = (string) arg; PropertyDescriptor backColorProp = TypeDescriptor.GetProperties (ctl) ["BackColor"]; switch (fmt) {case "FormatBlue": backColorProp.SetValue (ctl, Color.Blue); break Case "FormatRed": backColorProp.SetValue (ctl, Color.Red); break; case "FormatWhite": backColorProp.SetValue (ctl, Color.White); break } / / Refresh the design-time html tag _ parent.UpdateDesignTimeHtml (); return true;}
After the above steps are completed, then associate with the relevant controls, the effect picture has been seen above.
[DesignerAttribute (typeof (SampleControlDesigner))]
ASP.NET control design-time operation list and template editing II. Template editor
I believe everyone is familiar with the template editing interface above. How little template to set up support. Template editing is relatively easy to implement when setting up. Let's take a look at how to implement it.
The custom template controls are no longer listed
1. Override the TemplateGroups of the ControlDesigner class to return a collection of custom template groups, namely (TemplateGroupCollection)
The add steps are similar to the addition of tables, td add tr and then table add td
The template is TemplateGroup add TemplateDefinition and then TemplateGroupCollection add TemplateGroup.
The code is as follows
Public override TemplateGroupCollection TemplateGroups {get {if (col = = null) {col = base.TemplateGroups; TemplateGroup tempGroup; TemplateDefinition tempDef; TemplateGroupsSample ctl; ctl = (TemplateGroupsSample) Component / / create template grouping-tempGroup = new TemplateGroup ("template Group A"); / / provide editing template tempDef = new TemplateDefinition (this, "Template A1", ctl, "Template1", false) when setting up TempGroup.AddTemplateDefinition (tempDef); tempDef = new TemplateDefinition (this, "Template A2", ctl, "Template2", false); tempGroup.AddTemplateDefinition (tempDef); col.Add (tempGroup) / / create template grouping 2: tempGroup = new TemplateGroup ("template Group B"); tempDef = new TemplateDefinition (this, "Template B1", ctl, "Template3", true); tempGroup.AddTemplateDefinition (tempDef) TempDef = new TemplateDefinition (this, "Template B2", ctl, "Template4", true); tempGroup.AddTemplateDefinition (tempDef); col.Add (tempGroup);} return col;}}
Note here that there is a property of the TemplateDefinition constructor, while true can only add server controls at design time.
two。 Initialize enable design-time template editing
We also need to call the SetViewFlags method in the Initialize method to enable design-time template editing
Public override void Initialize (IComponent component) {base.Initialize (component); SetViewFlags (ViewFlags.TemplateEditing, true);}
3. Provides a default rectangular identifier to provide a description for the control
As shown in the figure below, DataList gives the following prompts by default
We can do this by overriding the GetDesignTimeHtml method calling the CreatePlaceHolderDesignTimeHtml method to create a rectangular identifier
Public override string GetDesignTimeHtml () {return CreatePlaceHolderDesignTimeHtml ("right-click or select Edit template panel to edit template content");}
All right, it's done, and the next thing to do is associate it with the relevant template controls.
Usually everyone is too busy, the above functions have nothing to do with it, but the commonly used control properties and functions, design support will certainly make the use of more effective.
The above is all the contents of the article "sample Analysis of Action list and template Editing at ASP.NET Control Design time". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.