Binding an user control to WPF ComboBox? - wpf

I want to bind an user control as an item of a ComboBox, is this possible?
I want to get a ComboBox like this:
Thanks.

do you want all items in your combobox to render like your picture? so if you have 4 items it should look like this?
if yes, the easiest way would to create a datatemplate for your type of object you wanna show in your combobox.
if not you should specify your question

Related

Display a Grid as a comboBox's selectedValue

I was wondering, is it possible to display a grid in a comboBox as its selectedValue (or displayMemberPath) ?
I wanted to do something like that :
It's a screen from Telerik's comboBox, but I wish to do the same in WPF only. I already use a grid inside the dropdown and it works pretty well, and I'd achieve something cool if I could display many rows as a selectedValue. I supposed I'd use a grid but applying a grid in the displayMemberPath style doesn't really work.
My comboBox is inside a DataGridTemplateColumn but I don't think it matters, just saying.
Thanks !

How to dynamically set DataTemplate based on item type?

The objective is to have different layout for items in a ListView depending on the item's type. For example some items would have text and a button, other text and image, others text and check-box etc.
Having a DataTemplate for each kind of item would solve the problem. I looked into DataTrigger but it seems to allow only change properties of items, but not the layout template. Does the framework provider any convenient way of doing this?
I believe DataTemplateSelector is what you're looking for.
Or use DataType.
does each item's type has is own class?
so item1 is classA, item2 is classB?
if yes then you can simply create one datatemplate for each type.
if not you can create style and trigger to handle your conditions. maybe you post some code so we can helk you better

Is there a way to create a "header row" for a Winforms ComboBox?

Is there a way to create a "header row" for a winforms combo box?
So that's it's always displayed at the top?
The quick answer is: probably not. You would have to make your own usercontrol to do something like that.
This Getting ComboBox to show a TreeView shows how to so something like that. Just replace the treeview with a usercontrol that contains a label at the top and a listbox. Pass your combobox list of items to the usercontrol, etc.

Silverlight AutoCompleteBox SelectedValue(?)

I need to implement an editable combobox where users can select existing values from the data/tables. It needs to be editable because users can also add new rows to the table by entering new values in the editable combobox, so I put an AutoCompleteBox control into my page but I can't find any sample on how to implement such feature. It should display something like Employee Name in the editable dropdown while having the SelectedValue property to contain the Employee ID.
Any help will be very much appreciated.
Cheers!
You will need to bind your autocompletebox's ItemsSource to your "lookup" collection.
You can use ValueMemberBinding to resolve the textual input to look for, ie if you have a list of people, bind this to Model.Name like this {Binding Name} to find people by name.
As far as the drop down items, you could use templating to display the items the way you like.
Heres a good tut on the subject, you want to style the ItemTemplate. following from the example you would make a datatemplate in xaml within the ItemsTemplate element add a Textblock and bind its Text property to Name like {Binding Name}.
Here a nice example where a autocompletebox is styled like a combobox. You could extend that to look for "enter" on TextChanged and check to see if the item is contained in the ItemsSource. If not it could push the new value to the server (if you are into MVVM, you could raise a command on you ViewModel that would delegate the addition to the server and update the Items).
Here's another example that extends the AutoCompleteBox to be used as a type-ahead ComboBox. It can handle foreign keys / lookup ids using DPs and can be used in MVVM scenarios.
AutoComplete ComboBox for Silverlight

WPF "flying" combobox

is it possible to create a combobox in wpf from code, which I could position wherever I want on the window?
In my case, I basically want to create something like a Autocomplete for DataGrid rows,...
Thanks!
TextBox supports auto complete, and you can create your datagrid's template column and you can specify the template with textbox which can interact and give you autocompletion.
if you put it in a <Popup> you can then position the popup wherever you want--it is not "bound" by a parent container.

Resources