Adding a custom item to a Silverlight ComboBox bound to ObservableCollection - silverlight-4.0

I have a search screen within my application that has a ComboBox which is bound to an ObservableCollection in a ViewModel (the collection contains Organisation entities returned via WCF from an Entity Framework model).
I wish to add an item to the combo representing "All Organisations" - so the user does not have to specify an organisation when searching.
Is there a way of adding custom items to a ComboBox or do I have to add a dummy Organisation to the collection and carry out the necessary logic when this is selected.

Have a look at WPF combo box, adding an all options item, when binding to an Observable Collection. It describes one option which is a CompositeCollection.

Related

XAML control that supports data binding except listview or listbox

Is there any XAML control that supports data binding except listview or listbox. I am developing an application using windows azure mobile services table. After retrieving the data from table I am binding the list to a listview as a small preview. When user will select any Item from the list view I want to display the details of the selected item. Which XAML control will be suitable for this task. I can use lots of TextBoxes and assign its Text property from C# code. I dont think It is a good practice. Thank you
If it's a better collection viewer you are looking for for, use a DataGrid. If you want to show more info, it's worth making another panel and showing more data there about the selected item (master detail pattern)
All XAML controls support data bindings. Use DataContext if you want children to access the binding, otherwise you can bind directly on the property.
For example, you could have a separate panel that is a Grid with a few child controls. This Grid's DataContext can be set to the DataGrid's SelectedItem, then it's child controls can easily bind to the item's properties.

Exposing internal objects of a user control in the properties view of the designer?

I've already had success exposing a collection of items in the vb.net designer using DesignerSerializationVisibility(Content). Now I have a new twist. The items in my collection for a certain custom control are immutable--i.e. items can neither be added nor removed. All I want is to expose the items of my collection in the properties panel of the designer so that a developer can tweak the individual properties of each item in the predefined collection of items.
When I tried DesignerSerializationVisibility(Content) it allows the developer to manage the items but rather than editing the existing items it attempts to re-add the items to the collection, which causes key collisions.
As a result I figured it might make sense to expose each item of the collection as its own property. I used DesignerSerializationVisiblity(Visible) and (Content) and both just display the type name in the properties window but the object it exposes is not visible in a way that it can have its properties manipulated.
Am I missing something or can this not be done? I read somewhere about using a TypeConverter. Is this right?
If I understand your Question correctly, you want to change a property to expandable property that has several sub-property.
If I understand properly, you must create a class that is derived from ExpandableObjectConverter. And use this class with TypeConverterAttribute for your property or that class that is related with your property.
For more information, please see my question that its link is offered in below:
Hide ellipsis (…) button of expandable property like “…” button of font property in the property grid

Insert/Remove item in listbox bound to database

I want to be able to reorder my listbox which is bound to my sql ce database by clicking up and down arrow buttons. Since my listbox is populated directly from my database using the entity framework, I think I have to delete the object (from the listbox) and reinsert it (in the row above) if I want to move the item up the list.
I have no view model, my listbox is populated directly from my database in my code like this:
listBoxProperties.ItemsSource = entities.Properties.ToList();
Does my question make sense?
Cheers
ormally you would handle the moving of your list item in your view model which would hold the ObservableCollection the control was bound to - and then that would be reflected in your control via the binding.
It is going to get messy trying to accomplish this dirrectly on the control - which is your only way since your binding to a throwaway copy of the EF properties list.
As your UI dev goes on you are only going to run into more issues like this. I strongly recommend getting a view model in place sooner rather that later.

Data Binding ListBox in a User Control in the Silverlight Page

I have a user control that has a ListBox with a bunch of other controls.
I need to be able to bind the ListBox control in the Silverlight Page.
I need to be able to do this, so that i can use my usercontrol on several different pages and bind it to different table on each page.
Any ideas of how this can be done?
You can expose a DP of type IEnumerable in your UserControl and, as you feel the property change, set your ListBox's ItemsSource to that property.

Databinding a list (in an object) to a combobox in VB.net

VB 2008 .NET 3.5
I have a custom "Shipment" object that contains a list of "ShippingRate" objects. This list of "ShippingRates" is accessible through a property "Shipment.PossibleShippingRates." That property simply returns a copy of the list of "ShippingRate" for that particular Shipment.
My UI layer receives a list of "Shipment" objects from the BLL. This list is databound to a datagridview, and shows details relevant to the Shipment such as Shipping Address, etc.
I want to bind the "Shipment.PossibleShippingRates" property to a combobox, such that when the user changes the grid row, the combobox reflects the "PossibleShippingRates" for that "Shipment."
In addition, I need a way to store the "ShippingRate" they selected from the combobox for later use.
I have tried a few ideas, but none of them work properly. Any ideas on how to do this?
Wouldn't the simplest solution be to tie a TextChanged or SelectedIndexChanged event to any/all fields in the datagrid that need to trigger a refresh of the combobox?