I am trying to create custom controls for my JavaFx app and I got a bit lost in the correct architecture of the code.
I have created a custom combobox control, which is based on detailed customization of the default ComboBox control. Since, after the customization, I cannot guarantee the general function of the control as ComboBox type (some methods could "spoil" my customization etc.), I thought the correct way is the encapsulation using this architecture:
My CustomComboControl extends Control, not ComboBox.
It contains a private field internalCombo, which is my customized ComboBox instance. The internal combo is a part of the custom control, not of its skin, so that I can easily get data from the internal combo, delegate things to internal combo etc.
My CustomComboControl uses a custom Skin, which uses the internal combo from the control as its root node.
Is this a correct architecture? It seems generally to work well but I encountered some problems I cannot solve.
Focus and key events. If I keep both my custom control and the internal combo setFocusTraversable(true), the focus seems to be doubled in going through focus cycle (need to press TAB twice to go over my custom control).
If I make only the internal combo focustraversable, I cannot listen for focus on my custom control (which is sometimes needed).
If I make only the custom control focustraversable, the internal combo does not receive keyboard events, which breaks its function.
What is the correct architecture? (I know that this question is probably too broad.)
Question EDITed:
In the second suggested solution (only skin focustraversable, not the control itself) is passing key events from the custom control to the internal combo somehow possible?
Related
I have several pages that all have a GridView control. Within that control there are several events that need to be implemented (OnRowDataBound, OnEditing, etc...)
Any suggestions as far as inheriting from a page that will force me (virtual functions) to implement each of these events? I can't visualize how that would look because of the GridView being a control. How do I inherit from a control?
A common way of doing this is to contain your GridView in a UserControl
If you place your grid on the user control, and subscribe to all the events there, then you can reuse this implementation anywhere you want in the application - you are essentially just wrapping the user control with the functionality you want, and then reusing this wrapper everywhere.
The neat thing is that you only have to write the wire-up code once.
That's what I think you want to do.
If you want to extend or handle these events outside the usercontrol, though, you'll need to reimplement them (i.e. add your own event handlers and let those bubble up).
You can't force anyone to subscribe to your events though.
If you wanted to force an implementation of the events then you can put the events on an interface, and implement that interface on the class or control you add it to. As the events are on the interface, you will not be able to compile until the interface has been implmented.
If you have a specific use case I can try to add an example.
I am writing a composite control in c# asp.net as an experiment and would like to have all the instances of my composite control interact with one external control. Is this possible?
Things I have tried:
option 1: check from within the control whether an external control exists on the page, and add it if it doesn't
option 2: have the target control's id passed to the composite control at design time and then use this.Page.FindControl()
Obviously it was wishful thinking that it would be that simple :)
If I try do this from within the CreateChildControls Method, this.Page.FindControl(target control) always returns null. If I try to add the control to the page from within this method, it throws an exception:
"The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases."
is there another method / event where I can achieve this?
Why don't you expose a public property on your Composite Control of what output from them, then when rendering the Panel's contents, recurse through the page, find all instances of the composite control, grab the text, and add it to the panel?
You can create multiple instances on the same Web form by implementing the INamingContainer Interface. This basically helps prevent id clashes in the same namespace.
If you want to access another control set a property on it to expose the data you want made public.
Build Composite Controls
So in a WinForm app, the Properties tab has an event button. It shows me all the possible events I can wire up to a delegate for the control that has focus. Then, all I have to do is double-click my event of choice and VS will auto-stub the delegate for me with the appropriate EventArgs type and everything. It'll then automagically take me to that delegate in the class.
How can I do the same thing in ASP.NET? For example, where can I click or double-click to have VS auto-stub in lifecycle Page events such as OnInit or OnUnload and then take me to the newly stubbed delegate? Surely this isn't always a manual process?
The Event tab in the property grid requires that Design View be up to date (synchronized) to work. For this to happen, you either need to be in design view, or have just left it without making changes to the document (or be in split view, so you can refresh the designer easily at will).
See also: Events tab randomly appears and disappears in VS 2008
Adding information from the comments:
Currently (VS2010), the only stubbing support for event handler generation using WebForms is for server control events. There isn't any tooling out-of-the-box to create event handlers for the Page itself (e.g. OnInit, OnUnload) if you're using code-behind files. However, if you are using single file webforms (i.e. no code behind) you can generate these via the Navigation Bar (disabled by default in VS2010, but enabled in previous versions).
Just select the element, go to event tab in property grid. Then double click the event you want.
Also make sure you are using "runat=server" and ASP.NET WebControls. In other words, not HTML controls.
As an addendum to the question: Please see Jimmy's comments above. Looks like everything else works fine but there's no method of auto-wiring up Page-type-specific events.
Ok, this question might more about design theory. I have successfully created controls that show up in my toolbox, so I'm pretty sure I have the process right. Also, my "AutoToolboxPopulate" is set to true, so things are showing up as I create them. My question is this: I'm sub-classing a native Control for specialized use. When I derive my class from an exposed concrete class, such as BulletedList, my custom Control appears in my Toolbox. However, when I drop it back to the parent, such as ListControl, my Control is not listed (actually it's grayed out when I "List All"). What am I missing?
I think the answer is that there must have been a problem with my code. I did eventually get these to show up, and it may have been an error somewhere.
However, here's an important tip: In order to get custom server controls to show up in your toolbox, you have to load your page into "design" mode. This will update the toolbox list. (apparently, it's necessary for the document outline, too)
I am developing an ASP.Net web app that needs to run in a Kiosk/Touch screen environment.
The existing ASP.Net web controls are not too touch-screen friendly as they seem better suited for a mouse/touchpad.
The hot potato dropped in my lap when the powers-that-be decided we need some sort of composite control similar to the ASP.Net Radio Button List, but instead of radio buttons I want the items to be displayed as large rubber buttons. The selected item's button needs to be indented for example or depict this graphically somehow.
I still need to have access to a selecteditem/ selectedvalue type property to determine what was selected...
What would be the best approach in achieving this? Creating a custom server control that overrides the radiobutton control or using a .Net control 'skin' file somehow that allows me to graphically alter a standard radio button list via CSS?
Your input is appreciated.
You can do this with the existing control- see here for an example. See if that does what you require before considering extending an existing control or writing a custom one.