How to create context menu for data-bound WP Silverlight ListBox totally from code? - listbox

I have a classic ListBox control with a custom ItemTemplate. The ListBox is bound to a collection of objecs. How can I create a custom context menu (an instance of the ContextMenu class from Microsoft.Phone.Controls.Toolkit.dll) and attach them to my ListBox items totally from code?

Related

Delphi: What is type of window appears after you click a ComboBox

There is a window appear after you click that triangle icon of ComboBox. This I know it's not just a panel like object because for example in the following picture it' out of main form.
What is its type and how can I create something like this?
It is a standard ListBox control that the ComboBox creates internally (its HWND is accessible via the CB_GETCOMBOBOXINFO message). It is implemented as a free-floating window (so it can appear outside the ComboBox's parent window), except when the Style property is set to csSimple, in which case the ListBox resides as a child within the ComboBox's client area instead.

Is there a way to activate component editor menu for a concealed component in Delphi

I implemented two menu items for my component in Delphi IDE with TComponentEditor descendant. They're both supposed to be used with "right-clicking" a component on the form. But can I do this for component that is currently hidden (concealed) by other components? So I select a component with other tools (for example object inspector) and would like to activate one of my context menu items.
Shift-F10 doesn't work (at least in D5).
Bringing the component to top for this task is not an option.
Right-click the component in the Object TreeView (Shift-Alt-F11).
D7: Menu > View > Object TreeView
XE2: Menu > View > Structure
Or make a property editor with paDialog in the attributes and forward the Edit method to your component editor. Then double clicking that property or clicking the ellipsis will bring up the component editor, just like the Colums property for TDBEdit does.
If you feel like writing a something mimicking Delphi IDE's Object TreeView, I suggests you the following resources:
Populating all controls of a container object using recursion (Blog post). Using TVirtualTreeView like the Delphi IDE is better than the stock TTreeView to my opinion.
Study the commercial TLMDComponentTree
of the LMD IDE-Tools (Excerpt: This powerful control allows to use a Delphi IDE like Object TreeView. Collections, child controls etc. are automatically handled).

Dynamically Add listbox Item to an ObservableCollection

I have a listbox that I have bound to an Observable collection. At runtime I would like the user to click a button and add thier own custom ID and Name to the listbox.
How do I do that when the listbox is already bound to an Observable collection?
THank you
When the user clicks the button add the item to the observable collection and the listbox should automatically update. If not, call databind on the listbox after it's been added to the collection and this will rebind the data to the listbox updating it

grid binding to a listbox selecteditem runtime

I am a beginner, so please bear with me.
Let's say we have a listbox and a grid that contains textblocks on a window. But these are instanced from separate xaml files, and added to two different stackpanels in the window.
How can I bind the grid datasource to the listbox's selected item in runtime?
I guess what I need to do is to do this following xaml in runtime:
Grid DataContext="{Binding ElementName=lstContacts, Path=SelectedItem}"
Thanks.
You could handle the Window's Loaded event, and in your handler: traverse your Window's children using VisualTreeHelper to find your ListBox based on its name, then set your Grid's DataContext.
Here is a question that discusses, and provides a method for, finding children in such a manner.

How can I create a context menu for a Delphi component?

I want to create a context menu for Delphi components like TDBGrid, TTreeView or similar. How can I do that?
Place a TPopupMenu onto your form and design your menu with it. Then select the component the popupmenu is meant for (DbGrid, TreeView, ...) and set it's PopupMenu property to the PopupMenu you just designed.
You can have different PopupMenus for different components.
After placing a TPopupmenu control and linking it to the desired control, if you want to change the available items in the popup menu according to the selected cell or node in a treeview use the OnContextPopup event of the control, that gives you a chance to alter the default behaivor of the Popupmenu

Resources