I would like to build a multiline combobox in WPF. This would be similar to label control wherein the width of control will grow such that entire selected text is visible. The text displayed can go over next line if there is no enough space available on current line.
I tried few things around control template of combobox. But still no success.
Below is sample screenshot of how it should look like!
Any pointers?
Thanks,
Sambhaji
As per my understanding setting the control template for this particular scenario would be a tedious job. I would have created a TextBlock and tried setting the event triggers which will open a container on mouse hover or click event.
Related
I am working on a simple text editor that allows the user to hover over words in the text and get information about them. I am looking for a way to control a tooltip that pops up based on my own logic the drives from the MouseMove event. Trying to create a simple popup that acts similar to a code editing window when you are debugging and looking at variable symbol values by hovering the mouse over words in the text.
I am not seeing an obvious way to force the tooltip to show/hide on-demand.
Instead of using the ToolTip property, you could use a Popup element and set its IsOpen property to control when you want to display it.
You can style it to look like a ToolTip.
Is there a way to make an entire WPF Window inert after a button click?
The window is invoked via Window.ShowDialog() and after use, the window is no longer needed for interaction but I leave it open to remind the user of the inputs in TextBox's, ListBox's, and give visual feedback via OxyPlot and so on. I leave it to the user to close the window manually.
One solution is to disable all buttons but that's tedious and it still leaves TextBox's functioning. That's not optimal because for anything to be functioning creates the wrong impression that the Window remains for anything other than looking at. It would be better for every control to be non-functioning by a single setting.
I did it by putting a name on the WPF window code behind and then setting .IsEnabled false upon the appropriate button click. All buttons, combo boxes, text boxes, and even OxyPlot became inert at that point and most parts were greyed out.
Consider creating a dedicated boolean dependency property in your code-behind or viewmodel and binding IsEnabled of every TextBox to the property.
I have a textbox and some labels inside the data template of bounded listbox.
When I click on any label the whole item is highlighted in blue, but when I click directly on a different textbox the selection does not change.
Is there a way to make the selection of the listbox change even when a textbox is clicked?
thanks
This is what I've exactly asked few days ago, see post: "WPF: Trigger SelectedIndex changed whilst clicking on any control within a ListBoxItem area"
basically there are few solutions, using code behind and XAML, but I've not verified latter approach yet
The reason is because the TextBox handles the click event in order to receive focus. There are a number of ways to handle this, including but not limited to:
stop the TextBox handling mouse events (which prevents the user from focussing it using the mouse)
use an eventhandler when the TextBox gains focus (or PreviewClick or similar), to select the parent ListItem
Can the width of the dropdown be set to a different value than the AutoCompleteBox itself?
The Popup is a separate Part of the AutoCompleteBox, so it should be possible to extend that beyond the width of the text box.
In Blend, right-click on the AutoCompleteBox and select Edit Template > Edit a Copy, giving the new template a name.
Drill-down in the Objects and Timeline window to the 'Popup' part, and beneath that is a Grid. Change the width of that Grid to change the width of the popup content whilst maintaining the current width of the text box).
(I must admit I've only had chance to do this in Silverlight Spy, but it definitely works there so I can't see it being a problem doing it through Blend).
If you are not using Blend, just copy Default Style and Template of AutocompleteBox from MSDN and paste it into your App.xaml file (here is little tutorial on how to handle styles in app.xaml).
You can then modify that pasted style or template.
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.