I'm trying to create a wpf combobox where certain keywords in the item text are always a different color (eg, phrase "abc" should always be blue, even if it's just a part of a longer word). Ideally, this should apply to all templates of the combobox: selected item, dropdown items, and the editing textbox as the user is typing new entries ("IsEditable" is set to true).
My initial thought is to use rich text controls for the templates of the combobox, but I'm having difficulty figuring out how to set the editing template. Even then, I'm not sure how to proceed on enforcing keyword coloring as the user types. Suggestions?
Related
I have a dropdownlist combobox that uses an ItemTemplate to display information. When the dropdown of the combo is open, I want the user to be able to type things that I will search the data for. Then I'd like to highlight the item (and potentially scroll it into view), but NOT select it (selection in this case is expensive and should only occur when the user presses Enter once he's found the right entry).
Essentially this is how a vanilla combobox behaves and I want to do this for my templated one that searches differently.
I've have an AttachedProperty that does the searching correctly, but I can't figure how to set the highlighted item (IsHighlighted is read-only).
This is not a cosmetic issue only, since Enter should select the highlighted item.
Any ideas?
If you can add a dependency property to the object in the list you are displaying that holds a bool value for the "ShowHighlighted" state, you could then add a trigger to your ItemTemplate that changes the Background Brush based upon the value of ShowHighlighted.
I need a control that allows a sequence of controls to be edited. Each control has a single associated value and the value of an editable sequence would be the sequence of those values. Editing the sequence refers to adding new elements, deleting existing elements and reordering elements.
I've written an editable sequence control that displays a dock panel with a list box, up and down arrows and a text box. Entering text into the text box and pressing return adds a new element with that name. Pressing the up or down arrows moves the currently selected element. Pressing DELETE when an element is selected removes it.
I'd like to examine other options. Do any built-in WPF controls provide this functionality? How might I compose existing controls to create what I need? Are there commercial solutions that would make my life easier?
EDIT: For example, it would be more user friendly to allow elements to be reordered using drag-and-drop. What is the easiest way to accomplish this?
My requirement is rather a tricky one (it seems to me).
I will explain the scenario.
I have a DataGrid. In the DataGrid, I have two columns in which I have a grid in every cell of these two columns, inside of which, there are two comboboxes - the purpose being to switch the visibility based on some conditions.
When we select a value in the combobox, the combobox itself, plus some other controls in some other columns will get disabled (requirement of the pjt). Now there is also, another requirement like, Tab should not be allowed in the cell which has disabled controls - say disabled combobox.
We are setting the controls as Enabled or Disabled based on a selected value from the combobox. So, since we are applying the disabling property on the control level, and the IsTabStop property is on the cell level, I am not able to restrict Tabbing in the cells having disabled control.
Any thoughts?
Don't use a DataGrid.
DataGrid's are awesome for read-only stuff, but they seem to suck for doing any kind of interesting editing. After well over a week of fighting with it, I've given up on it.
Right now I'm looking for a replacement, which may end up just being a scrollable stack panel with manually added controls.
WPF: Is there a "ListBox" without the ability to select items?
My WPF combobox is populated with a different set of strings each click of a button. There are other controls on the window as well. The combobox is the 'first' (top) in the window, but the text doesn't get highlighted. When the user tabs through the controls, the text DOES get highlighted, but when it's the first on the window, it doesn't.
Maybe i need to force a highlight on the individual textbox control 'within' the combobox itself, but how would i do this? I couldnt seem to find the internal 'structure' of this control anywhere. Could anyone help here?
Jack
to get the TextBox of Combobox you can use
TextBox TxtBox = (TextBox)myCombo.Template.FindName("PART_EditableTextBox", myCombo);
I'm not sure it's the best solution, but you can use FrameworkElement.FindName to access the child control -- it's guaranteed to be present in a combobox, because it's a key constituent part of the control.
That stated, is it not better to try and call .Focus() on the control? That is likely why when you tab, the highlight is provided.
Another option is to derive from ComboBox, and expose the child text box as a property allowing you to set it's selection, or add a method directly to the combobox to set it for you.
I'm looking to create a WPF textbox control that acts similar to the email recipient textboxes in Outlook (the To, Cc and Bcc inputs). I don't necessarily care that much about auto-completion (i've found millions of examples for that), but what I'm really struggling with is how to have delimited text entries in the textbox behave as entities the way they do in Outlook (once a recipient you've entered resolves, that text becomes an 'entity' which you can click to select, right click to get a context menu, etc. it's not longer 'plain text' in which you can place your cursor)...
Does anyone have any high level ideas how to accomplish this? Know of any existing examples (I've googled for hours)?
Thanks so much in advance,
Michael.
My rough thought process would be this... (note: I'm not actually coding it, so my details may be a little off...).
High level behaviour:
the type of data in your control is a list of items which aren't selectable. Therefore your control is, approximately, an ItemsControl (in terms of visual/XAML, it's an ItemsControl with a WrapPanel style layout and very simple TextBlock for the item template).
when your control gains focus, you need to switch the template to be a TextBox
when your control loses focus, you need to split the inputted text and convert it to a list for display.
Therefore, thinking code:
you need a UserControl, possibly derived from ItemsControl. That gives you basic behaviour to represent a list of items.
you need a custom DependencyProperty on your control that represents the delimited string.
when the string property changes, you need to parse it and replace the list of items in the control.
when the list property changes, you need to replace the string property with a suitably-delimited list.
In terms of code-behind, that part should be pretty simple. Then, for the XAML template...
you need a base template that displays your Items property as a list, using the WrapPanel layout mentioned above.
you need a trigger that replaces this template when the control has focus.
the replacement template should be a TextBox that is bound to the string property of the control.
the default binding behaviour on a TextBox will only push a new value when the TextBox loses focus, so you need to think about whether you want to make, say, an "Enter" keypress move focus (thus reverting the template to the list version - when the string property's value changes, your codebehind will update the list).
This should give you the basic behaviour. You should be able to bind either the list property or the string property from outside of the control, though you may have to be careful about what happens if you bind both properties since there's a two-way dependency between them...