LayoutTemplatePath for ImageControl Sitefinity - c#

We're trying to create an extended version of the built in Sitefinity ImageControl by creating a separate toolbox.config entry with a custom LayoutTemplate specified.
This essentially works, however when dragging the control from the toolbox in the editor it does not have the custom LayoutTemplate we specified in the config, it uses the default ImageControl LayoutTemplate.
If we manually change the value in the advanced settings of the widget to our new template, it all works. However, obviously in terms of usability this is quite useless.
Is it a bug that the widget doesn't pick up out LayoutTemplate in the toolbox.config, or is there something else we need to do in order for it to be picked up automatically?
Thanks in advance for your help!

It sounds like a bug to me, you should raise a bug report through the ticketing system.
In the meantime have you tried using Option 2 of this blog posted by Josh Morales:
Mapping External Templates for Sitefinity Widgets
It is written for version 4, but should still work in 5.

I'm still investigating the matter, but in addition to Seans suggestion, you could alternatively you inherit from the image control, hard-code the layout template path by overriding the property value to point to your template, then add that control to the toolbox with a different name.
This is a bit of an extreme workaround, since if this is a bug and gets resolved in the next release you'll have to go back and replace them all again to use the toolbox property...
but it's an option! I'll get back when I know more about why this isn't working the way you expect...

Related

How to make custom form control in c#

I was trying to do something in visual studio the other day when I realized, if I could just make a form control to do it for me it would be allot easier, except I have no idea how to do that, I want the form control to have grids, each square having its own color property, if anyone knows how to make form controls, or even better knows how to make something like what I just described, I would be very happy :D
This MSDN article is a basic step by step outline of how you can write a customer control.
Unfortunatly MS has not figured out how to do avoid link rot -- so you may need to search creating custom winform controls to find this if you come in the future.
You are usually best servered by subclassing an existing control and customizing it.
You might also find some of the freely available winform control projects a gold-mine of useful info if you get serious about this.
However, it sounds likely what you should consider doing is creating a "User Control", this is usually simpler for a composite of few existing controls. This
article on the types of controls for winforms may be a useful overview for you.
Beyond that you really should use S/O if you are trying to resolve a specific problem you are having when you are coding. Google is a more appropriate tool for finding tutorials, etc.
1) Inside your project: Solution Explorer --> Right Click the .csproj --> Add UserControl
2) Drag and drop gridBox or any control you want into your custom control.
3) Check the ToolBox, your custom control should be located at the very first selection

Is it possible to generate code properly through a toolbox custom control?

Ok, so long story short, I was working on a .NET WEBFORMS project which was capable of creating ASPX pages through an ASPX form, which was basically a drag and drop controls page which, we could say, seemed to be a basic but functionality acceptable page/wizard/aspx-creator.
Well, now my higher-ups decided that approach is not a worthy solution and, I don't know why, they got into their heads that this, instead of this ASPX creator form, could be implemented through custom controls added to the toolbox.
So, my doubt is... is that even possible? Or better, is that a reasonable solution? I mean, the first cons I've already found is the fact It seems that it's impossible to yield CodeBehind code by the drag and drop method.
Thanks in advance!
Custom Controls
This MDSN walkthrough teaches you aboutmaking custom web controlls for asp. these would be able to appear in your tool box and could be dragged into its respective place, is this waht you are looking for?
EDIT:
Re-reading it looks like you want to be able to drag in bits of code and have certain regions prompted for edits, this CAN be done, using snippets. if you type propg or propfull and tab twice it constructs that code and tells you what bits to edit right? you can make your own snippets!
Creating custom snippets
failful msdn tutorials to the rescue once more!

Simpler Breadcrumb Bar Sample

my question is very simple. I am building an app(WPF CSharp) and I need user to give me paths that my app is going to use. Previously I added textboxes to show pathways, however, later I decided that it would be cool to use a Win 7 style Explorer navigation bar, which is a Breadcrumb bar. I found a great open source component for it here (http://www.codeproject.com/KB/tree/WPFBreadcrumbBar.aspx) however, I could not use it in my app. I added references both to Toolbox section and Project>References section. I can also add the control to my WPF window from Toolbox, yet I could not figure out how to fill it, how to change and show items in it etc. With respect to component author, I think article on Codeproject is not very 'understandable'(XAML? I want C# code please) and also PopulateItems event, for instance, did not work for me. So, if someone give me a basic example on how to add items to this bar easily, change items, or shortly, shows me how to make it work, I will appreciate for that,
Thanks.
I Guess it depends on how you want to present it. If you want to use a tab control to simulate the functionality you could go this route:
http://www.wpfblogger.com/post/BreadCrumb-TabControl-Style-for-WPF-40.aspx

How to create a simple Custom Container control with 2 Divs inside?

Im looking to create a custom ASP.NET container control that will allow me to drag further controls into it within the VS designer.
The final HTML that im looking for is very simple..
<div id="panel1">
<div id="panel2">
</div>
<div id="panel2">
</div>
</div>
With additional controls being able to be dragged into panels 2 and 3.
Im sure its very simple but im struggling to find examples that will help.
Any pointers or ideas are appreciated!
Cheers
Stuart
I've done such things in the past, and yes, from my experience at that time there is not much documentation available. Even worse, at that time some of the documentation was incorrect or vague!
So, to save you all the headaches (ouch, it already starts to hurt when I just think of it :-P), here is some information you definitely need to know.
Basically all controls are for run-time use only. You can attach a ControlDesigner to a control with an attribute on the class definition, which the design time environment (VS.NET IDE) will load and use as a layer on top of your control.
Templates
Chris' suggestion to use Templates is in the right direction. Your control needs to store somewhere the 'content' of the div's, and Templates are the perfect solution. Make sure you get this part right at first. Note: template properties can behave weird if they have a set clause! Moreover, check the use of NotifyParentAttribute also.
When you've got the templates in place, and you can use declarative syntax in ASPX pages to add controls, and they render well, then you can start working on the designer.
For the designer you have 2 options; the easy and complex way.
Easy designer solution
Let's start with the easy way. The base ControlDesigner classes already provide a framework to show templates. You have probably already seen this in action, like in the GridView control and its template fields.
Check out the following MSDN article on creating a template control designer.
With this easy solution, you get an automatic implementation of the smart tag (the arrow to the right of a control during design-time), and can select a template to edit from a drop down list.
Complex designer solution
Now, if this is not really satisfying for you, and you would like to be able to edit controls just like a Panel control, then you have to dig deeper. So here is the complex solution using Control Designer Regions.
See the example in the example in the EditableDesignerRegion class.
What this example does, is overriding the CreateChildControls of the designer class. Remember I said the designer control is a layer on top of your run-time control? So this CreateChildControls method will run after your control's implementation. What you have to do, is mark a HTML element within your render output with a special designer region HTML attribute. In this way, the designer knows what part in your rendered control should be a region.
Now you have to instruct the IDE to assign a editor or viewer to your regions. You have to do this in the GetDesignTimeHtml(DesignerRegionCollection regions) method (notice the overloaded version of this method). As you can see, this method receives a collection of regions. You have to assign your editable of view regions to this collection. Important here - and this is the badly documented part - is that the order in this collection is very important. The value of the region attribute in your HTML, refers to the index in this collection.
So, now we have defined regions in our rendered output, assigned a editor or viewer to it. Next up is how to fill these regions and store the value from these regions back into our controls declaration.
These two actions are handled in GetEditableDesignerRegionContent and SetEditableDesignerRegionContent methods of the control designer. Here you see why it's important to name the regions that you've added to the collection in the GetDesignTimeHtml method. In these two methods you receive the region reference and by it's Name property you could determine which Template property of your control to read/write.
To read and write the template properties we use the magic of the ControlPersister and ControlParser. The persister creates an template instance from declarative ASP.NET (HTML) code. The parser does the job the other way around; creates plain HTML from a template instance.
In a nutshell
So it's up to you to decide whether the standard template editing framework is good enough for you. If you want to have fancy edit capabilities for both of your edit regions in your IDE, then you will have to implement the complex solution. Otherwise just stick with the simple implementation. The examples mentioned will help you a lot.
Here is a link to a MSDN article regarding what you are trying to do, unfortunently there is no VS designer support so it renders correctly from the server but not in the IDE.
How to: Create Templated ASP.NET User Controls
http://msdn.microsoft.com/en-us/library/36574bf6.aspx

C# UserControl Inheritance

Working with VS.NET 2008, output type Class Library, Target Framework .NET 2.0
I've come up with a simplified scenario to ask this question.
I have a Button user control, its a simple panel with a single big button on it.
I want to create a RedButton control that extends Button, and similarly, a GreenButton.e.g. Class RedButton : Button
Ideally, when I open up RedButton's designer I will see the button that I created in Button and be able to modify it, for example make it Red, or change font, etc.
I've tried to do this once, but when I open up the RedButton's designer I just get a bunch of errors.
In this case, doing all this work programatically isn't an option for us, as in the real case this would be a pain.
Could someone shed some light on this?
Thanks Very Much.
Truthfully, your example should work just fine. Just ensure that you provide a default constructor for your derived class. Also ensure that you do not use generic controls as the designer will have no clue how to create an instance of it.
Is your assembly setup to be delay signed? Look for the delay signing attribute as well as the checkbox in project properties. I've seen delay signing cause this sort of problem with VS2005 perhaps its still a problem in VS2008.
I had to deal with this problem for years at an old company. I researched it a little back then. I don't think that there is a solution for this.
I don't know how much you want to extend the base class in your real example, but the changes you mentioned in your example would be trivial. Just something like
btnTheButton.BackGround=Color.Red;
In reality, probably whatever changes you need to make to button could be done in a few minutes. It is unfortunate that this will be a few minutes everytime you need to inherit a new control, but I think it's the only option
If the control you inherit from is from a DLL and not just another class in the solution, then your designer will render the inherited control properly. My guess is that the VS Design View needs the DLL to draw the control. There may be other ways around this as well.
Since VS.NET 2008 the root designer is able to present "bunch of errors" as you mentioned. In general the described scenario should “just work”.
What kind of errors are you facing?
Follow this example if you aren't already:
public class RedButton : Button
then in the XAML instead of
<UserControl></UserControl>
Start/end your XAML file with
<Button></Button>
Note that it is okay to inherit from something in another namespace even though you didn't define the namespace yet. Example:
<radDock:RadPane ...
xmlns:radDock="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Docking"
...
Title="{Binding Path=StudyTitle}"...

Categories