How to hide the inner controls of a UserControl in the Designer? - c#

I have a UserControl that contains a DropDownList and an ObjectDataSource. That control is used in the markup of my MasterPage.
In the Designer of a ContentPage that uses that MasterPage I can see the DropDownList and the ObjectDataSource. See for yourself.
I know that other controls (like ComponentArt:Grid) only show themself as outer container and hide the inner controls.
I guess that is somehow achievable with attributes. Which ones do I have to set?

I'm guessing that the control you refer to, ComponentArt:Grid, have an associated ControlDesigner which can do about anything, including designtime editable areas and custom action menus (the menu associated with the arrow in the upper right corner).
However, Visual Studio does not [last time I tried] execute the control designer for UserControls, so you can not easily control this. There's a lot of magic happening in the background in the UserControlDesigner including parsing the html code. However, I've never seen actual compilation of the codebehind file, where the ControlDesigner attribute would be specified.
You will need to rewrite your control as a server control for Visual Studio to check for the attribute, and allowing your custom designtime view.

I'm not very familiar with WebForms but the BrowsableAttribute might be what you are looking for. Also look at the DesignTimeVisibleAttribute.
The System.ComponentModel namespace has a number of other attributes that may do what you need.

Visual studio doesn't support this. The moment you specify the word "user control", the thing goes beserk and renders everything you put on it.
Fortunately you can influence how server controls are rendered. In other words, you can cheat the Visual Studio designer by making use of that. The code you need can be found here: http://www.codeproject.com/Tips/773145/Hiding-contents-in-ASP-Net-user-control-designer

Related

Pre-defined XAML code for new control that is added in VS designer

Is there a way to automatically generate XAML code when you drop your control from toolbox to designer? I.e. it would create certain objects (nested properties) automatically and user would not have to type the same code every time to set certain (nested) properties. Kind of a template XAML code that is pre-defined by control's developer.
I'm pretty new to WPF so I'm wondering why there aren't any nested properties in the controls that are in Visual Studio's toolbox (button, label etc...)? Are attached properties a cure for this or have they just cut corners when designing WPF. :)
The problem is that my control (WinForms style property hierarchy) has nested properties and if I "internally" in my code create objects for those properties then XAML does not reflect the situation because it does not have any elements that match the current situation (i.e. the objects created in my control's constructor).
Is the only solution to leave all the properties null and let the user create them all? That way it seems to work correctly but user has to write many lines of XAML to reflect the situation in WinForms.
The functionality that you seek is not available via any of the controls in WPF. However, Visual Studio used to have Macros that would enable us to add pre-written sections of code into our pages, but unfortunately, they decided to remove that great functionality. Fortunately, they have introduced Code Snippets as a partial alternative.
Unfortunately again, these Code Snippets don't work in XAML pages, but once again fortunately, there are a few Visual Studio add ins that will enable you to enter pre-written XAML into your pages at the click of a button on the Code Plex website:
XAML Code Snippets addin for Visual Studio 2010
XAML Snippets for Visual Studio
Please try using one of the above add ins to see if they meet your needs.

Visual Studio: Typing code vs. drag and drop from the control menu

I tried creating a gridview by typing code using another block of code on a different page as an example. I found that, when I ran the program and clicked the Edit button on a row, the fields did not change into textboxes for editing. I did have code to handle the Row Editing event.
In an earlier project I found that I had to double-click the Row Editing event in the Properties window for a gridview to create the event handling code. Typing in that code in the separate aspx.cs file did not work.
I am working with ASP.Net / C#.
What is going on with Visual Studio when I do drag and drop from the control menu as opposed to just typing in code? I am assuming it is adding something that I am missing when I am just typing.
Does anyone else have other examples that didn't work when they typed code that I should watch out for?
Even if you did a mighty good job copying the HTML, you likely still missed a few properties. That's because the GridView component comes with a bunch of so-called Design-Time properties that can (only) be configured from the Properties panel in Visual Studio.
I think you'll find that dragging a control from the toolbox onto your web form will set the control's design-time properties to a specific set of default values. This does not happen when you type the HTML by hand.

Navigating between parental panels

I have problems with editing panels in C# windows forms(Visual studio 2008). I placed some panels into another, and now I have problems with navigating panels inside parental containers. Is there any tool that gives not only drag-drop control, but also tree view of container and panels in it. For example, like Navigator window in NetBeans(IDE for Java). Any help?
I'm not sure about VS2008, but newer versions have Document Outline Window (View > Other Windows > Document Outline)
To not get lost in controls, consider to name them properly. Then you can find them in the list of Properties window.
Instead of label1 use labelInputName, located on panel1, which you also rename to panelInput. This gives parent/child feeling and you will never lost.
If you get lost, use Document Outline window to see tree-like relation via Controls property (who is control of who). This window is a helper (help to find and select control), you will still have to use designer to do changes.
Another important thing is UI design. Whenever you get cluttered or bulky feeling, than it's the time to change something.
Making UserControl for repeatable part is one way.
Another is to differ design and run time (what you see in designer): to example, if you have several panels, which has to be shown at same place, then you can use dynamic container for them (FlowLayoutPanel, TableLayoutPanel) or you can have them placed in a way for you to easily see them in design-time, but their position will be corrected during run-time (to example, in the constructor). Prioritizing designing is a must if you are going to support project and edit functionality in next versions.
p.s.: talking about winforms, but all said should be true for wpf as well.

ASP.NET Custom Server Control not refreshing in designer

I have a written an ASP.NET Custom Server Control, which I have working. This control inherits from CompositeControl and has different views that it can show during its life time. The best analogy would be similar to a Tab control where one control has many user selectable views depending on which tab the user selected. Before someone asks, no, mine is not a Tab control, it's an analogy that everyone should be familiar with.
Anyway, I want to have the view to be selectable in the Visual Studio 2010 designer. To do this, I created a CompositeControlDesigner with actions (just a single combobox to select the view). All of this works just fine, I have even stepped through the code in the debugger and verified that everything is firing off as expected including CreateChildControls back in the main control, but Visual Studio is NOT refreshing the screen. It only appears to refresh the designer if a tag is added/removed/modified on the control (which will not happen in this case since it is an designer-only feature)
Does anyone have a clue as to how to force the designer to refresh?

Visual Studio 2008: Adding components to inherited panel

In this scenario I have a base component with a close button and a flow panel; (FlowLayoutPanel) the idea being that components extending this add their controls to the flow panel and will have the close button functionality done for them.
The problem is that I can't seem to persuade VS to add the components in the subclassed component to the flow panel; this ends up with me having to do so in the code. Which is all well and good except that it won't show up in the designer view. If I add it to the partial class with the designer generated code then I can see the controls in the designer view laid out by the flow panel. But this just gets overwritten afterwards.
Visual Studio doesn't seem to let you dock controls in inherited panels - unless I'm doing something wrong? I did make sure that the base panel is publically visible in case this was the issue.
--
An alternative might be some way to persuade the designer to execute/not overwrite my code in the designer class.
You need to make a ControlDesigner for your control and override the InternalControlDesigner and GetParentForComponent methods.
For an example, open System.Windows.Forms.Design.SplitContainerDesigner (in System.Design.dll in Reflector.

Categories

Resources