data binding - How to make a WPF ComboBox editable with custom values -


I have to put a combo box which allows selection from the list of values ​​and also the custom value typed in the text Allows Items are a complex type for the reasons shown (CongoBox shows a patch of item template color and shows that it is a custom color).

  Public Class ColorLevel {Receives {Public Decimal Intensity}; Set; } Public bool isCustom {get; Set; } Public color basalole {get; Set; } Public override toasting () {Return string. Format ("{0}", Intensity * 100); }}  

example item

  var items = new [] {new ColorLevel {Intensity = 0.9m, IsCustom = false, BaseColor = Color.Red} , New color level {intensity = 0.7m, icicute = false, basecolor = color Rd}}  

xml

  & lt; Combo box selectedItom = "{binding path = selected collar level}" isadetibil = "true" isTextSearchEnabled = "true" & gt; & Lt; / ComboBox & gt;  

The above markup works when an item item is selected from the list. And as you type with text search, the matching item is selected if the typed text does not match any object, then the selected coler level is set to clear.

At which point the question is (and how) it is best to create a new custom item that can be set to the selected caller level, when typed text does not match any item. For example, I would like to assign a new item to the value selected as

  New ColorLevel {Intensity =  

or text using text controller You can use the database for the property.

Not sure I fully understood .. You can use the event, for example, when the return is pressed if the item is an observable collection and you set it as the item source of the combo box, then the new ColorLevel to be added to the item will be available in the list. Should and must be selected event.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -